【发布时间】:2018-05-04 22:55:23
【问题描述】:
我正在尝试将我的 ggplot 注释放入图形图例中。目前,我的身材是这样的:
我添加的水平线代表每个浓度的平均值。如何将此添加到图例中,以便每种颜色都有一条水平线?
这是我的代码:
ggplot(all,aes(x=Concentration, y=Distance, colour=Genotype))+
geom_jitter(width=0.3, height=0, show.legend=TRUE)+
theme(panel.background = element_rect(fill = "white")) +
theme(axis.line.x = element_line(color = "black"),
axis.line.y = element_line(color = "black"))+
scale_y_continuous(breaks=seq(0, 8, 1))+
xlab("Caffeine concentration (mM)")+
ylab("Distance travelled (arbitrary units)")+
annotate("segment", x=0.8,xend = 1.2, y= 2.86, yend = 2.86,
colour="black")+
annotate("segment", x=1.8,xend = 2.2, y= 1.86, yend = 1.86, colour="black")+
annotate("segment", x=2.8,xend = 3.2, y= 1.11, yend = 1.11, colour="black")+
annotate("segment", x=0.8,xend = 1.2, y= 2.41, yend = 2.41, colour="green3")+
annotate("segment", x=1.8,xend = 2.2, y= 2.16, yend = 2.16, colour="green3")+
annotate("segment", x=2.8,xend = 3.2, y= 2.24, yend = 2.24, colour="green3")+
scale_colour_manual(values = c("Q24" = "black", "Q35" = "green3"))
样本数据:
Concentration Distance Genotype
0 1 Q24
0 4 Q24
5 1 Q24
5 0 Q24
10 0 Q24
10 1 Q24
0 1 Q35
0 3 Q35
0 4 Q35
5 0 Q35
5 1 Q35
10 0 Q35
10 2 Q35
【问题讨论】: