welch-lab / liger

R package for integrating and analyzing multiple single-cell datasets
GNU General Public License v3.0
380 stars 78 forks source link

How to split sample of function (plotByDatasetAndCluster) #268

Closed Jingle0814 closed 1 year ago

Jingle0814 commented 2 years ago

Hello, I want to plot a figure like seurat "DimPlot(SeuObj,split.by="time")" ,how can I do it by plotByDatasetAndCluster in liger?

cgao90 commented 1 year ago

Hi,

If you'd like to split the plot by time (Assuming each input dataset corresponds to one time point), you could try the following customized code:

library(ggplot2)
tsne_df <- data.frame(liger_object@tsne.coords) # After running LIGER pipeline
colnames(tsne_df) <- c("Dim1", "Dim2") # e.g. tSNE or UMAP coordinates
tsne_df[['Dataset']] <- unlist(lapply(1:length(liger_object@H), function(x) {
  rep(names(liger_object@H)[x], nrow(liger_object@H[[x]]))
}))

p <- ggplot(data = tsne_df, aes(Dim1, Dim2, color=Dataset)) +
     theme_bw() + 
     theme_cowplot(12) +
     geom_point() + 
     labs(title = "Example Plot",
          x = "Dim1", y = "Dim2") + 
     facet_wrap(~ Dataset)
p

Hope it helps!

Best,

samuel-marsh commented 1 year ago

As another option I have created package scCustomize that also has some Liger functionality. I have adapted the internal Liger plotting to support Seurat like arguments including split.by. You can check out functionality here: https://samuel-marsh.github.io/scCustomize/articles/LIGER_Functions.html

Best, Sam