Question: plotPCA - how to add labels to a PCA plot
1
2.6 years ago by
al-ash20
al-ash20 wrote:

I'm analyzing my HTseq count data using DEseq2 package. I generated the PCA plot using

plotPCA(rld, intgroup="condition")

Is there any straightforward way to label the points in a PCA plot by the names of the samples? (for example using a value named "sampleNames").

deseq2 plotpca labels • 11k views
modified 2.6 years ago by Federico Marini120 • written 2.6 years ago by al-ash20
Answer: plotPCA - how to add labels to a PCA plot
2
2.6 years ago by
United States
James W. MacDonald50k wrote:

If there is an easy way, I am sure Mike will be along soon with whatever that might be. For now, do note that plotPCA uses ggplot2, so you can always capture the output and rejigger to your heart's content. Using the example for plotPCA, we can do this:

> example(plotPCA)
## now recapture the last plot in a variable
> z <- plotPCA( DESeqTransform( se ) )
## replot, obscuring points with the sample name
> z + geom_label(aes(label = name))
## or 'nudge' the points up a bit
> nudge <- position_nudge(y = 1)
> z + geom_label(aes(label = name), position = nudge)
## different label without the box action
> z + geom_text(aes(label = name), position = nudge)

1

You can also build up the PCA plot by hand. See the second code chunk here:

https://bioconductor.org/packages/devel/bioc/vignettes/DESeq2/inst/doc/DESeq2.html#principal-component-plot-of-the-samples

thanks! I used this approach in the end.

Answer: plotPCA - how to add labels to a PCA plot
1
2.6 years ago by
Germany
Federico Marini120 wrote:

I am a big fan of the geom_label_repel, that you can also find directly implemented in the pcaplot function in my package, pcaExplorer (http://bioconductor.org/packages/pcaExplorer/) - note that you would need the ggrepel package