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

How do you plot one slice of a multi-slice spatial dataset? #5774

Closed
royfrancis opened this issue Mar 23, 2022 · 4 comments
Closed

How do you plot one slice of a multi-slice spatial dataset? #5774

royfrancis opened this issue Mar 23, 2022 · 4 comments
Labels
bug Something isn't working

Comments

@royfrancis
Copy link
Contributor

library(Seurat)
#> Attaching SeuratObject
library(SeuratData)
#> ── Installed datasets ───────────────────────────────────── SeuratData v0.2.1 ──
#> ✓ stxBrain 0.1.1
#> ────────────────────────────────────── Key ─────────────────────────────────────
#> ✓ Dataset loaded successfully
#> > Dataset built with a newer version of Seurat than installed
#> ❓ Unknown version of Seurat installed

brain1 <- LoadData("stxBrain", type = "anterior1")
brain2 <- LoadData("stxBrain", type = "posterior1")
brain <- merge(brain1, brain2)
#> Warning in CheckDuplicateCellNames(object.list = objects): Some cell names are
#> duplicated across objects provided. Renaming to enforce unique cell names.

SpatialDimPlot(brain)

SpatialDimPlot(subset(brain,subset=region=="anterior"))

SpatialDimPlot(subset(brain,idents="anterior1"))

Created on 2022-03-23 by the reprex package (v2.0.1)

Session info
sessioninfo::session_info()
#> ─ Session info ───────────────────────────────────────────────────────────────
#>  setting  value
#>  version  R version 4.1.0 (2021-05-18)
#>  os       Ubuntu 20.04.4 LTS
#>  system   x86_64, linux-gnu
#>  ui       X11
#>  language en_GB:en
#>  collate  en_GB.UTF-8
#>  ctype    en_GB.UTF-8
#>  tz       Europe/Stockholm
#>  date     2022-03-23
#>  pandoc   2.14.0.3 @ /usr/lib/rstudio/bin/pandoc/ (via rmarkdown)
#> 
#> ─ Packages ───────────────────────────────────────────────────────────────────
#>  package             * version date (UTC) lib source
#>  abind                 1.4-5   2016-07-21 [1] CRAN (R 4.1.0)
#>  assertthat            0.2.1   2019-03-21 [1] CRAN (R 4.1.0)
#>  cli                   3.2.0   2022-02-14 [1] CRAN (R 4.1.0)
#>  cluster               2.1.2   2021-04-17 [1] CRAN (R 4.1.0)
#>  codetools             0.2-18  2020-11-04 [1] CRAN (R 4.1.0)
#>  colorspace            2.0-3   2022-02-21 [1] CRAN (R 4.1.0)
#>  cowplot               1.1.1   2020-12-30 [1] CRAN (R 4.1.0)
#>  crayon                1.5.0   2022-02-14 [1] CRAN (R 4.1.0)
#>  curl                  4.3.2   2021-06-23 [1] CRAN (R 4.1.0)
#>  data.table            1.14.2  2021-09-27 [1] CRAN (R 4.1.0)
#>  DBI                   1.1.2   2021-12-20 [1] CRAN (R 4.1.0)
#>  deldir                1.0-6   2021-10-23 [1] CRAN (R 4.1.0)
#>  digest                0.6.29  2021-12-01 [1] CRAN (R 4.1.0)
#>  dplyr                 1.0.8   2022-02-08 [1] CRAN (R 4.1.0)
#>  ellipsis              0.3.2   2021-04-29 [1] CRAN (R 4.1.0)
#>  evaluate              0.15    2022-02-18 [1] CRAN (R 4.1.0)
#>  fansi                 1.0.2   2022-01-14 [1] CRAN (R 4.1.0)
#>  farver                2.1.0   2021-02-28 [1] CRAN (R 4.1.0)
#>  fastmap               1.1.0   2021-01-25 [1] CRAN (R 4.1.0)
#>  fitdistrplus          1.1-8   2022-03-10 [1] CRAN (R 4.1.0)
#>  fs                    1.5.2   2021-12-08 [1] CRAN (R 4.1.0)
#>  future                1.24.0  2022-02-19 [1] CRAN (R 4.1.0)
#>  future.apply          1.8.1   2021-08-10 [1] CRAN (R 4.1.0)
#>  generics              0.1.2   2022-01-31 [1] CRAN (R 4.1.0)
#>  ggplot2               3.3.5   2021-06-25 [1] CRAN (R 4.1.0)
#>  ggrepel               0.9.1   2021-01-15 [1] CRAN (R 4.1.0)
#>  ggridges              0.5.3   2021-01-08 [1] CRAN (R 4.1.0)
#>  globals               0.14.0  2020-11-22 [1] CRAN (R 4.1.0)
#>  glue                  1.6.2   2022-02-24 [1] CRAN (R 4.1.0)
#>  goftest               1.2-3   2021-10-07 [1] CRAN (R 4.1.0)
#>  gridExtra             2.3     2017-09-09 [1] CRAN (R 4.1.0)
#>  gtable                0.3.0   2019-03-25 [1] CRAN (R 4.1.0)
#>  highr                 0.9     2021-04-16 [1] CRAN (R 4.1.0)
#>  htmltools             0.5.2   2021-08-25 [1] CRAN (R 4.1.0)
#>  htmlwidgets           1.5.4   2021-09-08 [1] CRAN (R 4.1.0)
#>  httpuv                1.6.5   2022-01-05 [1] CRAN (R 4.1.0)
#>  httr                  1.4.2   2020-07-20 [1] CRAN (R 4.1.0)
#>  ica                   1.0-2   2018-05-24 [1] CRAN (R 4.1.0)
#>  igraph                1.2.11  2022-01-04 [1] CRAN (R 4.1.0)
#>  irlba                 2.3.5   2021-12-06 [1] CRAN (R 4.1.0)
#>  jsonlite              1.8.0   2022-02-22 [1] CRAN (R 4.1.0)
#>  KernSmooth            2.23-20 2021-05-03 [1] CRAN (R 4.1.0)
#>  knitr                 1.37    2021-12-16 [1] CRAN (R 4.1.0)
#>  labeling              0.4.2   2020-10-20 [1] CRAN (R 4.1.0)
#>  later                 1.3.0   2021-08-18 [1] CRAN (R 4.1.0)
#>  lattice               0.20-45 2021-09-22 [1] CRAN (R 4.1.0)
#>  lazyeval              0.2.2   2019-03-15 [1] CRAN (R 4.1.0)
#>  leiden                0.3.9   2021-07-27 [1] CRAN (R 4.1.0)
#>  lifecycle             1.0.1   2021-09-24 [1] CRAN (R 4.1.0)
#>  listenv               0.8.0   2019-12-05 [1] CRAN (R 4.1.0)
#>  lmtest                0.9-40  2022-03-21 [1] CRAN (R 4.1.0)
#>  magrittr              2.0.2   2022-01-26 [1] CRAN (R 4.1.0)
#>  MASS                  7.3-55  2022-01-13 [1] CRAN (R 4.1.0)
#>  Matrix                1.4-0   2021-12-08 [1] CRAN (R 4.1.0)
#>  matrixStats           0.61.0  2021-09-17 [1] CRAN (R 4.1.0)
#>  mgcv                  1.8-39  2022-02-24 [1] CRAN (R 4.1.0)
#>  mime                  0.12    2021-09-28 [1] CRAN (R 4.1.0)
#>  miniUI                0.1.1.1 2018-05-18 [1] CRAN (R 4.1.0)
#>  munsell               0.5.0   2018-06-12 [1] CRAN (R 4.1.0)
#>  nlme                  3.1-155 2022-01-13 [1] CRAN (R 4.1.0)
#>  parallelly            1.30.0  2021-12-17 [1] CRAN (R 4.1.0)
#>  patchwork             1.1.1   2020-12-17 [1] CRAN (R 4.1.0)
#>  pbapply               1.5-0   2021-09-16 [1] CRAN (R 4.1.0)
#>  pillar                1.7.0   2022-02-01 [1] CRAN (R 4.1.0)
#>  pkgconfig             2.0.3   2019-09-22 [1] CRAN (R 4.1.0)
#>  plotly                4.10.0  2021-10-09 [1] CRAN (R 4.1.0)
#>  plyr                  1.8.6   2020-03-03 [1] CRAN (R 4.1.0)
#>  png                   0.1-7   2013-12-03 [1] CRAN (R 4.1.0)
#>  polyclip              1.10-0  2019-03-14 [1] CRAN (R 4.1.0)
#>  promises              1.2.0.1 2021-02-11 [1] CRAN (R 4.1.0)
#>  purrr                 0.3.4   2020-04-17 [1] CRAN (R 4.1.0)
#>  R.cache               0.15.0  2021-04-30 [1] CRAN (R 4.1.0)
#>  R.methodsS3           1.8.1   2020-08-26 [1] CRAN (R 4.1.0)
#>  R.oo                  1.24.0  2020-08-26 [1] CRAN (R 4.1.0)
#>  R.utils               2.11.0  2021-09-26 [1] CRAN (R 4.1.0)
#>  R6                    2.5.1   2021-08-19 [1] CRAN (R 4.1.0)
#>  RANN                  2.6.1   2019-01-08 [1] CRAN (R 4.1.0)
#>  rappdirs              0.3.3   2021-01-31 [1] CRAN (R 4.1.0)
#>  RColorBrewer          1.1-2   2014-12-07 [1] CRAN (R 4.1.0)
#>  Rcpp                  1.0.8.3 2022-03-17 [1] CRAN (R 4.1.0)
#>  RcppAnnoy             0.0.19  2021-07-30 [1] CRAN (R 4.1.0)
#>  reprex                2.0.1   2021-08-05 [1] CRAN (R 4.1.0)
#>  reshape2              1.4.4   2020-04-09 [1] CRAN (R 4.1.0)
#>  reticulate            1.24    2022-01-26 [1] CRAN (R 4.1.0)
#>  rlang                 1.0.2   2022-03-04 [1] CRAN (R 4.1.0)
#>  rmarkdown             2.13    2022-03-10 [1] CRAN (R 4.1.0)
#>  ROCR                  1.0-11  2020-05-02 [1] CRAN (R 4.1.0)
#>  rpart                 4.1.16  2022-01-24 [1] CRAN (R 4.1.0)
#>  rstudioapi            0.13    2020-11-12 [1] CRAN (R 4.1.0)
#>  Rtsne                 0.15    2018-11-10 [1] CRAN (R 4.1.0)
#>  scales                1.1.1   2020-05-11 [1] CRAN (R 4.1.0)
#>  scattermore           0.8     2022-02-14 [1] CRAN (R 4.1.0)
#>  sctransform           0.3.3   2022-01-13 [1] CRAN (R 4.1.0)
#>  sessioninfo           1.2.2   2021-12-06 [1] CRAN (R 4.1.0)
#>  Seurat              * 4.1.0   2022-03-23 [1] Github (satijalab/seurat@699dd91)
#>  SeuratData          * 0.2.1   2021-06-03 [1] Github (satijalab/seurat-data@b59556b)
#>  SeuratObject        * 4.0.4   2021-11-23 [1] CRAN (R 4.1.0)
#>  shiny                 1.7.1   2021-10-02 [1] CRAN (R 4.1.0)
#>  spatstat.core         2.4-0   2022-02-15 [1] CRAN (R 4.1.0)
#>  spatstat.data         2.1-2   2021-12-17 [1] CRAN (R 4.1.0)
#>  spatstat.geom         2.3-2   2022-02-12 [1] CRAN (R 4.1.0)
#>  spatstat.random       2.1-0   2022-02-12 [1] CRAN (R 4.1.0)
#>  spatstat.sparse       2.1-0   2021-12-17 [1] CRAN (R 4.1.0)
#>  spatstat.utils        2.3-0   2021-12-12 [1] CRAN (R 4.1.0)
#>  stringi               1.7.6   2021-11-29 [1] CRAN (R 4.1.0)
#>  stringr               1.4.0   2019-02-10 [1] CRAN (R 4.1.0)
#>  stxBrain.SeuratData * 0.1.1   2021-06-03 [1] local
#>  styler                1.7.0   2022-03-13 [1] CRAN (R 4.1.0)
#>  survival              3.3-1   2022-03-03 [1] CRAN (R 4.1.0)
#>  tensor                1.5     2012-05-05 [1] CRAN (R 4.1.0)
#>  tibble                3.1.6   2021-11-07 [1] CRAN (R 4.1.0)
#>  tidyr                 1.2.0   2022-02-01 [1] CRAN (R 4.1.0)
#>  tidyselect            1.1.2   2022-02-21 [1] CRAN (R 4.1.0)
#>  utf8                  1.2.2   2021-07-24 [1] CRAN (R 4.1.0)
#>  uwot                  0.1.11  2021-12-02 [1] CRAN (R 4.1.0)
#>  vctrs                 0.3.8   2021-04-29 [1] CRAN (R 4.1.0)
#>  viridisLite           0.4.0   2021-04-13 [1] CRAN (R 4.1.0)
#>  withr                 2.5.0   2022-03-03 [1] CRAN (R 4.1.0)
#>  xfun                  0.30    2022-03-02 [1] CRAN (R 4.1.0)
#>  xml2                  1.3.3   2021-11-30 [1] CRAN (R 4.1.0)
#>  xtable                1.8-4   2019-04-21 [1] CRAN (R 4.1.0)
#>  yaml                  2.3.5   2022-02-21 [1] CRAN (R 4.1.0)
#>  zoo                   1.8-9   2021-03-09 [1] CRAN (R 4.1.0)
#> 
#>  [1] /home/user/miniconda3/envs/r-4.1/lib/R/library
#> 
#> ──────────────────────────────────────────────────────────────────────────────
@royfrancis royfrancis added the bug Something isn't working label Mar 23, 2022
@royfrancis royfrancis changed the title How do you plot one slide of a multi-slice spatial dataset? How do you plot one slice of a multi-slice spatial dataset? Mar 23, 2022
@andrewwbutler
Copy link
Collaborator

Hi,

You can specify the image parameter to plot a single slice. E.g.

SpatialDimPlot(brain, images = "anterior1")

@royfrancis
Copy link
Contributor Author

royfrancis commented Mar 26, 2022

This didn't initially work for me due to #5128. Then I removed the package SpatialExperiment, restarted and then it worked. But, one minor issue is that the legend is still incorrect showing slices that are not displayed.

SpatialDimPlot(brain, images = "anterior1")

e

In addition, I don't think the ncol argument works.

SpatialDimPlot(brain,ncol=1)

@andrewwbutler
Copy link
Collaborator

The legend issue should be fixed now on the latest develop branch (v4.1.0.9002). ncol is a bit more complicated. For now, I'd recommend passing combine = FALSE to get a list of plots and then combining in your preferred arrangement using something like patchwork::wrap_plots().

@andrewwbutler
Copy link
Collaborator

The ncol should now work properly on the latest develop branch (v4.1.0.9005). Thanks for the reprex and please reopen if issues persists.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants