【发布时间】:2018-07-01 09:43:59
【问题描述】:
我想用我的条形图绘制误差线和文本。为了制作一个漂亮且可读的图,我希望geom_text 元素的左侧(用于左侧栏)和右侧(用于右侧栏)的误差线。我会使用position_dodge 来执行此操作,但不知何故,如果条形图未分组,这将没有影响。
这是我的代码:
df1 <- data.frame(e=c(0.02,0.02), na=c("A","B"), value=c(0.25, 0.75))
ggplot(df1, aes(x=factor(na), y=value, fill=factor(na)))+
geom_bar(stat="identity", width=0.2)+
geom_errorbar(aes(ymin = value-e, ymax = value+e), width = 0.01, size=0.5,
alpha=.6)+
geom_text(aes(label=paste0(round(value*100,0),"%"), vjust=-0.5),
size=5)
这会产生相同的情节:
ggplot(df1, aes(x=factor(na), y=value, fill=factor(na)))+
geom_bar(stat="identity", width=0.2)+
geom_errorbar(aes(ymin = value-e, ymax = value+e), width = 0.01, size=0.5,
alpha=.6, position=position_dodge(width=0.2))+
geom_text(aes(label=paste0(round(value*100,0),"%"), vjust=-0.5),
size=5)
如何向左/向右移动我的错误栏?
谢谢
【问题讨论】: