Remove endpoints from error bars in ggplot2

My goal is to create boxes in R (itโ€™s not necessary to be with ggplot2, but what Iโ€™m using now) that are stylistically similar to this example I found somewhere (minus the text):

boxplot-example

Here is the code that I still have:

dat <- read.table(file = "https://www.dropbox.com/s/b59b03rc8erea5d/dat.txt?dl=1", header = TRUE, sep = " ") library(ggplot2) p <- ggplot(dat, aes(x = Subscale, y = Score, fill = Class)) p + stat_boxplot(geom = "errorbar", width = 1.2, size = 2.5, color = "#0077B3") + geom_boxplot(outlier.shape = NA, coef = 0, position = position_dodge(.9)) + scale_fill_manual(values = c("#66CCFF", "#E6E6E6")) + theme(panel.background = element_rect(fill = "white", color = "white")) 

Result:

my-boxplot

Obviously, there are many differences between what I have and what the example shows, but now I focus only on removing the endpoints from the error bars, by which I mean the horizontal upper and lower parts created by stat_boxplot . Does anyone know a way that I can get the desired effect?

+6
source share
1 answer

width in the errorbar geometry controls the width of the horizontal end bars, so set this to 0 to remove the end bars. You do not have enough dodging in the stat_boxplot layer, so you can add this to correctly avoid errors.

 ggplot(dat, aes(x = Subscale, y = Score, fill = Class)) + stat_boxplot(geom = "errorbar", width = 0, size = 2.5, color = "#0077B3", position = position_dodge(.9)) + geom_boxplot(outlier.shape = NA, coef = 0, position = position_dodge(.9)) + scale_fill_manual(values = c("#66CCFF", "#E6E6E6")) + theme(panel.background = element_rect(fill = "white", color = "white")) 

enter image description here

+5
source

All Articles