我想用gg-plot2(Rstudio)绘制几条线,并想添加与这些线匹配的图例。到目前为止,它不起作用。我确实有一个图例,但名称与线条的颜色不匹配。这是我的脚本:
p5 <- ggplot(curve_JN1,aes(x=Exposure,y=LogRR,colour="red")) +
geom_line() +
geom_point(data=set,aes(x=exp,y=LogRR)) +
scale_y_continuous("RR")+geom_errorbar(data=AML_set,aes(ymin=lower, ymax=upper, x=exp),inherit.aes = F) + scale_x_continuous("Exposure")
p5 + geom_line(data=curve_JN2,aes(x=Exposure,y=LogRR, colour="black"))+
geom_line(data=curve_JN3,aes(x=Exposure,y=LogRR, colour="pink"))+
geom_line(data=curve_JN4,aes(x=Exposure,y=LogRR, colour="blue"))+
geom_line(data=curve_JN5,aes(x=Exposure,y=LogRR, colour="purple"))+
geom_line(data=curve_JN6,aes(x=Exposure,y=LogRR, colour="orange")) +
scale_color_discrete(name = "Studies", labels = c("Tracy", "Rick","Bart", "Audrey", "Belina", "Susan"))+
#scale_color_discrete(name = "Studies", labels = c("red", "black","pink", "blue", "purple", "orange"))+
theme(legend.position="right")