r - 条形图的误差线仅在一个方向

标签 r plot ggplot2 bar-chart data-visualization

是否可以调整 ggplot2 中的误差条,使其仅在一个方向上绘制(例如,仅向上而不是向下)?

df <- data.frame(trt = factor(c(1, 1, 2, 2)), resp = c(1, 5, 3, 4),
                 group = factor(c(1, 2, 1, 2)), se = c(0.1, 0.3, 0.3, 0.2))
df2 <- df[c(1,3), ]

limits <- aes(ymax = resp + se, ymin = resp - se)
dodge <- position_dodge(width = 0.9)

p <- ggplot(df, aes(fill = group, y = resp, x = trt))
p + geom_bar(position = dodge, stat = "identity") +
    geom_errorbar(limits, position = dodge, width = 0.25)

Rplot

最佳答案

一个简单的解决方法是先绘制误差线:

p +
  geom_errorbar(limits, position = dodge, width=0.25) +
  geom_bar(position = dodge, stat = "identity")

enter image description here

关于r - 条形图的误差线仅在一个方向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27585776/

相关文章:

R download.file,下载excel文件不起作用

python - 使用 hexbin 的 Pairplot

plot - 使用 gnuplot 的迭代参数图

r - 如何使 ggplot2 中每个方面的 y 轴比例相同?

r - 是否可以在带有 ggplot geom_sf 的 map 中使用单独的固定颜色

r - 如何在水平条形图中绘制各个组件?

r - 使用变量名通过 mutate 定义列内容

使用小平面和翻转坐标删除 ggplot boxplot 中未使用的级别?

r - 为最后五个元素创建一个最多有两个向量的向量

r - 如何用ggplot2缩放第二个轴,第二个轴有负值