Navigation Menu

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error when facet strip.text = element_blank() #200

Closed
nstjhp opened this issue Jul 2, 2020 · 1 comment
Closed

Error when facet strip.text = element_blank() #200

nstjhp opened this issue Jul 2, 2020 · 1 comment

Comments

@nstjhp
Copy link

nstjhp commented Jul 2, 2020

The issue arose when I wanted to make arrange plots where I had removed the facet strip completely. I isolated the problem down to the removal of the strip.text.
As an example

facet_with_labels <- function(df) {
    ggplot(df, aes(hp, mpg)) +
    facet_wrap(gear~., ncol=1) + geom_point() }
facet_no_strip_bg <- function(df) {
    ggplot(df, aes(hp, mpg)) +
    facet_wrap(gear~., ncol=1) + geom_point() + theme(strip.background = element_blank())}
facet_no_striptext <- function(df) {
    ggplot(df, aes(hp, mpg)) +
    facet_wrap(gear~., ncol=1) + geom_point() + theme(strip.text = element_blank())}

p_with = facet_with_labels(mtcars)
p_no_bg = facet_no_strip_bg(mtcars)
p_no_striptext = facet_no_striptext(mtcars)

All individual plots are OK:

p_with
p_no_bg
p_no_striptext

Combined plot, one with blank facet strip background is OK

p_with + p_no_bg

tmp

Combined plot, one with blank facet strip text fails

p_with + p_no_striptext
Error in unit(height, default.units) : 
  'x' and 'units' must have length > 0

Combined plot, both without strips (my use case)

p_no_striptext + p_no_striptext
Error in unit(height, default.units) : 
  'x' and 'units' must have length > 0

What I wanted:

cowplot::plot_grid(p_no_striptext, p_no_striptext)

tmpCOW

sessionInfo()
R version 3.6.1 (2019-07-05)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 19.10

Matrix products: default
BLAS:   /usr/lib/x86_64-linux-gnu/blas/libblas.so.3.8.0
LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.8.0

locale:
 [1] LC_CTYPE=en_GB.UTF-8       LC_NUMERIC=C              
 [3] LC_TIME=en_GB.UTF-8        LC_COLLATE=en_GB.UTF-8    
 [5] LC_MONETARY=en_GB.UTF-8    LC_MESSAGES=en_GB.UTF-8   
 [7] LC_PAPER=en_GB.UTF-8       LC_NAME=C                 
 [9] LC_ADDRESS=C               LC_TELEPHONE=C            
[11] LC_MEASUREMENT=en_GB.UTF-8 LC_IDENTIFICATION=C       

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] patchwork_1.0.1 ggplot2_3.3.1  

loaded via a namespace (and not attached):
 [1] digest_0.6.25    withr_2.2.0      dplyr_1.0.0      crayon_1.3.4    
 [5] grid_3.6.1       R6_2.4.1         lifecycle_0.2.0  gtable_0.3.0    
 [9] magrittr_1.5     scales_1.1.1     pillar_1.4.4     rlang_0.4.6     
[13] farver_2.0.3     generics_0.0.2   vctrs_0.3.1      ellipsis_0.3.1  
[17] labeling_0.3     glue_1.4.1       purrr_0.3.4      munsell_0.5.0   
[21] compiler_3.6.1   pkgconfig_2.0.3  colorspace_1.4-1 tidyselect_1.1.0
[25] tibble_3.0.1 
@iagomosqueira
Copy link

I noticed this problem after moving to R 4.0.2

This test works in R 3.6.3 but not in R 4.0.2

library(patchwork)
data(cars)

(ggplot(cars, aes(x=speed, y=dist)) + geom_line()) +
(ggplot(cbind(cars, facet=1), aes(x=speed, y=dist)) + geom_point() + facet_wrap(~facet) +
  theme(strip.text = element_blank()))

If I compare the object returned by the second ggplot call, they do not appear to be different (all.equal is TRUE).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants