将geom_points和geom_lines合并为多个ggplots2添加图例

时间:2018-10-30 16:14:17

标签: r ggplot2 combinations legend

我正在尝试将图例添加到以下组合的ggplot中。我已经尝试了很多次,但是看来我不会成功。

图例的标题应为“ Years”,年份应为1995年(绿色),1996年(红色)和2000年(蓝色),并带有线条的颜色和点的形状。

欢迎任何帮助。

提前谢谢!

####
library("ggplot2")
library("grid")
library("gridExtra")  
#####
#####
breaks.major <- c(105,135,165,195,225,255) 
breaks.minor <- c(90,120,150,180,210,240,270) 
labels.minor <- c("Apr","May","June","July","Aug","Sept") 
lims =c(90,270)
######
ggplot() +
# Green plot
geom_point(data=MeanL_1995, aes(x=SamDay, y=TL_mm), shape=15, colour="green", size=2.5)+
geom_line(data=MeanL_1995, aes(x=SamDay, y=TL_mm), shape=15, colour="green", size=0.5)+
# Red plot
geom_point(data=MeanL_1996, aes(x=SamDay, y=TL_mm), shape=16, color="red", size=2.5)+
geom_line(data=MeanL_1996, aes(x=SamDay, y=TL_mm), shape=16, color="red", size=0.5)+
# Blue plot
geom_point(data=MeanL_2000, aes(x=SamDay, y=TL_mm), shape=17, color="blue", size=2.5)+
geom_line(data=MeanL_2000, aes(x=SamDay, y=TL_mm), shape=17, color="blue", size=0.5)+
scale_x_continuous(limit = lims, minor_breaks = breaks.minor, breaks = breaks.major, labels = labels.minor)+
ylab("Mean length (mm)")+
xlab("")+ 
guides(colour = guide_legend(title="Years", shape = guide_legend(title="Years")))

0 个答案:

没有答案