首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >改变图例中颜色和图例序列的r方格图

改变图例中颜色和图例序列的r方格图
EN

Stack Overflow用户
提问于 2018-08-03 09:45:33
回答 1查看 716关注 0票数 1

这篇文章中的数据:joining all points inside a grouped point plot using ggplot仍然是一样的,我又给它添加了一列。在Jimbou提供的解决方案的帮助下,我编写了以下代码

代码语言:javascript
运行
复制
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. 

现在进行绘图的代码是

代码语言:javascript
运行
复制
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))

现在情节如下

你能帮我纠正一下吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-08-03 10:09:53

如果您想像您所做的那样为整个geom分配颜色,只需将colour="red"放在aes()之外即可。但那样的颜色将不会出现在传说中,因为它没有映射到任何因素。

正确的方法是修改您的data.frame,以便Comp_applyL1_25显示为相同因素的两种模式(即在同一列中)。我不能为你做这件事,因为你的数据没有提供。

那么,您只需要调用geom_pointgeom_line一次。提供数据,我更新我的答案。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51669830

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档