是否可以调整 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)
最佳答案
一个简单的解决方法是先绘制误差线:
p +
geom_errorbar(limits, position = dodge, width=0.25) +
geom_bar(position = dodge, stat = "identity")
关于r - 条形图的误差线仅在一个方向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27585776/