我在設計圖上的圖例顏色時遇到了麻煩,我只是不能在我的圖例上設置適當的顏色,並且所有三個都顯示爲紅色: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