Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to place divisions between facet grid lines

Tags:

r

ggplot2

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 enter image description here

Desired Outcome

enter image description here

Thank you in advance.

like image 837
Tyler Rinker Avatar asked Mar 14 '12 00:03

Tyler Rinker


1 Answers

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"))
like image 191
baptiste Avatar answered Oct 14 '22 20:10

baptiste