Mix the empty and bquote-d torch marks with the label in ggplot2> = 2.0

Prior to 2.0 in ggplot2, I could use element_blank and labeller to indicate only rows or columns in facet_grid , for example:

 library(ggplot2) g <- ggplot(mtcars) + geom_point(aes(mpg, cyl)) g + facet_grid(vs ~ gear, labeller=labeller(vs = element_blank(), gear = label_bquote(mu == .(x)))) 

Now, with ggplot2 version 2.0, this does not work, providing

 Error in if (attr(labels, "facet") == "wrap") { : argument is of length zero Calls: <Anonymous> ... lapply -> FUN -> <Anonymous> -> x -> resolve_labeller 

Although the improvements are improved in label_bquote , is there a way to do the above labeller work?

I tried:

1) passing NULL , but by default it borders on label_value (according to ?label_bquote )

  g + facet_grid(vs ~ gear, labeller = label_bquote( rows = NULL, cols = mu == .(gear))) 

2) passing by element_blank , but the faces say element_blank()

 g + facet_grid(vs ~ gear, labeller = label_bquote( rows = element_blank(), cols = mu == .(gear))) 

3) wrapper element_blank in as_labeller

 g + facet_grid(vs ~ gear, labeller=labeller(.rows = as_labeller(element_blank()), .cols = label_bquote(mu == .(gear)))) 

Note you can remove facet labels after the fact using the subject

 g + facet_grid(vs ~ gear, labeller = label_bquote(cols = mu == .(gear))) + theme(strip.text.y = element_blank()) 

But I would like to do this with a labeller .

+7
r ggplot2
source share
1 answer

You can do rows="" or rows = ` ` . This will save you shortcuts, although you will still have an empty gray bar.

For clarity, this is a complete command:

  g + facet_grid(vs ~ gear, labeller = label_bquote(rows = "", cols = mu == .(gear))) 

You can also get rid of the gray bar by adding theme(strip.text.y = element_blank()) .

+3
source share

All Articles