当我使用以下代码生成图表时,误差线处于奇怪的位置。你能告诉我如何让错误栏显示在条形图中每个栏的顶部吗?我知道这是基本的,但我已经盯着它看了好几个小时了。谢谢。
library(ggplot2)
df <- data.frame(gender=c("male","male","female","female"),
trait=c("height","weight","height","weight"),
value=c(70,150,65,120),
sd = c(5,15,4,10))
gg <- ggplot(df,aes(x=trait,y=value,fill=trait))
gg <- gg+ geom_bar(stat="identity",position=position_dodge())
gg <- gg + facet_wrap(~ gender, ncol=1)
limits <- aes(ymax=df$value+df$sd, ymin=df$value-df$sd)
gg <- gg + geom_errorbar(limits)
#gg <- gg + geom_pointrange(limits)
gg