这篇文章中的数据:joining all points inside a grouped point plot using ggplot仍然是一样的,我又给它添加了一列。在Jimbou提供的解决方案的帮助下,我编写了以下代码
head(AA)
States Clusters value Comp_apply L1_25 L1_30 L1_50 x xbreaks
<chr> <chr> <dbl> <int> <int> <int> <int> <dbl> <dbl>
1 HR Cluster-1 0.0703 9 2 4 7 31 32.7
2 HR Cluster-2 0.0761 4 2 2 3 33 32.7
3 HR Cluster-3 0.0692 9 7 7 8 34 32.7
4 WB Cluster-1 0.0372 13 2 2 2 111 113.
5 WB Cluster-2 0.0762 13 2 3 6 113 113.
6 WB Cluster-3 0.0906 13 3 3 4 114 113.
现在进行绘图的代码是
ggplot(data=data.m1)+
geom_line(aes(x = x, y = Comp_apply, group=States,color="red")
,position=position_dodge(width = 0.90))+
geom_point(aes(x = x, y = Comp_apply, group=States,color="red")
,position=position_dodge(width = 0.90))+
geom_line(aes(x = x, y = L1_25, group=States,color="green")
,position=position_dodge(width = 0.90))+
geom_point(aes(x = x, y = L1_25, group=States,color="green")
,position=position_dodge(width = 0.90))
现在情节如下
你能帮我纠正一下吗?
发布于 2018-08-03 10:09:53
如果您想像您所做的那样为整个geom
分配颜色,只需将colour="red"
放在aes()
之外即可。但那样的颜色将不会出现在传说中,因为它没有映射到任何因素。
正确的方法是修改您的data.frame
,以便Comp_apply
和L1_25
显示为相同因素的两种模式(即在同一列中)。我不能为你做这件事,因为你的数据没有提供。
那么,您只需要调用geom_point
和geom_line
一次。提供数据,我更新我的答案。
https://stackoverflow.com/questions/51669830
复制相似问题