plotPCA - how to add labels to a PCA plot
2
1
Entering edit mode
al-ash ▴ 20
@al-ash-12112
Last seen 2.6 years ago

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").

plotPCA deseq2 labels • 20k views
3
Entering edit mode
@james-w-macdonald-5106
Last seen 18 hours ago
United States

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
Entering edit mode
0
Entering edit mode

thanks! I used this approach in the end.

1
Entering edit mode
@federico-marini-6465
Last seen 3 months ago
Germany

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

0
Entering edit mode

Thanks for pointing out ggrepel - I used the default geom_text_label which sufficiently solved in my case the overlapping labels but I will definitely give pcaExplorer a try.