与geom_errorbar的position_dodge [英] position_dodge with geom_errorbar

查看:53
本文介绍了与geom_errorbar的position_dodge的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下代码

require(ggplot2)
pd <- position_dodge(0.3)
ggplot(dt, aes(x=Time, y=OR, colour=Group)) + 
    geom_errorbar(aes(ymin=CI_lower, ymax=CI_upper), colour="black", width=.4, position=pd) +
    geom_point(size=2.2, position=pd) +
    geom_hline(aes(yintercept=1), colour="#990000", linetype="dashed")

产生这个

和未定义错误 ymax:改用y调整位置

数据为:

dt <- structure(list(CI_upper = c(1.93, 1.34, 0.73, 0.69, 0.99, 0.81), CI_lower = c(0.54, 0.66, 0.34, 0.48, 0.34, 0.49), Time = structure(c(1L, 1L, 2L, 2L, 3L, 3L), .Label = c("1", "2", "12"), class = "factor"), 
OR = c(1.02, 0.94, 0.5, 0.58, 0.58, 0.63), Group = c("D", 
"ND", "D", "ND", "D", "ND"
)), .Names = c("CI_upper", "CI_lower", "Time", "OR", "Group"), row.names = c(NA, 6L), class = "data.frame")

任何人都可以告诉我如何将闪避以及错误点应用于误差条吗?

Could anyone show me how to apply the dodge to the error bar as well as the points ?

推荐答案

它需要一个分组变量:

ggplot(dt, aes(x=Time, y=OR, colour=Group)) + 
  geom_errorbar(aes(ymin=CI_lower, ymax=CI_upper, colour=NULL, group=Group),  
                 position=pd) +
  geom_point(size=2.2, position=pd) +
  geom_hline(aes(yintercept=1), colour="#990000", linetype="dashed")

这篇关于与geom_errorbar的position_dodge的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆