我在更改图表的颜色和标签时遇到了麻烦。我想使用scale_color_discrete更改图例的顺序和名称,并使用scale_color_manual更改图形的颜色。但是,它们似乎相互重叠,并且图形将恢复为默认颜色,或者将使用我的颜色,但不会更改标签。错误消息是:“'colour‘的刻度已经存在。正在为'colour’添加另一个刻度,它将替换现有的刻度。”
除了标签和颜色,我怎么才能改变呢?
这是我的代码和图表的图片:
ggplot(model_set2, aes(x = mon.sst.levels, y = count.inv, shape = year_bin, color = mon.sst.levels)) +
geom_point(position ="jitter", alpha = 0.7, size = 2) +
scale_x_discrete(limits = c("low", "med", "high"), labels= c("Low", "Medium", "High")) +
scale_y_continuous(breaks = c(500, 1000)) +
xlab("Average Monthly SST") +
ylab("Count of Individals") +
scale_color_manual(values = c("#5436D9", "#D93840", "#55F2BB")) +
scale_shape_discrete(name = "Years") +
scale_color_discrete(name = "SST Levels", limits = c("low", "med", "high"), labels= c("Low", "Medium", "High")) +
ggtitle("Population Size due to SST") +
theme(plot.title = element_text(hjust = 0.5, size = 18, face = "bold")) +
theme_bw()
发布于 2021-05-11 12:49:47
下面是一个使用ggplot2附带的数据集的示例。
对于每个美学,你应该只有一个标尺。可以定义名称、分隔符和颜色,如下所示:
ggplot(diamonds, aes(x = cut, y = price, shape = color, color = clarity)) +
geom_point(position ="jitter", alpha = 0.7, size = 2) +
scale_color_manual(name = "SST Levels",
values = c("I1" = "#5436D9", "SI2" = "#D93840", "SI1" = "#55F2BB",
"VS2" = "#5436D9", "VS1" = "#D93840", "VVS2" = "#55F2BB",
"VVS1" = "#BBBBBB", "IF" = "#445599")) +
scale_shape_discrete(name = "color")
https://stackoverflow.com/questions/67480685
复制相似问题