YuLab-SMU / aplot

Decorate a plot with associated information
https://yulab-smu.top/aplot
92 stars 14 forks source link

About plot_list #20

Closed lbwfff closed 1 year ago

lbwfff commented 1 year ago

Hi,

I want to use plot_list to combine pictures, but I found that plot_list will report an error, in fact I can't even run the code of the example, I don't know how to solve it. Below is my code:

library(dplyr)
library(ggplot2)
library(ggstance)
library(ggtree)
library(patchwork)
library(aplot)
no_legend=theme(legend.position='none')

d <- group_by(mtcars, cyl) %>% summarize(mean=mean(disp), sd=sd(disp)) 
d2 <- dplyr::filter(mtcars, cyl != 8) %>% rename(var = cyl)

p1 <- ggplot(d, aes(x=cyl, y=mean)) + 
  geom_col(aes(fill=factor(cyl)), width=1) + 
  no_legend
p2 <- ggplot(d2, aes(var, disp)) + 
  geom_jitter(aes(color=factor(var)), width=.5) + 
  no_legend

p3 <- ggplot(filter(d, cyl != 4), aes(mean, cyl)) + 
  geom_colh(aes(fill=factor(cyl)), width=.6) + 
  coord_flip() + no_legend

pp <- list(p1, p2, p3)
plot_list(pp, ncol=1)

The following is the error:

> plot_list(pp, ncol=1)
Error in UseMethod("as.grob") : 
  no applicable method for 'as.grob' applied to an object of class "list"

The following is the information of the system:

> sessionInfo()
R version 4.1.2 (2021-11-01)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 20.04.3 LTS

Matrix products: default
BLAS:   /usr/local/lib/R/lib/libRblas.so
LAPACK: /usr/local/lib/R/lib/libRlapack.so

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

attached base packages:
 [1] splines   grid      parallel  stats4    stats     graphics  grDevices
 [8] utils     datasets  methods   base     

other attached packages:
 [1] ggstance_0.3.5.9000                     
 [2] ggtree_3.2.1                            
 [3] aplot_0.1.1                             
 [4] vroom_1.5.7                             
 [5] ggmsa_1.0.0                             
 [6] msaR_0.6.0                              
 [7] ggseqlogo_0.1                           
 [8] patchwork_1.1.1                         
 [9] cowplot_1.1.1                           
[10] tastypie_0.1.0                          
[11] OrgMassSpecR_0.5-3                      
[12] exomePeak2_1.6.1                        
[13] cqn_1.40.0                              
[14] quantreg_5.86                           
[15] SparseM_1.81                            
[16] preprocessCore_1.56.0                   
[17] nor1mix_1.3-0                           
[18] mclust_5.4.8                            
[19] SummarizedExperiment_1.24.0             
[20] MatrixGenerics_1.6.0                    
[21] matrixStats_0.61.0                      
[22] rtracklayer_1.54.0                      
[23] ggsci_2.9                               
[24] tackPlotR_0.0.1                         
[25] MAnorm2_1.2.0                           
[26] cliProfiler_1.0.0                       
[27] circlize_0.4.15                         
[28] ComplexHeatmap_2.10.0                   
[29] TxDb.Hsapiens.UCSC.hg38.knownGene_3.14.0
[30] GenomicFeatures_1.46.1                  
[31] factoextra_1.0.7                        
[32] FactoMineR_2.4                          
[33] ggvenn_0.1.9                            
[34] dplyr_1.0.7                             
[35] customProDB_1.34.0                      
[36] biomaRt_2.50.0                          
[37] AnnotationDbi_1.56.1                    
[38] Biobase_2.54.0                          
[39] impute_1.68.0                           
[40] magrittr_2.0.1                          
[41] antigen.garnish_2.3.0                   
[42] ftrCOOL_2.0.0                           
[43] pROC_1.18.0                             
[44] doParallel_1.0.16                       
[45] iterators_1.0.13                        
[46] foreach_1.5.1                           
[47] caret_6.0-90                            
[48] lattice_0.20-45                         
[49] iq_1.9.3                                
[50] data.table_1.14.2                       
[51] MSstats_4.2.0                           
[52] umap_0.2.7.0                            
[53] limma_3.50.0                            
[54] plotly_4.10.0                           
[55] ggplot2_3.3.5                           
[56] ChIPpeakAnno_3.28.0                     
[57] MetBrewer_0.2.0                         
[58] Cairo_1.5-12.2                          
[59] MSstatsConvert_1.4.1                    
[60] GenomicRanges_1.46.0                    
[61] Biostrings_2.62.0                       
[62] GenomeInfoDb_1.30.0                     
[63] XVector_0.34.0                          
[64] IRanges_2.28.0                          
[65] S4Vectors_0.32.1                        
[66] BiocGenerics_0.40.0                     

loaded via a namespace (and not attached):
  [1] apeglm_1.16.0            ps_1.6.0                 class_7.3-19            
  [4] Rsamtools_2.10.0         rprojroot_2.0.2          crayon_1.4.2            
  [7] rbibutils_2.2.7          MASS_7.3-54              nlme_3.1-153            
 [10] backports_1.3.0          rlang_0.4.12             callr_3.7.0             
 [13] extrafontdb_1.0          nloptr_1.2.2.3           filelock_1.0.2          
 [16] extrafont_0.17           BiocParallel_1.28.0      rjson_0.2.20            
 [19] bit64_4.0.5              glue_1.4.2               processx_3.5.2          
 [22] log4r_0.4.2              regioneR_1.26.0          tidyselect_1.1.1        
 [25] usethis_2.1.3            XML_3.99-0.8             tidyr_1.1.4             
 [28] zoo_1.8-9                proj4_1.0-10.1           GenomicAlignments_1.30.0
 [31] xtable_1.8-4             MatrixModels_0.5-0       Rdpack_2.1.3            
 [34] cli_3.1.0                zlibbioc_1.40.0          rstudioapi_0.13         
 [37] rpart_4.1-15             packcircles_0.3.4        ensembldb_2.18.1        
 [40] lambda.r_1.2.4           treeio_1.18.1            maps_3.4.0              
 [43] askpass_1.1              clue_0.3-60              pkgbuild_1.2.0          
 [46] multtest_2.50.0          cluster_2.1.2            caTools_1.18.2          
 [49] R4RNA_1.22.0             KEGGREST_1.34.0          tibble_3.1.6            
 [52] ggrepel_0.9.1            ape_5.5                  listenv_0.8.0           
 [55] png_0.1-7                permute_0.9-7            future_1.23.0           
 [58] ipred_0.9-12             withr_2.4.2              ggforce_0.3.3           
 [61] bitops_1.0-7             RBGL_1.70.0              plyr_1.8.6              
 [64] AnnotationFilter_1.18.0  coda_0.19-4              pillar_1.6.4            
 [67] gplots_3.1.1             GlobalOptions_0.1.2      cachem_1.0.6            
 [70] fs_1.5.0                 kernlab_0.9-29           scatterplot3d_0.3-41    
 [73] GetoptLong_1.0.5         vctrs_0.3.8              ellipsis_0.3.2          
 [76] generics_0.1.1           devtools_2.4.2           lava_1.6.10             
 [79] tools_4.1.2              tweenr_1.0.2             munsell_0.5.0           
 [82] DelayedArray_0.20.0      pkgload_1.2.3            fastmap_1.1.0           
 [85] compiler_4.1.2           sessioninfo_1.2.1        GenomeInfoDbData_1.2.7  
 [88] prodlim_2019.11.13       InteractionSet_1.22.0    utf8_1.2.2              
 [91] BiocFileCache_2.2.0      recipes_0.1.17           jsonlite_1.7.2          
 [94] scales_1.1.1             graph_1.72.0             tidytree_0.3.6          
 [97] vcfR_1.12.0              genefilter_1.76.0        lazyeval_0.2.2          
[100] reticulate_1.23          checkmate_2.0.0          ash_1.0-15              
[103] statmod_1.4.36           BSgenome_1.62.0          survival_3.2-13         
[106] numDeriv_2016.8-1.1      yaml_2.2.1               ggtranscript_0.99.9     
[109] htmltools_0.5.2          memoise_2.0.0            VariantAnnotation_1.40.0
[112] BiocIO_1.4.0             locfit_1.5-9.4           viridisLite_0.4.0       
[115] digest_0.6.28            assertthat_0.2.1         leaps_3.1               
[118] rappdirs_0.3.3           Rttf2pt1_1.3.9           futile.options_1.0.1    
[121] emdbook_1.3.12           RSQLite_2.2.8            yulab.utils_0.0.4       
[124] future.apply_1.8.1       remotes_2.4.1            VennDiagram_1.7.0       
[127] blob_1.2.2               vegan_2.5-7              futile.logger_1.4.3     
[130] labeling_0.4.2           ProtGenerics_1.26.0      RCurl_1.98-1.5          
[133] hms_1.1.1                colorspace_2.0-2         BiocManager_1.30.16     
[136] shape_1.4.6              nnet_7.3-16              Rcpp_1.0.7              
[139] mvtnorm_1.1-3            ggh4x_0.2.1              fansi_0.5.0             
[142] tzdb_0.2.0               conquer_1.2.1            parallelly_1.28.1       
[145] ModelMetrics_1.2.2.2     R6_2.5.1                 lifecycle_1.0.1         
[148] formatR_1.11             curl_4.3.2               minqa_1.2.4             
[151] testthat_3.1.0           Matrix_1.3-4             desc_1.4.0              
[154] pinfsc50_1.2.0           RColorBrewer_1.1-2       stringr_1.4.0           
[157] gower_0.2.2              htmlwidgets_1.5.4        polyclip_1.10-0         
[160] fmsb_0.7.3               purrr_0.3.4              shadowtext_0.0.9        
[163] gridGraphics_0.5-1       marray_1.72.0            mgcv_1.8-38             
[166] seqmagick_0.1.5          globals_0.14.0           openssl_1.4.5           
[169] flashClust_1.01-2        bdsmatrix_1.3-4          codetools_0.2-18        
[172] lubridate_1.8.0          gtools_3.9.2             prettyunits_1.1.1       
[175] dbplyr_2.1.1             RSpectra_0.16-0          gtable_0.3.0            
[178] DBI_1.1.1                ggfun_0.0.4              httr_1.4.2              
[181] KernSmooth_2.23-20       stringi_1.7.5            progress_1.2.2          
[184] farver_2.1.0             reshape2_1.4.4           uuid_1.0-3              
[187] annotate_1.72.0          timeDate_3043.102        seqinr_4.2-8            
[190] DT_0.19                  xml2_1.3.2               bbmle_1.0.24            
[193] boot_1.3-28              ggalt_0.4.0              lme4_1.1-27.1           
[196] restfulr_0.0.13          ade4_1.7-18              geneplotter_1.72.0      
[199] ggplotify_0.1.0          DESeq2_1.34.0            bit_4.0.4               
[202] pkgconfig_2.0.3          AhoCorasickTrie_0.1.2  

How can I fix this problem?

Thanks, LeeLee

GuangchuangYu commented 1 year ago

either plot_list(p1, p2, p3, ncol=1) or plot_list(gglist=pp, ncol=1) should work.

lbwfff commented 1 year ago

Yes, both work, and the code for online vignette is wrong