I am trying t o plot a bar plot using ggplot2as follows:
library(ggplot2)
ggplot(mtcars, aes(factor(carb))) +
geom_bar() +
coord_flip()
x axis is a continous variable, while y axis is a categorical one (factor).
I would like to add alternate shading area behind each bar to differentiate the factors in y axis. I know I can use geom_rect() for this. How to calculate the y axis limits for the area, when it is a factor? x axis limits for the rectangles would be -Inf to Inf.
I am looking for something along the lines of this image, but for barplots instead of boxplots.




