2015-06-21 144 views
2

我想从图例框中删除灰色(这是因为来自geom_smooth的SE,因此存在)。尽管如此,我仍想让SE保持在实际情节中。所以在图例框中,我只想要线条的颜色,而不是阴影。这里是一个例子:从ggplot2的图例中删除灰色

library(ggplot2) 

x <- rnorm(100) 
y <- rnorm(100) 
g_ <- sample(c("group1", "group2"), 100, replace = TRUE) 

ggplot(data.frame(x, y, g_), aes(x = x, y = y, color = g_)) + geom_smooth() 

回答

3

这是一种方法。首先,画出可信区间的线条,但没有传说。然后,画出没有间隔和图例的线条,最后将图例的颜色设为白色。

ggplot(data.frame(x, y, g_), aes(x = x, y = y, color = g_)) + 
    geom_smooth(show_guide=FALSE) + 
    geom_smooth(fill=NA) + 
    theme(legend.key = element_rect(fill = "white")) 

enter image description here

+0

创造性的解决方案! –