drieslab / Giotto

Spatial omics analysis toolbox
https://drieslab.github.io/Giotto_website/
Other
258 stars 98 forks source link

Issue when plotting multiple objects where not all cell types are present #1021

Closed jweis3 closed 1 month ago

jweis3 commented 1 month ago

Describe the Error

Using spatPlot2D with both a custom color vector as well as internal default Giotto provided colors results in plots where the same celltype across different samples can be colored differently (see example plots below). The function itself works, but isn't keeping one color for a single cell type across each sample.

Screenshots

Screenshot 2024-09-03 at 11 32 22 AM

System Information

Please replace the following according to your machine:

R version 4.4.0 (2024-04-24) Platform: x86_64-pc-linux-gnu Running under: AlmaLinux 8.10 (Cerulean Leopard)

Giotto Version 4.1.0

Matrix products: default BLAS/LAPACK: FlexiBLAS NETLIB; LAPACK version 3.11.0

locale: [1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C 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 LC_PAPER=en_US.UTF-8 LC_NAME=C
[9] LC_ADDRESS=C LC_TELEPHONE=C LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C

time zone: America/New_York tzcode source: system (glibc)

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

other attached packages: [1] reshape2_1.4.4 tidyr_1.3.1 ggpubr_0.6.0 clustree_0.5.1 ggraph_2.2.1 harmony_1.2.1
[7] Rcpp_1.0.12 ggplot2_3.5.1 Giotto_4.1.0 GiottoClass_0.3.4

loaded via a namespace (and not attached): [1] RcppAnnoy_0.0.22 later_1.3.2 tibble_3.2.1
[4] R.oo_1.26.0 polyclip_1.10-6 lifecycle_1.0.4
[7] rstatix_0.7.2 globals_0.16.3 lattice_0.22-6
[10] MASS_7.3-60.2 backports_1.5.0 magrittr_2.0.3
[13] plotly_4.10.4 rmarkdown_2.27 yaml_2.3.8
[16] remotes_2.5.0 httpuv_1.6.15 sp_2.1-4
[19] sessioninfo_1.2.2 pkgbuild_1.4.4 reticulate_1.37.0
[22] cowplot_1.1.3 RColorBrewer_1.1-3 abind_1.4-5
[25] pkgload_1.3.4 zlibbioc_1.50.0 GenomicRanges_1.56.0
[28] purrr_1.0.2 R.utils_2.12.3 BiocGenerics_0.50.0
[31] tweenr_2.0.3 rappdirs_0.3.3 GenomeInfoDbData_1.2.12
[34] IRanges_2.38.0 S4Vectors_0.42.0 ggrepel_0.9.5
[37] irlba_2.3.5.1 listenv_0.9.1 terra_1.7-78
[40] parallelly_1.37.1 colorRamp2_0.1.0 codetools_0.2-20
[43] DelayedArray_0.30.1 ggforce_0.4.2 tidyselect_1.2.1
[46] UCSC.utils_1.0.0 farver_2.1.2 ScaledMatrix_1.12.0
[49] viridis_0.6.5 matrixStats_1.3.0 stats4_4.4.0
[52] jsonlite_1.8.8 ellipsis_0.3.2 tidygraph_1.3.1
[55] progressr_0.14.0 systemfonts_1.0.6 dbscan_1.1-12
[58] tools_4.4.0 ragg_1.3.0 glue_1.7.0
[61] gridExtra_2.3 SparseArray_1.4.8 xfun_0.44
[64] MatrixGenerics_1.16.0 usethis_2.2.3 GenomeInfoDb_1.40.0
[67] dplyr_1.1.4 withr_3.0.0 fastmap_1.2.0
[70] fansi_1.0.6 digest_0.6.35 rsvd_1.0.5
[73] R6_2.5.1 mime_0.12 textshaping_0.3.7
[76] colorspace_2.1-0 scattermore_1.2 gtools_3.9.5
[79] R.methodsS3_1.8.2 RhpcBLASctl_0.23-42 utf8_1.2.4
[82] generics_0.1.3 data.table_1.15.4 graphlayouts_1.1.1
[85] httr_1.4.7 htmlwidgets_1.6.4 S4Arrays_1.4.1
[88] uwot_0.2.2 pkgconfig_2.0.3 gtable_0.3.5
[91] GiottoVisuals_0.2.4 SingleCellExperiment_1.26.0 XVector_0.44.0
[94] htmltools_0.5.8.1 carData_3.0-5 profvis_0.3.8
[97] scales_1.3.0 Biobase_2.64.0 GiottoUtils_0.1.11
[100] png_0.1-8 SpatialExperiment_1.14.0 knitr_1.47
[103] rstudioapi_0.16.0 rjson_0.2.21 checkmate_2.3.1
[106] cachem_1.1.0 stringr_1.5.1 parallel_4.4.0
[109] miniUI_0.1.1.1 pillar_1.9.0 grid_4.4.0
[112] vctrs_0.6.5 urlchecker_1.0.1 promises_1.3.0
[115] BiocSingular_1.20.0 car_3.1-2 beachmat_2.20.0
[118] xtable_1.8-4 evaluate_0.23 magick_2.8.3
[121] cli_3.6.2 compiler_4.4.0 rlang_1.1.3
[124] crayon_1.5.2 future.apply_1.11.2 ggsignif_0.6.4
[127] labeling_0.4.3 plyr_1.8.9 fs_1.6.4
[130] stringi_1.8.4 viridisLite_0.4.2 deldir_2.0-4
[133] BiocParallel_1.38.0 munsell_0.5.1 lazyeval_0.2.2
[136] devtools_2.4.5 Matrix_1.7-0 future_1.33.2
[139] shiny_1.8.1.1 SummarizedExperiment_1.34.0 igraph_2.0.3
[142] broom_1.0.5 memoise_2.0.1
Additional context

Add any other context about the problem here.

RubD commented 1 month ago

@jweis3 can you copy the code/commands that you used to generate these plots?

jweis3 commented 1 month ago

harmony_colors = c("darkgreen", "firebrick", "dodgerblue", "magenta", "gold3","lightblue","navy", "royalblue") spatPlot2D(filt_merged_TMA, cell_color = "harmony_celltypes", cell_color_code = harmony_colors, title = toupper(TMA_name))

To me it appears as if the plotting function starts with the first color and assigns each cell type sequentially, which becomes problematic when not all cell types are present within a specific TMA. This also happens if I don't supply a custom color vector.

RubD commented 1 month ago

If you create a 'named' vector then it should work. Something like this but with your own cell types and colors: harmony_colors = c("darkgreen", "firebrick") names(harmony_colors) = c("celltypeA", "celltypeB")

And then provide this named vector to the cell_color_code parameter. So each cell type will have the color you specified.

jweis3 commented 1 month ago

This looks like it worked, thanks!