1

我有以下代码

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 not defined: adjusting position using y instead

数据是:

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")

谁能告诉我如何将闪避应用于错误栏和点?

4

1 回答 1

3

它需要一个分组变量:

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")

在此处输入图像描述

于 2013-10-31T12:25:54.020 回答