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

SpatialDimPlot and DimPlot colors do not match #4102

Closed
JamesJDollar opened this issue Feb 18, 2021 · 5 comments
Closed

SpatialDimPlot and DimPlot colors do not match #4102

JamesJDollar opened this issue Feb 18, 2021 · 5 comments
Labels
more-information-needed We need more information before this can be addressed

Comments

@JamesJDollar
Copy link

I am trying to visualize the clusters on Dimplot and on SpatialDimPlot, but the colors will not match.
SpatialDimPlot reports the warning: 'Scale for 'fill' is already present. Adding another scale for 'fill',
which will replace the existing scale.' Specifying 'cols =' does not fix the issue either.

Thank you for your help!

@JamesJDollar
Copy link
Author

Current work around is providing scale_color_brewer(palette = ) to DimPlot and scale_fill_brewer(palette = ) to SpatialPlot, but I am wondering if there is a better way.

@mojaveazure mojaveazure added the more-information-needed We need more information before this can be addressed label Feb 19, 2021
@mojaveazure
Copy link
Member

I'm not able to reproduce this. Can you provide the code you used along with a dataset, a subset of a dataset, or a dataset in SeuratData that reproduces this error along with the output of sessionInfo()?

@no-response
Copy link

no-response bot commented Mar 5, 2021

This issue has been automatically closed because there has been no response to our request for more information from the original author. With only the information that is currently in the issue, we don't have enough information to take action. Please reach out if you have or find the answers we need so that we can investigate further.

@no-response no-response bot closed this as completed Mar 5, 2021
@SebastienNin
Copy link

Hi,
I'm working on 10X visium data and I got the same problem as @JamesJDollar.

Here is my code

library(SeuratData)
library(Seurat)

InstallData("stxBrain.SeuratData")

brain <- LoadData("stxBrain.SeuratData", type = "anterior1")

plot1 <- VlnPlot(brain, features = "nCount_Spatial", pt.size = 0.1) + NoLegend()
plot2 <- SpatialFeaturePlot(brain, features = "nCount_Spatial") + theme(legend.position = "right")
wrap_plots(plot1, plot2)

brain <- SCTransform(brain, assay = "Spatial", verbose = FALSE)

brain <- RunPCA(brain, assay = "SCT", verbose = FALSE)
brain <- FindNeighbors(brain, reduction = "pca", dims = 1:30)
brain <- FindClusters(brain, verbose = FALSE)
brain <- RunUMAP(brain, reduction = "pca", dims = 1:30)

p1 <- DimPlot(brain, reduction = "umap", label = TRUE)
p2 <- SpatialDimPlot(brain, label = TRUE, label.size = 3)
p1 + p2

And I got this picture for the DimPlot + SpatialDimPlot

wrong_color_spatialdimplot

As you can see, the colors between the DimPlot and the SpatialDimPlot are different.
Can you help me to figure out what is the problem please?

Have a nice day,
Sebastien

Here is my sessionInfo()

> sessionInfo()
R version 3.6.1 (2019-07-05)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 16.04.7 LTS

Matrix products: default
BLAS:   /usr/lib/libblas/libblas.so.3.6.0
LAPACK: /usr/lib/lapack/liblapack.so.3.6.0

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

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

other attached packages:
 [1] stxBrain.SeuratData_0.1.1 SeuratData_0.2.1          patchwork_1.1.1           Seurat_3.2.2             
 [5] Rcpp_1.0.7                GGally_2.1.2              DT_0.18                   cowplot_1.1.1            
 [9] plotly_4.9.4.1            factoextra_1.0.7          reshape2_1.4.4            VennDiagram_1.6.20       
[13] futile.logger_1.4.3       ggplot2_3.3.5             pheatmap_1.0.12           htmltools_0.5.1.1        
[17] yaml_2.2.1                data.table_1.14.0        

loaded via a namespace (and not attached):
  [1] backports_1.2.1      plyr_1.8.6           igraph_1.2.6         lazyeval_0.2.2       splines_3.6.1        listenv_0.8.0       
  [7] usethis_2.0.1        digest_0.6.27        rsconnect_0.8.18     fansi_0.5.0          magrittr_2.0.1       memoise_2.0.0       
 [13] tensor_1.5           cluster_2.1.0        ROCR_1.0-11          remotes_2.4.0        globals_0.14.0       matrixStats_0.59.0  
 [19] R.utils_2.10.1       prettyunits_1.1.1    colorspace_2.0-2     rappdirs_0.3.3       ggrepel_0.9.1        xfun_0.24           
 [25] dplyr_1.0.7          callr_3.7.0          crayon_1.4.1         jsonlite_1.7.2       spatstat_1.64-1      spatstat.data_2.1-0 
 [31] survival_3.2-11      zoo_1.8-9            glue_1.4.2           polyclip_1.10-0      gtable_0.3.0         leiden_0.3.8        
 [37] pkgbuild_1.2.0       R.cache_0.15.0       future.apply_1.7.0   abind_1.4-5          scales_1.1.1         futile.options_1.0.1
 [43] DBI_1.1.1            miniUI_0.1.1.1       viridisLite_0.4.0    xtable_1.8-4         reticulate_1.20      bit_4.0.4           
 [49] rsvd_1.0.3           htmlwidgets_1.5.3    httr_1.4.2           RColorBrewer_1.1-2   ellipsis_0.3.2       ica_1.0-2           
 [55] pkgconfig_2.0.3      reshape_0.8.8        R.methodsS3_1.8.1    farver_2.1.0         sass_0.4.0           uwot_0.1.10         
 [61] deldir_0.2-10        utf8_1.2.1           tidyselect_1.1.1     labeling_0.4.2       rlang_0.4.11         later_1.2.0         
 [67] cachem_1.0.5         munsell_0.5.0        tools_3.6.1          cli_3.0.1            generics_0.1.0       devtools_2.4.2      
 [73] ggridges_0.5.3       evaluate_0.14        stringr_1.4.0        fastmap_1.1.0        goftest_1.2-2        rematch2_2.1.2      
 [79] processx_3.5.2       knitr_1.33           bit64_4.0.5          fs_1.5.0             fitdistrplus_1.1-5   purrr_0.3.4         
 [85] RANN_2.6.1           pbapply_1.4-3        future_1.21.0        nlme_3.1-141         mime_0.11            formatR_1.11        
 [91] R.oo_1.24.0          hdf5r_1.3.3          compiler_3.6.1       rstudioapi_0.13      curl_4.3.2           png_0.1-7           
 [97] testthat_3.0.4       spatstat.utils_2.2-0 tibble_3.1.2         bslib_0.2.5.1        stringi_1.7.3        ps_1.6.0            
[103] highr_0.9            desc_1.3.0           RSpectra_0.16-0      lattice_0.20-44      Matrix_1.3-2         styler_1.5.1        
[109] vctrs_0.3.8          pillar_1.6.1         lifecycle_1.0.0      BiocManager_1.30.16  lmtest_0.9-38        jquerylib_0.1.4     
[115] RcppAnnoy_0.0.18     irlba_2.3.3          httpuv_1.6.1         R6_2.5.0             bookdown_0.22        promises_1.2.0.1    
[121] KernSmooth_2.23-15   gridExtra_2.3        parallelly_1.27.0    sessioninfo_1.1.1    codetools_0.2-16     lambda.r_1.2.4      
[127] pkgload_1.2.1        MASS_7.3-54          assertthat_0.2.1     rprojroot_2.0.2      withr_2.4.2          sctransform_0.3.2   
[133] mgcv_1.8-28          parallel_3.6.1       rpart_4.1-15         tidyr_1.1.3          rmarkdown_2.9        Rtsne_0.15          
[139] shiny_1.6.0    ```

@SebastienNin
Copy link

If I do the following:

p1 <- DimPlot(brain, reduction = "umap", label = TRUE)
p2 <- SpatialDimPlot(brain)
p1 + p2

I got the good colors:

good_color_spatialdimplot

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
more-information-needed We need more information before this can be addressed
Projects
None yet
Development

No branches or pull requests

3 participants