首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何将第二组标注添加到第二组数据点

如何将第二组标注添加到第二组数据点
EN

Stack Overflow用户
提问于 2017-03-20 21:36:06
回答 1查看 599关注 0票数 0

我已经将标签(2016响应率)添加到我的条形图的条形图中,但也希望将标签添加到位于每个条形图中的个人/黑色数据点(2015响应率)。

这是我的代码:

代码语言:javascript
运行
复制
ggplot(merged2[merged2$TrustCode %in% acuteCodes, ], aes(x = TrustName, y = ResponseRate16)) + 
  geom_bar(fill="white",stat="identity", colour="blue") +
  geom_point(aes(x = TrustName, y = ResponseRate15), shape=18, size=3, colour="black") +
  geom_text(aes(label=ResponseRate16, x=TrustName, y=1.10*ResponseRate16), colour="black")

如何才能做到这一点?

EN

Stack Overflow用户

发布于 2017-03-20 21:41:49

与映射条形值完全一样:添加一个geom_text()

代码语言:javascript
运行
复制
ggplot(merged2[merged2$TrustCode %in% acuteCodes, ], aes(x = TrustName, y = ResponseRate16)) + 
  geom_bar(fill = "white", stat = "identity", colour = "blue") +
  geom_point(aes(y = ResponseRate15), shape = 18, size = 3, colour = "black") +
  geom_text(aes(label = ResponseRate16, y = 1.10*ResponseRate16), colour="black") +
  geom_text(aes(label = ResponseRate15, y = 1.10*ResponseRate15), colour="red")

我稍微清理了代码中重复的x映射。如果已经在初始ggplot函数中映射了aesthetic,则不需要复制它。

您可能还希望使用nudge_y参数,而不是设置新的y美学。

代码语言:javascript
运行
复制
ggplot(merged2[merged2$TrustCode %in% acuteCodes, ], aes(x = TrustName, y = ResponseRate16)) + 
      geom_bar(fill = "white", stat = "identity", colour = "blue") +
      geom_text(aes(label = ResponseRate16), nudge_y = .5, colour="black") +
      geom_point(aes(y = ResponseRate15), shape = 18, size = 3, colour = "black") +
      geom_text(aes(label = ResponseRate15, y = ResponseRate15), nudge_y = .5, colour="red")
票数 1
EN
查看全部 1 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/42905029

复制
相关文章

相似问题

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