Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to Plot Multiple Modules onto one Violin Plot (VlnPlot()) #4551

Closed
ksaunders73 opened this issue May 31, 2021 · 4 comments
Closed

How to Plot Multiple Modules onto one Violin Plot (VlnPlot()) #4551

ksaunders73 opened this issue May 31, 2021 · 4 comments

Comments

@ksaunders73
Copy link

ksaunders73 commented May 31, 2021

From #3521 I learned how to plot multiple genes onto one plot using AddModuleScore():

tnbclist <- list(c("FABP7", "TSPAN8", "CYP4Z1", "HOXA10", "CLDN1",
                 "TMSB15A", "C10ORF10", "TRPV6", "HOXA9", "ATP13A4",
                 "GLYATL2", "RP11-48O20.4", "DYRK3", "MUCL1", "ID4", "FGFR2",
                 "SHOX2", "Z83851.1", "CD82", "COL6A1", "KRT23", "GCHFR",
                 "PRICKLE1", "GCNT2", "KHDRBS3", "SIPA1L2", "LMO4", "TFAP2B",
                 "SLC43A3", "FURIN", "ELF5", "C1ORF116", "ADD3", "EFNA3",
                 "EFCAB4A", "LTF", "LRRC31", "ARL4C", "GPNMB", "VIM", 
                 "SDR16C5", "RHOV", "PXDC1", "MALL", "YAP1", "A2ML1",
                 "RP1-257A7.5", "RP11-353N4.6", "ZBTB18", "CTD-2314B22.3", "GALNT3",
                 "BCL11A", "CXADR", "SSFA2", "ADM", "GUCY1A3", "GSTP1",
                 "ADCK3", "SLC25A37", "SFRP1", "PRNP", "DEGS1", "RP11-110G21.2",
                 "AL589743.1", "ATF3", "SIVA1", "TACSTD2", "HEBP2"))
sobj <- AddModuleScore(object = sobj, features = tnbclist, name = "TNBC_List") 
VlnPlot(sobj, features = "TNBC_List1")

image

From this I am able to plot one module onto a single violin plot, with the x axis being separated by cluster. Is there a way to plot multiple modules on the same plot, and not just the two plots listed side by side.

For example, to have the x axis be this "TNBC_List1" and this "ER_List1"?

ERlist <- list(c("CPB1", "RP11-53O19.1", "TFF1", "MB", "ANKRD30B",
            "LINC00173", "DSCAM-AS1", "IGHG1", "SERPINA5", "ESR1",
            "ILRP2", "IGLC3", "CA12", "RP11-64B16.2", "SLC7A2",
            "AFF3", "IGFBP4", "GSTM3", "ANKRD30A", "GSTT1", "GSTM1",
            "AC026806.2", "C19ORF33", "STC2", "HSPB8", "RPL29P11",
            "FBP1", "AGR3", "TCEAL1", "CYP4B1", "SYT1", "COX6C",
            "MT1E", "SYTL2", "THSD4", "IFI6", "K1AA1467", "SLC39A6",
            "ABCD3", "SERPINA3", "DEGS2", "ERLIN2", "HEBP1", "BCL2",
            "TCEAL3", "PPT1", "SLC7A8", "RP11-96D1.10", "H4C8",
            "PI15", "PLPP5", "PLAAT4", "GALNT6", "IL6ST", "MYC",
            "BST2", "RP11-658F2.8", "MRPS30", "MAPT", "AMFR", "TCEAL4",
            "MED13L", "ISG15", "NDUFC2", "TIMP3", "RP13-39P12.3", "PARD68"))

sobj <- AddModuleScore(object = sobj, features = ERlist, name = "ER_List") 

I tried a suggestion from this issue #3366 but unfortunately did not work (assuming I did this correctly), and just placed the two plots side by side instead of on one single plot:

sobj1 <- sobj
sobj1[['TNBC']] <- CreateAssayObject(data = t(x = FetchData(object = sobj1, vars = 'TNBC_List1')))
sobj1[['ER']] <- CreateAssayObject(data = t(x = FetchData(object = sobj1, vars = 'ER_List1')))
VlnPlot(sobj1, features = c('TNBC_List1', 'ER_List1'))

image

Hopefully this makes sense, and thanks for reading!

@saketkc
Copy link
Collaborator

saketkc commented Jun 4, 2021

While this is currently not supported, you can pull the values using FetchData and then plot these using ggplot2:
Example:

> mydata <- FetchData(object = pbmc_small, vars = c('nCount_RNA',  'nFeature_RNA', 'ident'))
> mydata
               nCount_RNA nFeature_RNA ident
ATGCCAGAACGACT         70           47     0
CATGGCCTGTGCAT         85           52     0
GAACCTGATGAACC         87           50     0
TGACTGGATTCTCA        127           56     0
AGTCAGACTGCACA        173           53     0

You would melt the data frame to make it long form and assign nCount_RNA and nFeature_RNA as variables which you could then use to color by in ggplot.

@saketkc saketkc closed this as completed Jun 4, 2021
@ksaunders73
Copy link
Author

ksaunders73 commented Jun 5, 2021

Thank you very much, @saketkc !

I think this is what you were saying I should do (but correct me if I am wrong):

sobjlists <- FetchData(object = sobj, vars = c("ER_List1", "TNBC_List1"))
head(sobjlists)

image

library(reshape2)
melt(sobjlists, id.vars = c("ER_List1", "TNBC_List1"))

vln <- ggplot(sobjlists, aes(x= ER_List1, y = TNBC_List1, color = ER_List1)) + geom_violin()
vln

image

Is there a way to have this plotted per cluster or is it only able to be compared to each other do you think?

@saketkc
Copy link
Collaborator

saketkc commented Jun 5, 2021

You would also need also idents say the "seurat_clusters" column in FetchData which would be your xaxis. Since this is more of a ggplot2 question, I would encourage you to explore other forums.

@ksaunders73
Copy link
Author

Thank you so much again @saketkc!

Due to my data having basically every cell in that seurat_clusters column, and the x-axis as a result having way too many entries, I tried this instead, essentially making a new column in the meta data listing the cluster identity, and then making that column the x axis. I then colored each violin plot by my gene list:

#after labeling my UMAP
sobj[["ClusterName"]] <- Idents(object = sobj)

sobjlists <- FetchData(object = sobj, vars = c("ER_List1", "TNBC_List1", "ClusterName"))
library(reshape2)
melt(sobjlists, id.vars = c("ER_List1", "TNBC_List1", "ClusterName"))
p <- ggplot() + geom_violin(data = sobjlists, aes(x= ClusterName, y = ER_List1, fill = ER_List1, colour = "ER+ Signature"))+ geom_violin(data = sobjlists, aes(x= ClusterName, y = TNBC_List1, fill = TNBC_List1, colour="TNBC Signature"))

image

See this page for lots of customization tips: http://www.sthda.com/english/wiki/ggplot2-violin-plot-quick-start-guide-r-software-and-data-visualization

Thanks again @saketkc and I hope this all helps someone else with their work!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants