I am attempting to to control ggplot2 theme plot.background element.rect.
What I want:
On this case, I want a single dotted element.rect line around the background that contains all the patched plots.
What I have attempted:
Used the "&" to patch a theme element.rect which adds rect around all plots.
Here is the reprex:
library(ggplot2)
library(patchwork)
g1 <- ggplot(mtcars, aes(wt, mpg)) +
theme_void() +
theme(panel.background = element_rect(fill ="gray76", color = 'red', size = 1),
plot.background = element_rect(color = NA, size = 4))
g2 <- ggplot(mtcars, aes(wt, mpg)) +
theme_void() +
theme(panel.background = element_rect(fill ="gray76", color = 'red', size = 1),
plot.background = element_rect(color = "brown", size = 4))
g3<- ggplot(mtcars, aes(wt, mpg)) +
theme_void() +
theme(panel.background = element_rect(fill ="gray76", color = 'red', size = 1))
g1 + g2 + g3 +
plot_layout(nrow = 1, widths = c(1, 2, 1)) &
theme(plot.margin = unit(c(.2,.2,.2,.2), "cm")) &
theme(plot.background = element_rect(color = 'blue', size = 2,linetype = 'dotted', fill ="ivory"))
Here is the rendered plot: