ggplot2 - Background bands with ggplot in R -
i'm trying create box plots different groups. i'd color background in 3 horizontal bands. central 1 there observations near overall mean
mean(weight)-0.5 < x < mean(weight)+0.5
the other 2 bands below , upper ones.
theese plot
library(ggplot2) bp <- ggplot(data=plantgrowth, aes(x=group, y=weight, fill=group)) + geom_boxplot() bp
use geom_rect:
bp <- ggplot(data=plantgrowth, aes(x=group, y=weight, fill=group)) + geom_rect(ymin = -inf, ymax = lwwt, xmin = -inf, xmax = inf, fill = 'blue') + geom_rect(ymin = lwwt, ymax = upwt, xmin = -inf, xmax = inf, fill = 'pink') + geom_rect(ymin = upwt, ymax = inf, xmin = -inf, xmax = inf, fill = 'skyblue') + geom_boxplot() print(bp) ggsave("example.jpg", bp) which gives figure:
hopefully you'll change background colors :)