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

plot_grid() interaction with theme_set() #60

Closed
crsh opened this issue Feb 24, 2017 · 6 comments
Closed

plot_grid() interaction with theme_set() #60

crsh opened this issue Feb 24, 2017 · 6 comments

Comments

@crsh
Copy link

crsh commented Feb 24, 2017

Hi there,

thanks for this useful package. Since one of the more recent updates (before updating to the current version I used 0.6.2) I'm experiencing some weird issues with the interaction between plot_grid(), theme_set(), and a theme of mine that modifies axis.text.x.

Everything works great as long as I don't use theme_set().

Works as expected:

library("ggplot2")
library("cowplot")

df <- data.frame(
  gp = factor(rep(letters[1:3], each = 10)),
  y = rnorm(30)
)

test <- ggplot(df, aes(gp, y)) +
  geom_point() +
  theme_classic() + 
  theme(axis.text.x = element_text())

plot_grid(test)

Throws an error:

theme_set(theme_classic() + theme(axis.text.x = element_text()))

test2 <- ggplot(df, aes(gp, y)) +
  geom_point()

plot_grid(test2)
Error in element_grob.element_text(el, ...) : 
  Text element requires non-NULL value for 'angle'.

If I set angle I get another error:

theme_set(theme_classic() + theme(axis.text.x = element_text(angle = 0)))

plot_grid(test2)
Error in if (debug) { : Argument has length 0

Now, if I set debug = FALSE it finally works, but I get some weird numbering on the bottom margin.

rplot

This is my session info:

Session info ---------------------------------------------------------------------------------------------------------------------------
 setting  value                       
 version  R version 3.3.2 (2016-10-31)
 system   x86_64, linux-gnu           
 ui       RStudio (1.0.136)           
 language de_DE                       
 collate  de_DE.UTF-8                 
 tz       <NA>                        
 date     2017-02-24                  

Packages -------------------------------------------------------------------------------------------------------------------------------
 package    * version  date       source                           
 assertthat   0.1      2013-12-06 CRAN (R 3.3.0)                   
 colorspace   1.2-6    2015-03-11 CRAN (R 3.3.0)                   
 cowplot    * 0.7.0    2017-02-24 Github (wilkelab/cowplot@78336ac)
 devtools     1.12.0   2016-06-24 CRAN (R 3.3.1)                   
 digest       0.6.11   2017-01-03 CRAN (R 3.3.2)                   
 ggplot2    * 2.2.1    2016-12-30 CRAN (R 3.3.2)                   
 gtable       0.2.0    2016-02-26 CRAN (R 3.3.0)                   
 labeling     0.3      2014-08-23 CRAN (R 3.3.0)                   
 lazyeval     0.2.0    2016-06-12 CRAN (R 3.3.0)                   
 memoise      1.0.0    2016-01-29 CRAN (R 3.3.0)                   
 munsell      0.4.3    2016-02-13 CRAN (R 3.3.0)                   
 plyr         1.8.4    2016-06-08 CRAN (R 3.3.0)                   
 Rcpp         0.12.9.3 2017-02-24 Github (RcppCore/Rcpp@8bf15c0)   
 scales       0.4.1    2016-11-09 CRAN (R 3.3.2)                   
 tibble       1.2      2016-08-26 CRAN (R 3.3.1)                   
 withr        1.0.2    2016-06-20 CRAN (R 3.3.1)
@clauswilke
Copy link
Contributor

This is a bug in ggplot2, specifically in theme_void(). Please report there. Here is how to show it's a ggplot2 bug:

library("ggplot2")
df <- data.frame(gp = factor(rep(letters[1:3], each = 10)), y = rnorm(30))
theme_set(theme_classic() + theme(axis.text.x = element_text()))

test2 <- ggplot(df, aes(gp, y)) + geom_point()

test2 # works
test2 + theme_void() # doesn't work

@crsh
Copy link
Author

crsh commented Feb 24, 2017

Thanks, will do.

@crsh crsh closed this as completed Feb 24, 2017
@clauswilke
Copy link
Contributor

Work-around:

In ggplot2:

test2 + theme_void() + theme(axis.text.x = NULL) # works

In `cowplot:

assignInNamespace("theme_nothing", function(){theme_void() + theme(axis.text.x = NULL)}, "cowplot")
plot_grid(test2) # works now

I don't want to make this change in the cowplot package, because theme_void() should work properly and I shouldn't have to work around its bugs.

@FMKerckhof
Copy link

FMKerckhof commented May 4, 2017

Hi Claus, I tried the workaround with assignInNamespace (I take it that all changed theme elements should be set to NULL) but keep ending up with the same Error in if (debug) { : Argument has length 0 error. The only thing that does help is detaching and reloading the cowplot package right before the call to plot_grid. Do you think this is the same bug in theme_void() causing this behavior? Am I missing something in how your suggested workaround operates?

My devtools::session_info() is the following:

Session info -------------------------------------------------------------------
 setting  value
 version  R version 3.4.0 (2017-04-21)
 system   x86_64, linux-gnu
 ui       X11
 language en_US:en
 collate  en_IE.UTF-8
 tz       Europe/Brussels
 date     2017-05-04

Packages -----------------------------------------------------------------------
 package              * version  date       source
 acepack                1.4.1    2016-10-29 CRAN (R 3.3.2)
 ade4                   1.7-6    2017-03-23 CRAN (R 3.3.3)
 annotate               1.54.0   2017-05-04 Bioconductor
 AnnotationDbi          1.38.0   2017-05-04 Bioconductor
 ape                    4.1      2017-02-14 CRAN (R 3.3.2)
 assertthat             0.2.0    2017-04-11 CRAN (R 3.3.3)
 backports              1.0.5    2017-01-18 CRAN (R 3.3.2)
 base64enc              0.1-3    2015-07-28 CRAN (R 3.3.1)
 Biobase              * 2.36.0   2017-05-04 Bioconductor
 BiocGenerics         * 0.22.0   2017-05-04 Bioconductor
 BiocParallel           1.10.0   2017-05-04 Bioconductor
 biomformat             1.4.0    2017-05-04 Bioconductor
 Biostrings             2.44.0   2017-05-04 Bioconductor
 bitops                 1.0-6    2013-08-17 CRAN (R 3.1.0)
 checkmate              1.8.2    2016-11-02 CRAN (R 3.3.2)
 cluster                2.0.6    2017-03-16 CRAN (R 3.3.3)
 codetools              0.2-15   2016-10-05 CRAN (R 3.3.1)
 colorspace             1.3-2    2016-12-14 CRAN (R 3.3.2)
 cowplot              * 0.7.0    2016-10-28 CRAN (R 3.4.0)
 data.table             1.10.4   2017-02-01 CRAN (R 3.3.2)
 DBI                    0.6-1    2017-04-01 CRAN (R 3.3.3)
 DelayedArray         * 0.2.0    2017-05-04 Bioconductor
 DESeq2               * 1.16.0   2017-05-04 Bioconductor
 devtools             * 1.12.0   2016-12-05 CRAN (R 3.4.0)
 digest                 0.6.12   2017-01-27 CRAN (R 3.3.2)
 dplyr                * 0.5.0    2016-06-24 CRAN (R 3.3.1)
 foreach                1.4.3    2015-10-13 CRAN (R 3.2.3)
 foreign                0.8-68   2017-04-24 CRAN (R 3.4.0)
 Formula                1.2-1    2015-04-07 CRAN (R 3.3.1)
 genefilter             1.58.0   2017-05-04 Bioconductor
 geneplotter            1.54.0   2017-05-04 Bioconductor
 GenomeInfoDb         * 1.12.0   2017-05-04 Bioconductor
 GenomeInfoDbData       0.99.0   2017-05-04 Bioconductor
 GenomicRanges        * 1.28.0   2017-05-04 Bioconductor
 ggplot2              * 2.2.1    2016-12-30 CRAN (R 3.3.2)
 gridExtra              2.2.1    2016-02-29 CRAN (R 3.2.3)
 gtable                 0.2.0    2016-02-26 CRAN (R 3.2.3)
 Hmisc                  4.0-3    2017-05-02 CRAN (R 3.4.0)
 htmlTable              1.9      2017-01-26 CRAN (R 3.3.2)
 htmltools              0.3.6    2017-04-28 CRAN (R 3.4.0)
 htmlwidgets            0.8      2016-11-09 CRAN (R 3.3.2)
 igraph                 1.0.1    2015-06-26 CRAN (R 3.3.1)
 IRanges              * 2.10.0   2017-05-04 Bioconductor
 iterators              1.0.8    2015-10-13 CRAN (R 3.2.3)
 jsonlite               1.4      2017-04-08 CRAN (R 3.3.3)
 knitr                  1.15.1   2016-11-22 CRAN (R 3.3.2)
 lattice              * 0.20-35  2017-03-25 CRAN (R 3.3.3)
 latticeExtra           0.6-28   2016-02-09 CRAN (R 3.3.1)
 lazyeval               0.2.0    2016-06-12 CRAN (R 3.3.1)
 locfit                 1.5-9.1  2013-04-20 CRAN (R 3.4.0)
 magrittr               1.5      2014-11-22 CRAN (R 3.2.1)
 MASS                   7.3-47   2017-04-21 CRAN (R 3.4.0)
 Matrix                 1.2-10   2017-04-28 CRAN (R 3.4.0)
 matrixStats          * 0.52.2   2017-04-14 CRAN (R 3.3.3)
 memoise                1.1.0    2017-04-21 CRAN (R 3.4.0)
 mgcv                   1.8-17   2017-02-08 CRAN (R 3.3.2)
 multtest               2.32.0   2017-05-04 Bioconductor
 munsell                0.4.3    2016-02-13 CRAN (R 3.2.3)
 nlme                   3.1-131  2017-02-06 CRAN (R 3.3.2)
 nnet                   7.3-12   2016-02-02 CRAN (R 3.4.0)
 permute              * 0.9-4    2016-09-09 CRAN (R 3.3.2)
 phyloseq             * 1.20.0   2017-05-04 Bioconductor
 plyr                   1.8.4    2016-06-08 CRAN (R 3.3.1)
 R6                     2.2.0    2016-10-05 cran (@2.2.0)
 RColorBrewer           1.1-2    2014-12-07 CRAN (R 3.3.1)
 Rcpp                   0.12.10  2017-03-19 CRAN (R 3.3.3)
 RCurl                  1.95-4.8 2016-03-01 CRAN (R 3.2.3)
 reshape2               1.4.2    2016-10-22 CRAN (R 3.3.2)
 rhdf5                  2.20.0   2017-05-04 Bioconductor
 rpart                  4.1-11   2017-04-21 CRAN (R 3.4.0)
 RSQLite                1.1-2    2017-01-08 CRAN (R 3.3.2)
 rstudioapi             0.6      2016-06-27 CRAN (R 3.3.1)
 S4Vectors            * 0.14.0   2017-05-04 Bioconductor
 scales                 0.4.1    2016-11-09 CRAN (R 3.3.2)
 stringi                1.1.5    2017-04-07 CRAN (R 3.3.3)
 stringr                1.2.0    2017-02-18 CRAN (R 3.3.2)
 SummarizedExperiment * 1.6.0    2017-05-04 Bioconductor
 survival               2.41-3   2017-04-04 CRAN (R 3.3.3)
 tibble                 1.3.0    2017-04-01 CRAN (R 3.3.3)
 vegan                * 2.4-3    2017-04-07 CRAN (R 3.4.0)
 withr                  1.0.2    2016-06-20 CRAN (R 3.3.1)
 XML                    3.98-1.7 2017-05-03 CRAN (R 3.4.0)
 xtable                 1.8-2    2016-02-05 CRAN (R 3.2.3)
 XVector                0.16.0   2017-05-04 Bioconductor
 zlibbioc               1.22.0   2017-05-04 Bioconductor

@clauswilke
Copy link
Contributor

Please post an example of code that causes this error for you. Thanks!

@clauswilke
Copy link
Contributor

Since this issue is still not resolved in the ggplot2 code base, I have decided to reimplement theme_nothing() so it avoids this problem. So going forward, this will not be a problem anymore.

The code is currently on github and will be in the upcoming cowplot 0.8.0.

library("cowplot")
df <- data.frame(gp = factor(rep(letters[1:3], each = 10)), y = rnorm(30))
theme_set(theme_classic() + theme(axis.text.x = element_text()))

test2 <- ggplot(df, aes(gp, y)) + geom_point()

test2 # works

screen shot 2017-07-28 at 1 22 15 pm

test2 + theme_nothing() # works

screen shot 2017-07-28 at 1 22 53 pm

flying-sheep pushed a commit to flying-sheep/cowplot that referenced this issue Aug 13, 2019
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

3 participants