enblacar / SCpubr

Generate high quality, publication ready visualizations for single cell transcriptomics data.
https://enblacar.github.io/SCpubr-book/
GNU General Public License v3.0
157 stars 12 forks source link

BUG | do_DimPlot | Multiple legends are visualised when "Group by a variable but split by another" #36

Closed frac2738 closed 1 year ago

frac2738 commented 1 year ago

Bug:

I want to split the umap by sample, while colouring the inside of each umap by the clusters. I managed to do that using the combination of group.by="cluster" and split.by="SampleID", but I get multiple legends; one per split (sample).

uMAP_res1 2_by_SampleID_split

The code I used is:

tmp_plot <- do_DimPlot(exp_tumour, split.by ="SampleID ",  group.by = "integrated_snn_res.1.2" , ncol = 4,
                          label = FALSE,
                          pt.size = 0.8, repel = TRUE, plot.axes = TRUE,
                          legend.position = "bottom", legend.nrow = 3) 
ggsave(tmp_plot, filename = paste0(figDIR,"/uMAP_",outname,"_by_",colonna,"_split.png"),width = 14,height = 18) 

In seurat I usually do:

Idents(exp_tumour) <- "integrated_snn_res.1.2"
DimPlot(exp_tumour, label = TRUE, pt.size = 0.8, split.by = "SampleID", repel = TRUE, ncol = 4) 

DimPlot_legend

SCpubr version: 1.1.2

Session info:


R version 4.3.1 (2023-06-16)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 20.04.6 LTS

Matrix products: default
BLAS:   /usr/lib/x86_64-linux-gnu/libf77blas.so.3.10.3 
LAPACK: /usr/lib/x86_64-linux-gnu/atlas/liblapack.so.3.10.3;  LAPACK version 3.9.0

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

time zone: Europe/Paris
tzcode source: system (glibc)

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

other attached packages:
 [1] SCpubr_1.1.2                scR_0.9                     UCell_2.4.0                 viridis_0.6.4               viridisLite_0.4.2           dplyr_1.1.2                
 [7] pheatmap_1.0.12             scCustomize_1.1.3           plotly_4.10.2               dittoSeq_1.12.0             ggpubr_0.6.0                garnett_0.2.20             
[13] monocle3_1.3.1              SingleCellExperiment_1.22.0 SummarizedExperiment_1.30.2 GenomicRanges_1.52.0        GenomeInfoDb_1.36.1         IRanges_2.34.1             
[19] S4Vectors_0.38.1            MatrixGenerics_1.12.3       matrixStats_1.0.0           Biobase_2.60.0              BiocGenerics_0.46.0         wesanderson_0.3.6          
[25] patchwork_1.1.2             data.table_1.14.8           ggplot2_3.4.2               sctransform_0.3.5           SeuratObject_4.1.3          Seurat_4.3.0.1             

loaded via a namespace (and not attached):
  [1] RcppAnnoy_0.0.21        splines_4.3.1           later_1.3.1             ggplotify_0.1.1         bitops_1.0-7            tibble_3.2.1            polyclip_1.10-4        
  [8] janitor_2.2.0           lifecycle_1.0.3         rstatix_0.7.2           globals_0.16.2          lattice_0.21-8          MASS_7.3-60             backports_1.4.1        
 [15] magrittr_2.0.3          httpuv_1.6.11           sp_2.0-0                spatstat.sparse_3.0-2   reticulate_1.30         cowplot_1.1.1           pbapply_1.7-2          
 [22] minqa_1.2.5             RColorBrewer_1.1-3      lubridate_1.9.2         abind_1.4-5             zlibbioc_1.46.0         Rtsne_0.16              purrr_1.0.1            
 [29] RCurl_1.98-1.12         yulab.utils_0.0.6       circlize_0.4.15         GenomeInfoDbData_1.2.10 ggrepel_0.9.3           irlba_2.3.5.1           listenv_0.9.0          
 [36] spatstat.utils_3.0-3    terra_1.7-39            goftest_1.2-3           spatstat.random_3.1-5   fitdistrplus_1.1-11     parallelly_1.36.0       leiden_0.4.3           
 [43] codetools_0.2-19        DelayedArray_0.26.7     tidyselect_1.2.0        shape_1.4.6             farver_2.1.1            lme4_1.1-34             spatstat.explore_3.2-1 
 [50] jsonlite_1.8.7          BiocNeighbors_1.18.0    ellipsis_0.3.2          progressr_0.13.0        ggridges_0.5.4          survival_3.5-5          systemfonts_1.0.4      
 [57] tools_4.3.1             ragg_1.2.5              ica_1.0-3               Rcpp_1.0.11             glue_1.6.2              gridExtra_2.3           withr_2.5.0            
 [64] fastmap_1.1.1           boot_1.3-28.1           fansi_1.0.4             digest_0.6.33           gridGraphics_0.5-1      timechange_0.2.0        R6_2.5.1               
 [71] mime_0.12               textshaping_0.3.6       ggprism_1.0.4           colorspace_2.1-0        scattermore_1.2         tensor_1.5              spatstat.data_3.0-1    
 [78] utf8_1.2.3              tidyr_1.3.0             generics_0.1.3          httr_1.4.6              htmlwidgets_1.6.2       S4Arrays_1.0.5          uwot_0.1.16            
 [85] pkgconfig_2.0.3         gtable_0.3.3            lmtest_0.9-40           XVector_0.40.0          htmltools_0.5.5         carData_3.0-5           scales_1.2.1           
 [92] png_0.1-8               snakecase_0.11.0        rstudioapi_0.15.0       reshape2_1.4.4          nlme_3.1-162            nloptr_2.0.3            zoo_1.8-12             
 [99] GlobalOptions_0.1.2     stringr_1.5.0           KernSmooth_2.23-22      parallel_4.3.1          miniUI_0.1.1.1          vipor_0.4.5             ggrastr_1.0.2          
[106] pillar_1.9.0            grid_4.3.1              vctrs_0.6.3             RANN_2.6.1              promises_1.2.0.1        car_3.1-2               xtable_1.8-4           
[113] cluster_2.1.4           paletteer_1.5.0         beeswarm_0.4.0          cli_3.6.1               compiler_4.3.1          rlang_1.1.1             crayon_1.5.2           
[120] future.apply_1.11.0     ggsignif_0.6.4          labeling_0.4.2          rematch2_2.1.2          plyr_1.8.8              forcats_1.0.0           ggbeeswarm_0.7.2       
[127] stringi_1.7.12          BiocParallel_1.34.2     deldir_1.0-9            assertthat_0.2.1        munsell_0.5.0           lazyeval_0.2.2          spatstat.geom_3.2-4    
[134] Matrix_1.6-0            future_1.33.0           shiny_1.7.4.1           ROCR_1.0-11             igraph_1.5.0.1          broom_1.0.5  ```
enblacar commented 1 year ago

Hi @frac2738,

Thanks for using my package!

That is indeed a bug, thanks for pointing it out! There is not much one can do about it in v1.1.2 of SCpubr. I have just committed the changes fixing it, and will roll out in the 2.0.0 update soon.

Best, Enrique

frac2738 commented 1 year ago

Thanks you for fixing it. I look forward the 2.0.0 update.

enblacar commented 1 year ago

Hi @frac2738,

The update is already on CRAN!

Best, Enrique