seurat
seurat copied to clipboard
Bug(s) in SpatialDimPlot
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.
These are critical functions for plotting any type of spatial data so a bug fix would really be appreciated :) Thank you!
me too! If there is any solution, please let me know
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.
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.
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)
It's glad to know that SpatialDimPlot works on the Idents of the Seurat object again.