R ggplot: suppress the bottom of the error bar on geom_bar

I am drawing line plots with errors, but I cannot figure out how to suppress the bottom of the error bar. Does anyone know how I can do this?

This is my code:

barplot <- qplot(x=..., y=mean, fill=variable,
             data=dat, geom="bar", stat="identity",
             position="dodge")

barplot + geom_errorbar(aes(ymax=upper, ymin=lower), 
                    position=position_dodge(7),
                    data=dat)

      

So, the goal is that the plot only shows a portion of the error bar which is defined by "ymax = upper" but "ymin = lower" does not.

I tried to give each cell in the "lower" column a value of zero, but that didn't work:

dat<- transform(dat, lower="0", upper=mean+sem)

      

Ok, thanks in advance!

+3


source to share


1 answer


I know the post is out of date, but I am facing this problem now. These options work if you want to add geom_errorbar to geom_bar, but if you want to plot geom_point + geom_bar, a horizontal line will appear above your point.

I have found a "trap" to solve this problem.



ggplot(data, (aes(x...) + geom_point() + 
geom_errorbar(aes(ymin = upper, ymax = upper)) + 
geom_linerange(aes(ymin = mean, ymax = upper))

      

Using this code, you only get the top line, because the bottom line overlaps the top one, and with this geom_linerange

you get a vertical line.

+2


source







All Articles