kstreet13 / slingshot

Functions for identifying and characterizing continuous developmental trajectories in single-cell data.
259 stars 42 forks source link

Assign Seurat Colors to Slingshot plot #219

Closed deepdiver25 closed 12 months ago

deepdiver25 commented 1 year ago

Good morning!

I've bene browsing the vignette and closed posts on Github but I've been unable to find an answer to my question. This feels like It should be simple, but I can't seem to figure it out.

I want to maintain the color palette of my seurat clusters on my slingshot plot.

Here is what I'm running(without trying to change colors):

_dimred <- Bs@reductions$umap@cell.embeddings clustering <- Bs$RNA_snn_res.0.3 counts <- as.matrix(Bs@assays$RNA@counts[Bs@assays$RNA@var.features, ]) lineages <- getLineages(data = dimred, clusterLabels = clustering, start.clus=c("5")) lineages

par(mfrow=c(1,2)) plot(dimred[,1:2], col = clustering, cex=.5,pch = 16) for(i in levels(clustering)){ text( mean(dimred[clustering==i,1]), mean(dimred[clustering==i,2]), labels = i,font = 2) } plot(dimred, col = clustering, pch = 16) lines(SlingshotDataSet(lineages), lwd = 3, col = "black")_

I'm sorry if this has been answered before, but the posts were quite old and there were references to updating the packages and none of the answers seemed to work for me. (Namely: cell_colors_clust <- cell_pal(SeuratObj$seurat_clusters, hue_pal()))

Thank you!

kstreet13 commented 1 year ago

Hi @deepdiver25,

I'm definitely no expert when it comes to Seurat or ggplot, but I'm pretty sure this is possible! First though, I wanted to mention that the actual Slingshot vignette can be found here: https://bioconductor.org/packages/release/bioc/vignettes/slingshot/inst/doc/vignette.html

Anyway, I think the easiest way to do this would be to add the curves directly to a plot produced by Seurat, which should be possible through our visualization package, traviz. This vignette shows how to plot Slingshot elements with ggplot2, which should hopefully allow you to add them to Seurat plots.

If that doesn't work, let me know and I'll look into it further! Best, Kelly

deepdiver25 commented 1 year ago

Kelly,

Thank you for the vignette, I agree that that will probably be the easiest and I wish I had thought of that. My only problem is that in the vignette linked they refer to the aesthetic for geom_path as aes = Lineage but there isn't any information provided on what "Lineage" is.

curves <- slingCurves(sds, as.df = TRUE) p + geom_path(data = curves %>% arrange(Order), aes(group = Lineage))

kstreet13 commented 1 year ago

It's the name of a column in the curves data frame (same with Order).