How to place divisions between facet grid lines

2019-06-21 15:50发布

问题:

I'm using ggplot with facet_grid to make a plot for publication. I'm not sure how the reviewers will react to the standard gray background with white grid lines and so I'm preparing with and without. However when I use opts(panel.background = theme_blank()) the display lacks the between panes discrimination that the standard background gives. what is the easiest way to add the between pane grid back (not that it was there but it was white against gray) that looks similar to my desired outcome below?

The Code

ggplot(CO2, aes(conc)) + geom_density() + 
    facet_grid(Type~Treatment) +
    opts(panel.background = theme_blank())

Current Outcome

Desired Outcome

Thank you in advance.

回答1:

This should do:

last_plot() + theme_bw()

or

last_plot() + 
   opts(panel.background = theme_rect(fill = NA, color = "black"))

Since version 0.9.2, opts has been replaced by theme:

last_plot() + 
   theme(panel.background = element_rect(fill = NA, color = "black"))


标签: r ggplot2