0
我使用ggplot繪製10個主題的散點圖,每個主題在兩個不同的列中包含2個值。我可以繪製散點圖但無法調整圖例。圖例框應該顯示供體-1,供體-2,...供體-10,但是它顯示了供體-1,供體-10,...,供體-9。另外,它在圖例中顯示geom_point函數中提到的大小塊,它不應該存在。ggPlot2圖例調整
下面是我爲它的代碼片段:
color1 = 'red'
color2 = 'green'
color3 = 'blue'
color4 = 'forestgreen'
color5 = 'purple'
color6 = 'yellow'
color7 = 'orange'
color8 = 'royalblue'
color9 = 'palevioletred4'
color10 = 'pink'
p2<-qplot(CEACAM4.2hrs, CEACAM4.EDTA, data=res, xlab="CECAM4 PAX 2 Hr", ylab=" CECAM4 EDTA 0 Hr")
p3<-p2+geom_point(aes(color = row.names(res2), size = 3)) + scale_x_continuous(limit =c(22,28), breaks = c(22,23,24,25,26,27,28)) + scale_y_continuous(limit=c(22,28), breaks = c(22,23,24,25,26,27,28)) + stat_smooth(method="lm", se=FALSE)+ scale_color_manual(values=c(color1, color2, color3, color4, color5, color6, color7, color8, color9, color10))
p4<- p3 + guides(colour = guide_legend(override.aes = list(size = 10)))
p4+ ggtitle("CECAM4 EDTA 0Hr Vs PAX 2Hr") + theme(plot.title = element_text(size = 28,colour=" mediumvioletred", face = "bold"))+ theme(legend.key = element_rect(colour = "black"), legend.title=element_text(size=22), legend.text=element_text(size=20)) + theme(plot.margin=unit(c(2.5,2,2,2),"cm"))+ theme(axis.text=element_text(size=18, face="bold"), axis.title=element_text(size=20, face="bold", colour="purple4")) + theme(axis.title.y=element_text(vjust=-0.65)) + theme(axis.title.x=element_text(vjust=-3.0)) + theme(plot.title = element_text(vjust=5)) + theme(axis.ticks.length=unit(1,"cm")) + theme(legend.key.size=unit(1.5,"cm"))
ggsave(file="ggplot_cecam4_2_edta.png")
所以,問題更確切地說就是,如何才能得到傳說中的順序與ggplot? 例如
供體 - 1
供體 - 2
供體 - 3
供體 - 4
供體-5-
供體 - 6
供體 - 7
供體 - 8
供體 - 9
捐助-10
謝謝。
歡迎堆棧溢出!給[可重現示例](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example)使其他人更容易幫助您。 – Jaap