我这里有一个线条图,灰色矩形从x轴值50-160阴影。此矩形的附加绘图似乎覆盖了我的图例键规范,使用灰色填充图例键,并使用对角线作为变量的颜色。我尝试了以下两种方法但没有成功:
theme(legend.key = element_rect(fill = "white",colour = "white")) +
theme(legend.background = element_blank())
和
guides(fill = guide_legend(override.aes = list(colour = NULL)))
theme(legend.key = element_rect(colour = "black"))
这与我上一个情节线中的inherit.aes = FALSE
有关吗?
有什么建议吗? 非常感谢!
rect=data.frame (xmin=50, xmax=160, ymin=-Inf, ymax=Inf)
p1=ggplot(p1, aes(x=JDY, y=value, colour=variable)) +
geom_line(stat='identity', size=0.75) +
theme_bw() %+replace% theme(panel.background=element_rect(fill=NA)) +
theme(panel.grid.minor=element_blank()) +
theme(panel.grid.major=element_blank()) +
guides(colour=guide_legend(title="Phytoplankton")) +
theme(legend.key=element_rect(fill="white",colour="black")) +
theme(legend.background = element_blank()) +
theme(legend.position=c(1,1), legend.justification = c(1, 1)) +
theme(legend.text=element_text(size=10)) +
theme(legend.title = element_text(size =11)) +
scale_colour_manual(values=c('#e41a1c', '#377eb8', '#4daf4a', '#984ea3')) +
theme(panel.border=element_rect(color="black", size=0.2)) +
coord_cartesian(xlim=c(0,365)) +
scale_y_continuous(label=scientific)
plot(p1 + geom_rect(data=rect, aes(xmin=xmin, xmax=xmax,
ymin=ymin,ymax=ymax), alpha=0.1, inherit.aes = FALSE))