Skip to content

SpatialPlot can not plot with manual colors #6083

Answered by Secretloong
Secretloong asked this question in Q&A
Discussion options

You must be logged in to vote

I have resolved this problem.
As ggplot2 said in their scale-manual.r, it's better use a named vector to colors. so I named the my manual color vector col with the Idents(). then it works OK.

Idents(object) <- object$annotation
require(RColorBrewer)
col <- c(brewer.pal(9, "Set1")[c(1:5, 7, 6, 8, 9)])
col <- head(col, length(unique(Idents(object))))
###important
names(col) <- unique(Idents(object))
###
SpatialPlot(object, stroke=NA,image.alpha = 0.5, pt.size.factor=14, cols=col)

It's a strange problem, and not elegant. I suggest Seurat could deal with this by default.

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by Secretloong
# for free to join this conversation on GitHub. Already have an account? # to comment
Category
Q&A
Labels
None yet
1 participant