ggplot jitter geom_errorbar?

ggplot jitter geom_errorbar?,r,ggplot2,R,Ggplot2,我的数据如下所示: df1 <- structure( list( y = c(-0.19, 0.3,-0.05, 0.15,-0.05, 0.15), lb = c(-0.61, 0.1,-0.19,-0.06,-0.19,-0.06), ub = c(0.22, 0.51, 0.09, 0.36, 0.09, 0.36), x = structure( c(1

我的数据如下所示:

df1 <-
  structure(
    list(
      y = c(-0.19, 0.3,-0.05, 0.15,-0.05, 0.15),
      lb = c(-0.61,
             0.1,-0.19,-0.06,-0.19,-0.06),
      ub = c(0.22, 0.51, 0.09, 0.36,
             0.09, 0.36),
      x = structure(
        c(1L, 2L, 1L, 2L, 1L, 2L),
        .Label = c("X1",
                   "X2"),
        class = "factor"
      ),
      Group = c("A", "A", "B", "B", "C",
                "C")
    ),
    .Names = c("y", "lb", "ub", "x", "Group"),
    row.names = c(NA,-6L),
    class = "data.frame"
  )

您可以使用
位置减淡
来实现所需的顺序和在点位置绘制的错误条

ggplot(data = df1, aes(x, y, color = Group)) +
    geom_point(size = 4, position=position_dodge(width=0.5)) +
    geom_errorbar(
        aes(ymin = lb, ymax = ub),
        width = 0.1,
        linetype = "dotted",
        position=position_dodge(width=0.5)) +
    geom_hline(aes(yintercept = 0), linetype = "dashed") + 
    theme_bw()

如果您想要抖动,我喜欢这样:

ggplot(data = df1, aes(x, y, color = Group)) +
    geom_pointrange(aes(ymin = lb, ymax = ub), 
                    position=position_jitter(width=0.5), 
                    linetype='dotted') +
    theme_bw()

这是一个很好的答案,但如果每个x轴类别中有多个点,该怎么办<代码>位置\宽度将所有点放置在垂直线上,以便错误条在类别内重叠。是否有办法在类别内实现进一步的抖动,并且仍然将错误条与点对齐?@EcologyTom您可以定义一个新的因子,该因子考虑到每个类别中的点数?例如,如果你在A类中有2分,你的因子水平将是A1、A2、B、C。。我认为没有一种方法可以像你描述的那样将闪避和抖动结合起来,这似乎是一个很好的解决方法。我最终找到了解决办法。但是你的建议会更直截了当,特别是如果没有太多的要点的话。谢谢
ggplot(data = df1, aes(x, y, color = Group)) +
    geom_pointrange(aes(ymin = lb, ymax = ub), 
                    position=position_jitter(width=0.5), 
                    linetype='dotted') +
    theme_bw()