【发布时间】:2019-01-06 17:05:43
【问题描述】:
您好,我正在努力在正确位置的分组水平条形图中获取标签。我知道以前也有类似的问题,但我似乎没有找到工作的答案。
我的数据(“相关性”)如下所示:
Trait r se Disease significant
1 0.4 0.06 A *
1 0.1 0.06 B
1 -0.05 0.03 C
2 0.4 0.06 A *
2 0.1 0.05 B
2 -0.06 0.03 C *
3 0.04 0.06 A *
3 0.2 0.05 B *
3 0.3 0.04 C *
还有我的代码:
grouped_plot <- ggplot(data=Correlation, aes(x=Trait, y=r,
fill=Disease)) + geom_bar(stat="identity", position="dodge",
width=0.9)+ geom_errorbar(aes(ymin = r - se, ymax = r + se),
width = 0.3, position=position_dodge(0.9), stat="identity",
color=rgb(100,100,100, maxColorValue = 255)) + coord_flip() +
theme_minimal() +
scale_y_continuous(breaks=seq(-0.8,0.8,by=0.1)) +
theme(legend.position="none") + ggtitle("XXX") + theme(plot.title =
element_text(size=11) )
grouped_plot + geom_text(aes(x=Trait, y=r + 0.07 * sign(r),
label=format(significant), hjust=ifelse(r>0,0,1)),
position=position_dodge(0.9), size=5, color=rgb(100,100,100,
maxColorValue = 255) )
但是无论我调整参数,星星从来没有完全垂直居中+每次到误差条的距离都不一样:
在 geom_text 的 y 参数中添加“se”也不会使星星与误差线的距离相同(对于朝负方向的误差线)
grouped_plot + geom_text(aes(x=Trait, y=r +se + 0.01 * sign(r),
label=format(significant), hjust=ifelse(r>0,0,1)),
position=position_dodge(0.9), size=5, color=rgb(100,100,100, maxColorValue
= 255) )
有人有解决办法吗?我会很感激的
【问题讨论】:
-
我在搞砸这个时看到的一件事是它似乎部分是印刷的。星号略带上标;将
label参数更改为"o"或"I"以查看。我在想可能有一个 unicode 可以用来代替居中的星形 -
我确实有所作为——谢谢!