当使用geom_smooth()
在ggplot2
中绘制两条回归曲线时,对于fill
颜色,图例选择置信区间相交的一条。我确实认为,当重叠区域按比例比另一个区域大时,就会出现这种行为,但是我发现这是非常不理想的,因为读者能够推断出“黑暗”区域是CI相交的区域。为这两条曲线指定相同的颜色,这是IMHO有点困难或不直观。
我该怎么纠正呢?
MWE:
library(ggplot2)
p <- ggplot(data=iris, aes(x=Sepal.Width, y=Sepal.Length)) + geom_point()
p <- p + geom_smooth(method=loess, aes(colour="Loess"), fill="yellow")
p <- p + geom_smooth(method=lm, aes(colour="LM"))
print(p)
输出:
发布于 2020-10-14 10:25:58
您可以将填充添加为美学映射,确保将其命名为与颜色映射相同的名称,以获得合并的传奇:
library(ggplot2)
ggplot(data=iris, aes(x=Sepal.Width, y=Sepal.Length)) +
geom_point(aes(shape = "data")) +
geom_smooth(method=loess, aes(colour="Loess", fill="Loess")) +
geom_smooth(method=lm, aes(colour="LM", fill = "LM")) +
scale_fill_manual(values = c("yellow", "gray"), name = "model") +
scale_colour_manual(values = c("red", "blue"), name = "model") +
labs(shape = "")
https://stackoverflow.com/questions/64359233
复制