Error bars are displayed using an open character.

I have a graph with pairs of points that are slightly offset. Each pair of points has corresponding error bars. I pointed out that the symbol of the first point in the pair is different from the symbol of the second (closed circle versus open circle). I would like the error bars not to be displayed through the open character.

Here is the dataset:

x = runif(4,-2,2) x_1 = runif(4,-1,3) dfr <- data.frame( x = c(x, x_1), y = rep(c("A","B","C","D"), 2), upper = c(x+2, x_1+1), lower = c(x-2, x_1-2), type = rep(c("alpha", "beta"), each = 4)) 

And here is the plot:

 dodge=position_dodge(width=0.5) ggplot(dfr,aes(x=y,y=x,colour=type)) + geom_point(size=8,aes(shape=type),position=dodge) + geom_errorbar(aes(ymax=upper,ymin=lower),position = dodge) + scale_colour_manual(values = c('gray','black')) + scale_shape_manual(values = c(19,21)) + coord_flip() + opts(legend.position="none") 

rplot

Thanks for any help you can provide!

+6
source share
2 answers

I canโ€™t figure out how to make an โ€œopenโ€ point and prevent the error bar from being displayed. The only way to do this is to fill the dots with the same color as the background, but then your grid lines will not be visible through the dot.

To do this, draw a fill aesthetic type and specify scale_fill_manual with the fill color grey90 , which is the theme_grey parameter:

 ggplot(dfr,aes(x=y,y=x,colour=type, fill=type)) + geom_errorbar(aes(ymax=upper,ymin=lower),position = dodge) + geom_point(size=8,aes(shape=type),position=dodge) + scale_colour_manual(values = c('gray','black')) + scale_fill_manual(values=c('grey', 'grey90')) + scale_shape_manual(values = c(19,21)) + coord_flip() + opts(legend.position="none") 

enter image description here

+4
source

Why don't you just use color , as shown in the modified code below. It will also fill black circles. Not sure if this is acceptable.

 ggplot(dfr,aes(x=y,y=x,colour=type)) + geom_point(size=8,position=dodge) + geom_errorbar(aes(ymax=upper,ymin=lower),position = dodge) + scale_colour_manual(values = c('gray','black')) + coord_flip() + opts(legend.position="none") 
+1
source

Source: https://habr.com/ru/post/895072/


All Articles