Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove the grey background from a facet_grid() (ggplot2) [duplicate]

Tags:

r

ggplot2

facet

I have the following plot:

enter image description here

obtained by executing:

ggplot() + 
  stat_summary( data = test_data1, aes(x=x, y=(1-value) , colour = as.factor(1) , lty = as.factor(1) ) , fun.y=mean, geom="line" ,  size=1 ) +
  stat_summary( data = test_data1, aes(x=x, y=(1-value) , colour = as.factor(1), shape=as.factor(1) ) , fun.y=mean, geom="point" ,  size=3, pch=21, fill="white" ) +
  stat_summary( data = test_data2, aes(x=x, y=(1-value) , colour = as.factor(2), lty = as.factor(2) ) , fun.y=mean, geom="line", size=1 ) +
  stat_summary( data = test_data2, aes(x=x, y=(1-value) , colour = as.factor(2), shape=as.factor(2)) , fun.y=mean, geom="point", size=3, pch=21, fill="white" ) +
  theme_bw(base_size = 14, base_family = "Palatino") + 
  theme(legend.key = element_blank() ) +
  expand_limits(x=c(0), y=c(0)) +
  facet_grid(distance ~ . ) 

How do I get rid of the grey background appearing behind 100 and 200.

I would like that to be white, without changing the rest of the theme I am using at the moment.

like image 457
cross Avatar asked Sep 04 '25 03:09

cross


1 Answers

After googling a bit more I found this post, which explains different manipulations that can be applied to facet.

In turns out my question can be solved by doing:

theme(legend.key = element_blank(), strip.background = element_rect(colour="red", fill="#CCCCFF") ) 

Using strip.background = element_rect(colour="red", fill="#CCCCFF") inside theme() does the work.

like image 166
cross Avatar answered Sep 06 '25 11:09

cross