Hi I am struglling with getting labels in a grouped horizontal barplot in the right position. I know that there have been similar questions before but I dont seem to ge the answers to work.
My data ("Correlation") looks like this:
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 *
And my code:
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) )
But howevery I adjust the parameters, the stars are never quite centered vertically + the distance to the errorbars is different each time :
Adding "se" to the y-parameter in geom_text also doesnt make the stars to be in the same distance to the error-bars ( for the error-bars that go in the negative direction )
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) )
Does anybody have a solution? I would be very greatful
label
argument to something like"o"
or"I"
to see that. I'm thinking there might be a unicode you can use instead for a star shape that is centered – camille