Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ggplot facet_wrap different themes

Tags:

r

ggplot2

I am looking for a way to facet_wrap different themes in the same %>% line, to get something like

enter image description here

Is there any way to do something similar without having to do

fig1 = mtcars %>% filter(am == 1) %>%
  ggplot(aes(wt, mpg)) +
  geom_point() + 
  theme_bw(base_size = 15) + ggtitle('Theme A')

fig2 = mtcars %>% filter(am == 0) %>%
  ggplot(aes(wt, mpg)) +
  geom_point() + 
 theme_minimal(base_size = 15) + ggtitle('Theme B')

grid.arrange(fig1,fig2, ncol = 2)

Is there a way to display different themes for the facet argument in the same line of code?

If not, even just displaying different colour backgrounds for the facet argument will be helpful.

like image 496
giac Avatar asked May 09 '20 19:05

giac


1 Answers

I would think facets are meant to have the same theme (the only thing changing between facets should only be a column that determines which data goes where and the axes based on certain settings free/fixed/etc.).

As @sam81 suggested, this answer is a good hacked solution based on a comment by hadley

like image 157
Arthur Yip Avatar answered Nov 04 '22 18:11

Arthur Yip