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

cannot apply check_model title with patchwork::plot_annotation #712

Closed
qdread opened this issue Apr 17, 2024 · 4 comments · Fixed by easystats/see#339
Closed

cannot apply check_model title with patchwork::plot_annotation #712

qdread opened this issue Apr 17, 2024 · 4 comments · Fixed by easystats/see#339

Comments

@qdread
Copy link

qdread commented Apr 17, 2024

I recently tried to run some code from 2022 again, where I applied a title to a check_model() plot using patchwork::plot_annotation(). It returns an error which I've unsuccessfully tried to debug. This reprex should be equivalent to the code I'm trying to run. Thanks very much for your help!

Reprex:

library(easystats)
library(patchwork)

m <- lm(mpg ~ factor(cyl) + disp + hp, data = mtcars)
pp <- check_model(m)

print(plot(pp) + plot_annotation(title = 'mtcars model'))

Error:

Error in p + plot_annotation(title = "mtcars model") : 
  non-numeric argument to binary operator

Other potentially useful info:

> class(pp)
[1] "check_model"     "see_check_model"
> class(plot(pp))
[1] "list"

Session info:

R version 4.3.3 (2024-02-29 ucrt)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 11 x64 (build 22631)

Matrix products: default


locale:
[1] LC_COLLATE=English_United States.utf8  LC_CTYPE=English_United States.utf8    LC_MONETARY=English_United States.utf8
[4] LC_NUMERIC=C                           LC_TIME=English_United States.utf8    

time zone: America/New_York
tzcode source: internal

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

other attached packages:
 [1] patchwork_1.2.0    see_0.8.3          report_0.5.8       parameters_0.21.6  performance_0.11.0 modelbased_0.8.7   insight_0.19.10   
 [8] effectsize_0.8.7   datawizard_0.10.0  correlation_0.8.4  bayestestR_0.13.2  easystats_0.7.1   

loaded via a namespace (and not attached):
 [1] gtable_0.3.4            tensorA_0.36.2.1        xfun_0.43               ggplot2_3.5.0           twosamples_2.0.1       
 [6] caTools_1.18.2          processx_3.8.4          lattice_0.22-5          vctrs_0.6.5             tools_4.3.3            
[11] ps_1.7.6                bitops_1.0-7            generics_0.1.3          parallel_4.3.3          sandwich_3.1-0         
[16] pbmcapply_1.5.1         tibble_3.2.1            fansi_1.0.6             DEoptimR_1.1-3          cmdstanr_0.7.1         
[21] pkgconfig_2.0.3         Matrix_1.6-5            checkmate_2.3.1         distributional_0.4.0    lifecycle_1.0.4        
[26] farver_2.1.1            compiler_4.3.3          munsell_0.5.1           codetools_0.2-19        pracma_2.4.4           
[31] pillar_1.9.0            MASS_7.3-60.0.1         iterators_1.0.14        abind_1.4-5             multcomp_1.4-25        
[36] foreach_1.5.2           nlme_3.1-164            robustbase_0.99-2       posterior_1.5.0         tidyselect_1.2.1       
[41] mvtnorm_1.2-4           dplyr_1.1.4             labeling_0.4.3          splines_4.3.3           grid_4.3.3             
[46] colorspace_2.1-0        cli_3.6.2               qqconf_1.3.2            magrittr_2.0.3          survival_3.5-8         
[51] utf8_1.2.4              TH.data_1.1-2           withr_3.0.0             scales_1.3.0            backports_1.4.1        
[56] opdisDownsampling_1.0.1 estimability_1.5        emmeans_1.10.1          zoo_1.8-12              coda_0.19-4.1          
[61] qqplotr_0.0.6           knitr_1.46              doParallel_1.0.17       mgcv_1.9-1              rlang_1.1.3            
[66] Rcpp_1.0.12             glue_1.7.0              rstudioapi_0.16.0       R6_2.5.1               
@strengejacke
Copy link
Member

plot() returns a list of ggplot-objects, not an object where you can add layers from patchwork. However, is you use see::plots() on a list of ggplot-objects, that will return a patchwork-object:

library(easystats)
library(patchwork)

m <- lm(mpg ~ factor(cyl) + disp + hp, data = mtcars)
pp <- check_model(m)

x <- plot(pp)
plots(x, n_columns = 2) + plot_annotation(title = 'mtcars model')

Created on 2024-04-17 with reprex v2.1.0

@bwiernik
Copy link
Contributor

@strengejacke i had thought plot() returned the patchwork object. Did we change that at some point? I don't seem much value in retuning a list vs the final thing that is shown by default--should we change it?

@strengejacke
Copy link
Member

@qdread
Copy link
Author

qdread commented Apr 18, 2024

Yes I am fairly sure that plot() returned the patchwork object at some point, and now returns a list.

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

Successfully merging a pull request may close this issue.

3 participants