How to make a complicated dot plot for scRNAseq marker genes with ggplot2?
2
2
Entering edit mode
4.0 years ago
grayapply2009 ▴ 300

I like this dot plot (Figure a) for showing marker gene expression patterns for the clusters. Any ideas about how to make this plot with ggplot2? Some pseudocode would be enough.

enter image description here

single cell RNAseq ggplot2 RNA-Seq R • 10k views
ADD COMMENT
3
Entering edit mode
4.0 years ago

Use dittoDotPlot from the dittoSeq package. Much easier than from scratch. The resulting plot is still a ggplot2 object, so you can customize as you'd like. Though the function itself is also quite flexible. Works natively on SingleCellExperiment, Seurat, or SummarizedExperiment objects and can use gene expression and/or continuous metadata variables as desired.

So all you'd have to do is grab your top 5 markers for each cluster or what have you and feed them in along with your data object:

your_markers <- c("Gfap", "Vim", "Aqp4")
dittoDotPlot(sce_seurat_or_se_object, your_markers, group.by = "cluster_metadata_column") + coord_flip()
ADD COMMENT
0
Entering edit mode

Thank you, my friend. Sounds like a perfect solution to me. I’m trying it now.

ADD REPLY
0
Entering edit mode

harmony also might help here.

ADD REPLY
0
Entering edit mode

How so? Harmony has no viz functions.

ADD REPLY
0
Entering edit mode

I just noticed Seurat has a DotPlot function that does the same thing.

ADD REPLY
0
Entering edit mode

That it does, if you're using Seurat. I like to think the dittoSeq version is more flexible given it handles metadata variables and multiple data formats, but I was involved in its development so I am a bit biased.

ADD REPLY
0
Entering edit mode

Hi Jared, since you are one of the developers of dittoSeq, is it possible to revise the dittoDotPlot function so that it makes the plot like the one in the example by default?

ADD REPLY
0
Entering edit mode

What do you mean exactly? I can tell you now that the cell numbers in each cluster are best added after the fact in Illustrator or your favorite figure editor. Getting the clusters labeled and oriented as in that figure would be something like:

dittoDotPlot(
    myRNA, c("gene1", "gene2", "gene3", "gene4"),
    group.by = "clustering") + scale_y_discrete(position = "right") + coord_flip()
ADD REPLY
0
Entering edit mode

I mean the aesthetics of the figure but I guess it's no big deal since the result is a ggplot object. Thanks. I already made the figure with your help.

ADD REPLY
0
Entering edit mode

It would be so useful if it was possible to provide a named list of gene vectors, instead of just one. I mean like this:

dittoDotPlot( myRNA, list("A"=c("gene1", "gene2"), "B"=c("gene3", "gene4"), "C"=c("gene5","gene6")), group.by = "clustering") + scale_y_discrete(position = "right") + coord_flip()

It is possible in the normal Seurat DotPlot function but there I can't split by identities with facet... I'm struggling so much to find a way to get both

ADD REPLY
0
Entering edit mode

If you open an issue on the dittoSeq Github with an example of what you want, we may be able to implement it (or provide a way to hack it together).

ADD REPLY
0
Entering edit mode

Jared poked me, and I started development on this feature =). You can try out the in-progress dev version by installing via remotes::install_github("dtm2451/dittoSeq@dotplot-categories")

ADD REPLY
0
Entering edit mode

Just wanna add another note about this: Although similar, there is a major implementation difference between how dittoSeq::dittoDotPlot() and Seurat::DotPlot() work if you are doing any subsetting to show only certain cell groups: Seurat's does all data summary and scaling BEFORE trimming to only your requested groups, while dittoDotPlot's implementation does the subsetting before calculating expression summaries and performing scaling. This let's subsetting be more flexible in dittoSeq's version. I'm just flagging this for when you or anyone else notice the two plotters give a different result -- Seurat's docs tend to be more sparse so I figured this out myself through trial-and-error!

ADD REPLY
1
Entering edit mode
4.0 years ago
zx8754 12k

From scratch, this is just a start, depends how far you want to go to have the same exact plot:

library(ggplot2) # ggplot2_3.3.3

# example data
d <- mtcars[1:10, ]
d$car <- rownames(d)
d$carb <- as.factor(d$carb)
d$cyl <- as.factor(d$cyl)

# plot
ggplot(d, aes(car, carb, size = qsec, fill = cyl)) +
  geom_point(shape = 21) +
  theme_light() +
  guides(x =  guide_axis(angle = 90))

But, I'd first find that paper where this plot is coming from, then check if they have anything at GitHub.

ADD COMMENT
0
Entering edit mode

Thank you. It's a good way to customize the graph.

ADD REPLY

Login before adding your answer.

Traffic: 1938 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6