YuLab-SMU / enrichplot

Visualization of Functional Enrichment Result
https://yulab-smu.top/biomedical-knowledge-mining-book/
234 stars 65 forks source link

New Emapplot Error when plotting #300

Open mj-kamal opened 2 days ago

mj-kamal commented 2 days ago

Hello,

I've gotten a new error that I didn't get with a previous version of R & enrichplot

My code: DE_go_BP <- enrichGO(gene = allDE_target_entr, OrgDb = org.Mm.eg.db, keyType = "ENTREZID", ont = "BP") DE_go_BP_PT <- pairwise_termsim(DE_go_BP) emapplot(DE_go_BP_PT, showCategory = 50, layout = "nicely", group )

Got this error: Error in storage.mode(mat) <- "integer" : 'list' object cannot be coerced to type 'integer'

R version 4.4.2 (2024-10-31) clusterProfiler V 4.14.3 enrichplot V1.26.2

mj-kamal commented 2 days ago

Solved the issue, problem was the layout argument, this has been updated to use igraph layouts. Leaving this up in case anyone else has the same problem.

mj-kamal commented 1 day ago

emapplot won't display legend for adjusted p values.

Code:

DE_go_BP <- enrichGO(gene = allDE_target_entr, OrgDb = org.Mm.eg.db, keyType = "ENTREZID", ont = "BP") DE_go_BP_PT <- pairwise_termsim(DE_go_BP) 
emapplot(DE_go_BP_PT, 
         group = TRUE,
         showCategory = 50,
         size_category = 0.5,
         layout = igraph::layout_with_kk, 
         node_label = "none", 
         color = "p.adjust")

I get the following error:

Warning messages:
1: `guide_colourbar()` cannot be used for colour_ggnewscale_1.
ℹ Use one of colour, color, or fill instead. 
2: `guide_colourbar()` needs continuous scales. 
guidohooiveld commented 1 day ago

FWIW: the warning AND disappearance of the color legend for (adjusted) pvalues are caused because of the argument group=TRUE. If it is set to group=FALSE (which is default), there is no warning and the color legend is plotted.

@GuangchuangYu : could you please have a look at this?

Reproducible example:

> library(clusterProfiler)
> library(org.Hs.eg.db)
> library(enrichplot)
> library(ggplot2)
> 
> ## load and prepare example data / results
> data(geneList, package="DOSE")
> 
> up <- names(geneList)[abs(geneList) > 2]
> 
> ## run ORA using GOBP categories
> res.up <- enrichGO(gene         = up,
+                   OrgDb         = org.Hs.eg.db,
+                   ont           = "BP",
+                   pAdjustMethod = "BH",
+                   pvalueCutoff  = 0.01,
+                   qvalueCutoff  = 0.05,
+                   readable      = TRUE)
> 
> res.up <- pairwise_termsim(res.up)
> head(res.up)
                   ID                          Description GeneRatio   BgRatio
GO:0098813 GO:0098813       nuclear chromosome segregation    34/196 324/18986
GO:0000819 GO:0000819         sister chromatid segregation    30/196 235/18986
GO:0140014 GO:0140014             mitotic nuclear division    32/196 282/18986
GO:0000070 GO:0000070 mitotic sister chromatid segregation    28/196 194/18986
GO:0007059 GO:0007059               chromosome segregation    37/196 429/18986
GO:0000280 GO:0000280                     nuclear division    37/196 451/18986
           RichFactor FoldEnrichment   zScore       pvalue     p.adjust
GO:0098813 0.10493827      10.165092 16.99418 1.637859e-24 2.862638e-21
GO:0000819 0.12765957      12.366044 17.90610 3.280746e-24 2.862638e-21
GO:0140014 0.11347518      10.992039 17.26559 3.668997e-24 2.862638e-21
GO:0000070 0.14432990      13.980854 18.56041 3.796601e-24 2.862638e-21
GO:0007059 0.08624709       8.354526 15.73618 1.283918e-23 7.744593e-21
GO:0000280 0.08203991       7.946989 15.24960 7.364511e-23 3.701894e-20
                 qvalue
GO:0098813 2.487773e-21
GO:0000819 2.487773e-21
GO:0140014 2.487773e-21
GO:0000070 2.487773e-21
GO:0007059 6.730433e-21
GO:0000280 3.217129e-20
                                                                                                                                                                                                                                 geneID
GO:0098813                     CDCA8/CDC20/KIF23/CENPE/MYBL2/CCNB2/NDC80/TOP2A/NCAPH/ASPM/DLGAP5/UBE2C/SKA1/NUSAP1/TPX2/TACC3/NEK2/CDK1/MAD2L1/KIF18A/CDT1/BIRC5/KIF11/TTK/NCAPG/AURKB/TRIP13/PRC1/KIFC1/KIF18B/AURKA/CCNB1/KIF4A/PTTG1
GO:0000819                                            CDCA8/CDC20/KIF23/CENPE/MYBL2/NDC80/TOP2A/NCAPH/DLGAP5/UBE2C/SKA1/NUSAP1/TPX2/TACC3/NEK2/CDK1/MAD2L1/KIF18A/CDT1/BIRC5/KIF11/TTK/NCAPG/AURKB/TRIP13/PRC1/KIFC1/KIF18B/CCNB1/KIF4A
GO:0140014                                 CDCA8/CDC20/KIF23/CENPE/MYBL2/NDC80/NCAPH/DLGAP5/UBE2C/SKA1/NUSAP1/TPX2/NEK2/UBE2S/CDK1/MAD2L1/KIF18A/CDT1/BIRC5/KIF11/TTK/NCAPG/AURKB/CHEK1/TRIP13/PRC1/KIFC1/KIF18B/AURKA/CCNB1/KIF4A/BMP4
GO:0000070                                                        CDCA8/CDC20/KIF23/CENPE/MYBL2/NDC80/NCAPH/DLGAP5/UBE2C/SKA1/NUSAP1/TPX2/NEK2/CDK1/MAD2L1/KIF18A/CDT1/BIRC5/KIF11/TTK/NCAPG/AURKB/TRIP13/PRC1/KIFC1/KIF18B/CCNB1/KIF4A
GO:0007059   CDCA8/CDC20/KIF23/CENPE/MYBL2/CCNB2/NDC80/TOP2A/NCAPH/ASPM/DLGAP5/UBE2C/HJURP/SKA1/NUSAP1/TPX2/TACC3/NEK2/CENPM/CENPN/CDK1/MAD2L1/KIF18A/CDT1/BIRC5/KIF11/TTK/NCAPG/AURKB/TRIP13/PRC1/KIFC1/KIF18B/AURKA/CCNB1/KIF4A/PTTG1
GO:0000280 CDCA8/CDC20/KIF23/CENPE/MYBL2/CCNB2/NDC80/TOP2A/NCAPH/ASPM/DLGAP5/UBE2C/SKA1/NUSAP1/TPX2/NEK2/RAD51AP1/UBE2S/CDK1/MAD2L1/KIF18A/CDT1/BIRC5/KIF11/TTK/NCAPG/AURKB/CHEK1/TRIP13/PRC1/KIFC1/KIF18B/AURKA/CCNB1/KIF4A/PTTG1/BMP4
           Count
GO:0098813    34
GO:0000819    30
GO:0140014    32
GO:0000070    28
GO:0007059    37
GO:0000280    37
> 
> ## make emapplot
> ## using default settings,
> ## NO warning + color legend p.adjust is plotted
> emapplot(res.up)
> 

image

> ## WARNING and NO color legend; when group = TRUE
> emapplot(res.up, group = TRUE)
Warning messages:
1: `guide_colourbar()` cannot be used for colour_ggnewscale_1.
ℹ Use one of colour, color, or fill instead. 
2: `guide_colourbar()` needs continuous scales. 
> 

image


> sessionInfo()
R version 4.4.2 (2024-10-31 ucrt)
Platform: x86_64-w64-mingw32/x64
Running under: Windows 10 x64 (build 19042)

Matrix products: default

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

time zone: Europe/Amsterdam
tzcode source: internal

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

other attached packages:
 [1] ggplot2_3.5.1          igraph_2.1.1           enrichplot_1.27.1.004 
 [4] org.Hs.eg.db_3.20.0    AnnotationDbi_1.68.0   IRanges_2.40.0        
 [7] S4Vectors_0.44.0       Biobase_2.66.0         BiocGenerics_0.52.0   
[10] clusterProfiler_4.14.3

loaded via a namespace (and not attached):
  [1] DBI_1.2.3               gson_0.1.0              remotes_2.5.0          
  [4] rlang_1.1.4             magrittr_2.0.3          DOSE_4.0.0             
  [7] compiler_4.4.2          RSQLite_2.3.7           systemfonts_1.1.0      
 [10] png_0.1-8               callr_3.7.6             vctrs_0.6.5            
 [13] reshape2_1.4.4          stringr_1.5.1           pkgconfig_2.0.3        
 [16] crayon_1.5.3            fastmap_1.2.0           XVector_0.46.0         
 [19] labeling_0.4.3          utf8_1.2.4              UCSC.utils_1.2.0       
 [22] ps_1.8.1                purrr_1.0.2             bit_4.5.0              
 [25] zlibbioc_1.52.0         cachem_1.1.0            aplot_0.2.3            
 [28] GenomeInfoDb_1.42.0     jsonlite_1.8.9          blob_1.2.4             
 [31] tweenr_2.0.3            BiocParallel_1.40.0     parallel_4.4.2         
 [34] R6_2.5.1                stringi_1.8.4           RColorBrewer_1.1-3     
 [37] GOSemSim_2.32.0         Rcpp_1.0.13-1           snow_0.4-4             
 [40] ggtangle_0.0.4.004      R.utils_2.12.3          Matrix_1.7-1           
 [43] splines_4.4.2           tidyselect_1.2.1        qvalue_2.38.0          
 [46] codetools_0.2-20        curl_6.0.1              processx_3.8.4         
 [49] pkgbuild_1.4.5          lattice_0.22-6          tibble_3.2.1           
 [52] plyr_1.8.9              treeio_1.30.0           withr_3.0.2            
 [55] KEGGREST_1.46.0         gridGraphics_0.5-1      desc_1.4.3             
 [58] polyclip_1.10-7         Biostrings_2.74.0       pillar_1.9.0           
 [61] BiocManager_1.30.25     ggtree_3.14.0           ggfun_0.1.7            
 [64] generics_0.1.3          munsell_0.5.1           scales_1.3.0           
 [67] tidytree_0.4.6          glue_1.8.0              lazyeval_0.2.2         
 [70] tools_4.4.2             ggnewscale_0.5.0        data.table_1.16.2      
 [73] fgsea_1.32.0            fs_1.6.5                fastmatch_1.1-4        
 [76] cowplot_1.1.3           grid_4.4.2              tidyr_1.3.1            
 [79] ape_5.8                 colorspace_2.1-1        nlme_3.1-166           
 [82] GenomeInfoDbData_1.2.13 patchwork_1.3.0         ggforce_0.4.2          
 [85] cli_3.6.3               fansi_1.0.6             dplyr_1.1.4            
 [88] gtable_0.3.6            R.methodsS3_1.8.2       yulab.utils_0.1.8      
 [91] digest_0.6.37           ggrepel_0.9.6           ggplotify_0.1.2        
 [94] farver_2.1.2            memoise_2.0.1           R.oo_1.27.0            
 [97] lifecycle_1.0.4         httr_1.4.7              GO.db_3.20.0           
[100] bit64_4.5.2             MASS_7.3-61            
>
mj-kamal commented 1 day ago

Yes, you are correct. It must be a problem with one of the recent enrichplot versions. The last time I ran it, it was with V1.20.3 and group = TRUE didn't give this error and I was still able to cluster the nodes and colour them with p.adjust/display the legend.

It's also worth noting that in the current version of enrichplot (V1.26.2), using the group = TRUE argument will still colour the nodes according to some metric, even if the color = "p.adjust" argument is missing from the function. Interestingly, the plots generated look identifical whether or not you include color = "p.adjust"

Hopefully there is an easy fix for this because I need to cluster the terms and plot the p.adjust as colors. It would also be good to have a way to set color = "black" or something in case you didn't want to plot the p-value or you wanted the size to correspond to the p-values and the colours to correspond to the size.