我在设计图上的图例颜色时遇到了麻烦,我只是不能在我的图例上设置适当的颜色,并且所有三个都显示为红色:Multiple Scatter ggplot。我尝试使用scale_colour_manual
选项和scale_fill_manual
,但它不起作用。我不知道数据框和gerenarl中的代码是否合适,但这是我找到将不同回归线放在同一个图上的唯一方法。 这里是一个MWE:使用ggplot标签的问题
`library("ggplot2")
ConcCurve<-c(0.000,5.809,11.514,21.995,32.349,44.390,53.552)
ABSHei<-c(0.01299076, 0.44779044, 0.87251242, 1.64435113, 2.41385198, 3.25395864,3.93389333)
ABSAr3<-c(0.0224455, 0.8303167, 1.6170380, 3.0466451, 4.4496162, 5.9631238, 7.1746112)
ABSAr5<-c(0.03847996, 1.44915907, 2.81864550, 5.29479463, 7.69466231, 10.27269797, 12.32472597)
DataR<-data.frame(ConcCurve,ABSHei,ABSAr3,ABSAr5)
p1<-ggplot(DataR) +
geom_point(aes(x=ConcCurve,y=ABSHei,fill="Height"),colour="blue") +
geom_smooth(aes(ConcCurve,ABSHei), method="lm", se=T,level = 0.9999,lwd=0.6, col ="blue") +
geom_point(aes(x=ConcCurve,y=ABSAr3,fill = "Area 3 pix"),colour="green") +
geom_smooth(aes(ConcCurve,ABSAr3), method="lm", se=T,level = 0.9999,lwd=0.6, col ="green") +
geom_point(aes(x=ConcCurve,y=ABSAr5,fill = "Area5 pix"),colour="red")+
geom_smooth(aes(ConcCurve,ABSAr5), method="lm", se=T,level = 0.9999,lwd=0.6, col ="red") +
labs(x = expression(paste(plain("Hg"^plain("2+"))," Concentration (",mu,"g ",plain("kg"^plain("-1")),")")), y = "Integrated absorbance")+
ggtitle("Calibration curves obtained using R")+
guides(fill = guide_legend(reverse=F,title="Evaluation\nmode"))+
scale_colour_manual(labels=c("Heigth", "Area 3 pix", "Area 5 pix"),
breaks=c("Heigth", "Area 3 pix", "Area 5 pix"),
values=c("blue","green","red"))
print(p1)
`
如何配置的颜色,使他们出现在解释的方式?
似乎有在你的代码(例如“Heigth”)的一些错字,但他们似乎并不成为问题的唯一原因,如将它们固定不产生你想要的结果。 – wwl
我也试过在这些问题中给出的解决方案,他们没有工作:http://stackoverflow.com/questions/19330257/changing-the-color-in-the-legend-with-ggplot2-in-r – wwl