seurat icon indicating copy to clipboard operation
seurat copied to clipboard

Error when running SpatialDimPlot

Open FionaMoon opened this issue 1 year ago • 7 comments

Hi all, I got an error when running https://satijalab.org/seurat/articles/spatial_vignette. Here's the code:

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

The error looks like this:

Error in fill_alpha(data$fill %||% "black", data$alpha)

Does anyone know how to solve this problem?

FionaMoon avatar Feb 26 '24 08:02 FionaMoon

Hi,

I have a different error, but it might be related because I am facing it today for the first time and is related to label and maybe fill to.

This is running SpatialDimPlot(brain.norm.MNN, label = FALSE, ncol=4, image.alpha =0, stroke = 0)& theme(legend.position = "none")& scale_fill_manual(values = Ditto_cols25)

This is getting an error SpatialDimPlot(brain.norm.MNN, label = TRUE, ncol=4, image.alpha =0, stroke = 0)& theme(legend.position = "none")& scale_fill_manual(values = Ditto_cols25)

Error in .subset2(x, i, exact = exact) : Indexing outside the limits Additionally: Warning messages: 1: In max(data[, xynames["y"]]) : no non-missing argument for max; return -Inf 2: In min(data[, xynames["y"]]) : no non-missing argument for min; return Inf

What might be the problem? I just changed label= FALSE to label= TRUE

nina-hahn avatar Feb 26 '24 14:02 nina-hahn

Please provide the output of sessionInfo() so we can help to debug your issue 🙂

dcollins15 avatar Mar 01 '24 18:03 dcollins15

Hi dcollins15,

here you go.

sessionInfo() R version 4.3.1 (2023-06-16 ucrt) Platform: x86_64-w64-mingw32/x64 (64-bit) Running under: Windows 10 x64 (build 19045)

Matrix products: default

locale: [1] LC_COLLATE=German_Germany.utf8 LC_CTYPE=German_Germany.utf8 LC_MONETARY=German_Germany.utf8 [4] LC_NUMERIC=C LC_TIME=German_Germany.utf8

time zone: Europe/Berlin tzcode source: internal

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

other attached packages: [1] dittoViz_1.0.1 ggplot2_3.4.4 SeuratObject_4.1.4 Seurat_4.4.0

loaded via a namespace (and not attached): [1] fs_1.6.3 matrixStats_1.0.0 spatstat.sparse_3.0-2 bitops_1.0-7
[5] devtools_2.4.5 httr_1.4.7 RColorBrewer_1.1-3 profvis_0.3.8
[9] tools_4.3.1 sctransform_0.4.0 backports_1.4.1 utf8_1.2.3
[13] R6_2.5.1 lazyeval_0.2.2 uwot_0.1.16 urlchecker_1.0.1
[17] withr_2.5.1 sp_2.1-0 prettyunits_1.2.0 gridExtra_2.3
[21] progressr_0.14.0 cli_3.6.1 Biobase_2.60.0 spatstat.explore_3.2-3 [25] labeling_0.4.3 spatstat.data_3.0-1 ggridges_0.5.4 pbapply_1.7-2
[29] parallelly_1.36.0 sessioninfo_1.2.2 rstudioapi_0.15.0 RSQLite_2.3.1
[33] generics_0.1.3 ica_1.0-3 spatstat.random_3.1-6 car_3.1-2
[37] dplyr_1.1.3 Matrix_1.6-1.1 ggbeeswarm_0.7.2 fansi_1.0.5
[41] S4Vectors_0.38.2 abind_1.4-5 lifecycle_1.0.3 carData_3.0-5
[45] Rtsne_0.16 grid_4.3.1 blob_1.2.4 promises_1.2.1
[49] crayon_1.5.2 miniUI_0.1.1.1 lattice_0.21-8 cowplot_1.1.1
[53] KEGGREST_1.40.1 pillar_1.9.0 future.apply_1.11.0 codetools_0.2-19
[57] leiden_0.4.3 glue_1.6.2 data.table_1.14.8 remotes_2.4.2.1
[61] vctrs_0.6.3 png_0.1-8 gtable_0.3.4 cachem_1.0.8
[65] mime_0.12 survival_3.5-5 ellipsis_0.3.2 fitdistrplus_1.1-11
[69] ROCR_1.0-11 nlme_3.1-162 usethis_2.2.2 bit64_4.0.5
[73] RcppAnnoy_0.0.21 GenomeInfoDb_1.36.4 irlba_2.3.5.1 vipor_0.4.7
[77] KernSmooth_2.23-21 colorspace_2.1-0 BiocGenerics_0.46.0 DBI_1.1.3
[81] ggrastr_1.0.2 tidyselect_1.2.0 processx_3.8.2 bit_4.0.5
[85] compiler_4.3.1 plotly_4.10.2 scales_1.2.1 lmtest_0.9-40
[89] callr_3.7.3 stringr_1.5.0 digest_0.6.33 goftest_1.2-3
[93] spatstat.utils_3.0-3 XVector_0.40.0 htmltools_0.5.6.1 pkgconfig_2.0.3
[97] fastmap_1.1.1 rlang_1.1.1 htmlwidgets_1.6.2 shiny_1.7.5.1
[101] farver_2.1.1 zoo_1.8-12 jsonlite_1.8.7 RCurl_1.98-1.12
[105] magrittr_2.0.3 GenomeInfoDbData_1.2.10 patchwork_1.1.3 munsell_0.5.0
[109] Rcpp_1.0.11 reticulate_1.34.0 stringi_1.7.12 zlibbioc_1.46.0
[113] MASS_7.3-60 plyr_1.8.9 pkgbuild_1.4.2 parallel_4.3.1
[117] listenv_0.9.0 ggrepel_0.9.4 deldir_1.0-9 Biostrings_2.68.1
[121] splines_4.3.1 tensor_1.5 ps_1.7.5 igraph_1.5.1
[125] ggpubr_0.6.0 spatstat.geom_3.2-5 ggsignif_0.6.4 reshape2_1.4.4
[129] stats4_4.3.1 pkgload_1.3.3 BiocManager_1.30.22 httpuv_1.6.11
[133] RANN_2.6.1 tidyr_1.3.0 purrr_1.0.2 polyclip_1.10-6
[137] future_1.33.0 scattermore_1.2 broom_1.0.5 xtable_1.8-4
[141] rstatix_0.7.2 later_1.3.1 viridisLite_0.4.2 tibble_3.2.1
[145] memoise_2.0.1 beeswarm_0.4.0 AnnotationDbi_1.62.2 IRanges_2.34.1
[149] cluster_2.1.4 globals_0.16.2

nina-hahn avatar Mar 04 '24 09:03 nina-hahn

I found a solution. Some of the images were empty in the data set. When I only select the images with data, it is working.

nina-hahn avatar Mar 13 '24 08:03 nina-hahn

@FionaMoon were you able to solve your issue? I'm having the same problem and I'm also unsure how to fix it.

angie-john avatar Apr 04 '24 20:04 angie-john

This is caused, as the error implies, by the missing function fill_alpha which is a ggplot2 function. It was just added in version 3.5.0. I had the same error with any Spatial*Plot and could fix it by upgrading ggplot2 to 3.5.0. Since fill_alpha is not used in the Seurat code (at least I couldn't find any usage) it seems that a dependency recently adopted the most recent ggplot2 features and API changes.

ppm1337 avatar Apr 11 '24 14:04 ppm1337

Hi everyone,

I was having the same issue. As @ppm1337 mentioned, fill_alpha function is missing or simply not working for whatever reason. However, updating ggplot2 to version 3.5.0 didn't work for me either. My solution was to add the fill_alpha function to my R environment as follows:

fill_alpha <- function(fill, alpha) {
  if (!is.list(fill)) {
    # Happy path for no patterns
    return(alpha(fill, alpha))
  }
  if (is_pattern(fill) || any(vapply(fill, is_pattern, logical(1)))) {
    check_device("patterns", action = "warn")
    fill <- pattern_alpha(fill, alpha)
    return(fill)
  } else {
    # We are either dealing with faulty fill specification, or we have a legend
    # key that is trying to draw a single colour. It can be given that colour
    # as a list due to patterns in other keys.
    msg <- paste0(
      "{.field fill} must be a vector of colours or list of ",
      "{.cls GridPattern} objects."
    )
    # If single colour list, try applying `alpha()`
    fill <- try_fetch(
      Map(alpha, colour = fill, alpha = alpha),
      error = function(cnd) {
        cli::cli_abort(msg, call = expr(fill_alpha()))
      }
    )
    # `length(input)` must be same as `length(output)`
    if (!all(lengths(fill) == 1)) {
      cli::cli_abort(msg)
    }
    return(unlist(fill))
  }
}

Then, run SpatialDimPlot or SpatialPlot and everthing should be set. Hope it helps!

dimitrisokolowskei avatar Jul 14 '24 03:07 dimitrisokolowskei