New error when removing facet strip from ggplots

36 views
Skip to first unread message

Sam Zipper

unread,
Oct 6, 2017, 7:04:55 PM10/6/17
to ggplot2
I'm attempting to remove the facet strips from a plot. My issue is analogous to a question posed on StackOverflow here: https://stackoverflow.com/questions/46347656/ggplot2-error-when-setting-facet-strip-to-element-blank

Here is some example code: 
# generate data
gdat
<- data.frame(a = rep(LETTERS[1:10], 10), x = rnorm(100), y = rnorm(100))

# make plot with labels
g <- ggplot(gdat, aes(x = x, y = y)) + geom_point() + facet_wrap(~a)

# make plot without labels
g
+ theme(strip.background = element_blank(), strip.text = element_blank()

# returns an error:
Error in apply(strip_mat, 1, max_height) :
  dim
(X) must have a positive length

# stackoverflow answer:
g
+ theme(strip.background=element_blank(), strip.text=element_text(color="transparent"), panel.spacing.y=unit(-0.8, "lines"))

The StackOverflow response to the question is workable, but not particularly satisfying because it requires defining the space between plots with the `panel.spacing.y` option. This means that, if I am producing plots of different sizes, then I have to re-tune the spacing so things line up correctly. 

I am curious whether anyone is aware of a solution to delete the facet strips while preserving the automatic spacing between the panels?

Previously, the facet strips would just be deleted and the spacing would be automatic, just as the x-spacing is set automatically. My script worked last time I ran it (~5 weeks ago) and I recently updated ggplot, so I am guessing this may be an unintended consequence of the upgrade. I am using ggplot 2.2.1.9000 and R v3.4.2. 

Brandon Hurr

unread,
Oct 9, 2017, 9:34:56 AM10/9/17
to Sam Zipper, ggplot2
Sam, 

I prodded the development team and this was a bug that is now fixed. There was a very large rewrite of the faceting system and this possibility was overlooked when recoding. 

Many thanks to Thomas for the quick fix. 



It looks like Hadley has merged this with the master already. I believe you should be able to install this version and test it with:
devtools::install_github("tidyverse/ggplot2")

Thanks for pointing it out and for the reproducible example. Very helpful. 

Brandon



--
--
You received this message because you are subscribed to the ggplot2 mailing list.
Please provide a reproducible example: https://github.com/hadley/devtools/wiki/Reproducibility
 
To post: email ggp...@googlegroups.com
To unsubscribe: email ggplot2+unsubscribe@googlegroups.com
More options: http://groups.google.com/group/ggplot2

---
You received this message because you are subscribed to the Google Groups "ggplot2" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ggplot2+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages