【发布时间】:2015-11-18 11:45:45
【问题描述】:
我正在使用带有 GAM 平滑的 ggplot2 来查看两个变量之间的关系。绘图时,我想删除两种类型变量符号后面的灰色区域。为此,我会使用theme(legend.key = element_blank()),但在使用平滑时似乎不起作用。
谁能告诉我如何去除图例中两条黑线后面的灰色区域?
我在下面有一个 MWE。
library(ggplot2)
len <- 10000
x <- seq(0, len-1)
df <- as.data.frame(x)
df$y <- 1 - df$x*(1/len)
df$y <- df$y + rnorm(len,sd=0.1)
df$type <- 'method 1'
df$type[df$y>0.5] <- 'method 2'
p <- ggplot(df, aes(x=x, y=y)) + stat_smooth(aes(lty=type), col="black", method = "auto", size=1, se=TRUE)
p <- p + theme_classic()
p <- p + theme(legend.title=element_blank())
p <- p + theme(legend.key = element_blank()) # <--- this doesn't work?
p
【问题讨论】:
-
试试
element_rect(fill = NA) -
这似乎不起作用。我猜想——当我使用 fill = "green" 时,盒子会变成深绿色,已经涉及到某种背景。将进一步调查。
-
@CathG 是的,海似乎在传说中。不过我找到了解决方法。