Change midline color ggplot geom_boxplot ()

I would like to change the color of the midline in geom_boxplot() . I looked and can not find a way to do this. I have posted here the R code that I am using, but I just need a link on how to change the color.

 ggplot(invitro2) + geom_boxplot(aes(x = reorder(CANCER_TYPE,tmedian), y = GeoMedian_IC50)) + xlab("") + geom_point(aes(x = reorder(CANCER_TYPE,tmedian), y = GeoMedian_IC50)) + theme_bw() + scale_y_log10(breaks = trans_breaks("log10", function(x) 10^x), labels = trans_format("log10", math_format(10^.x))) + annotation_logticks(sides="l") + theme(axis.text.x=element_text(angle=45,size=10,hjust=1), panel.grid.major = element_blank()) 
+7
r ggplot2
source share
1 answer

You can use the details of the graph to get the coordinates where the middle line is, and then add color to it using geom_segment .

 library(ggplot2) p <- ggplot(mtcars, aes(factor(am), mpg)) + geom_boxplot() dat <- ggplot_build(p)$data[[1]] p + geom_segment(data=dat, aes(x=xmin, xend=xmax, y=middle, yend=middle), colour="red", size=2) 

It was also necessary to increase the size line so that it covered the original black median Line

+9
source share

All Articles