seurat icon indicating copy to clipboard operation
seurat copied to clipboard

Bug(s) in SpatialDimPlot

Open mvhunter1 opened this issue 2 years ago • 2 comments

Hi Seurat team, Thank you so much for your service to the community. Similar to previous issue #5975 I am unable to use SpatialDimPlot or SpatialPlot with group.by after upgrading to Seurat 4.1.1. The plots appear as unlabeled points no matter which metadata column is used to group the data. Screen Shot 2022-07-12 at 5 30 18 PM These are critical functions for plotting any type of spatial data so a bug fix would really be appreciated :) Thank you!

mvhunter1 avatar Jul 12 '22 21:07 mvhunter1

me too! If there is any solution, please let me know

lengjing0519 avatar Aug 17 '22 08:08 lengjing0519

I've encountered this as well in v4.1.1, while it worked in v4.1.0. It appears to bisect to commit 4024b0c38a8a4009d4889de145385e5b10e7adba, where the addition of cols <- cols[names(x = cols) %in% data$ident] appears to filter out the colors when grouping by something other than ident.

The workaround for me was just to comment out this line. I also tried replacing data$ident with data[[col.by]], but col.by gets surrounded by backticks and doesn't appear to work here.

yoda-vid avatar Aug 22 '22 06:08 yoda-vid

Hi, I have updated my Seurat to 4.3.0, however, the SpatialDimPlot(..., col = colors) still produce the error of Insufficient values in manual scale. 12 needed but only 0 provided, which is similar to the previous issue.

Luckily, I found a suggestion here. The suggestion fixes the error. My version of the solution is like this:

numCluster <- [email protected]$seurat_clusters %>% unique %>% length
colors = Seurat::DiscretePalette(n = numCluster, palette = "polychrome")
Idents(my_seurat_object) # should be seurat clusters.
# The colors, which is a character vector of different color codes, need the names for the vector.
names(colors) <- Idents(my_seurat_object) %>% levels()

the_ggplot_list <- SpatialDimPlot(
    my_seurat_object, # the seurat object here contain only one sample, though it can contain more samples.
    images = "my_image_name",
    group.by = c("seurat_clusters"),
    pt.size.factor = 1.15,
    label = TRUE,
    label.size = 6,
    repel = TRUE,
    combine = FALSE,
    cols = colors
)
print(the_ggplot_list)

If the error could be further investigated by the devolopers, that would be terrific. Otherwise, it would be helpful if the document of SpatialDimPlot(..., col = colors) have more explanation, which should not be hard.

Thank you very much for your contribution to the science community.

sciencepeak avatar Feb 04 '23 05:02 sciencepeak

I have an alternative trick here, it seems that the SpatialDimPlot still works on the Idents of the Seurat object.

Idents(ST.seu) <- ST.seu$group
SpatialDimPlot(ST.seu)

chengwenxuan1997 avatar Mar 09 '23 02:03 chengwenxuan1997

It's glad to know that SpatialDimPlot works on the Idents of the Seurat object again.

sciencepeak avatar Mar 16 '23 17:03 sciencepeak