One would like to colour the background of selected facet_wrap
facets using the theme
and panel.background
arguments, as explained here. However, as explained here, theme
doesn't map onto data, so one is forced to colour selected facets using geom_rect
and fill
, and making the alpha
quite transparent.
The code below works. However, I find that the colouring isn't pretty, especially when dealing with large data that forces increasing the transparency.
mtcars %>%
ggplot(aes(mpg, cyl)) +
facet_wrap(~gear) +
geom_point() +
geom_rect(data = mtcars %>% filter(gear == 3), fill = 'red',
xmin = -Inf,xmax = Inf,
ymin = -Inf,ymax = Inf,
alpha = 0.003)
Is there an alternative way of colouring selected facets, ideally using theme
and panel.background
?