[英]Mixed fill color in ggplot2 legend using geom_smooth() in R
在ggplot2
使用geom_smooth()
繪制兩條回歸曲線時,對於fill
顏色,圖例會選擇置信區間相交的曲線。 我確實認為當重疊區域按比例大於另一個時會出現這種行為,但是我發現這很不受歡迎,因為讀者能夠推斷出“變暗”區域是 CI 相交的區域。 恕我直言,為兩條曲線指定相同的顏色有點困難或不直觀。
我該如何糾正?
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)
輸出:
您可以將填充添加為美學映射,確保將其命名為與顏色映射相同的名稱以合並圖例:
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 = "")
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.