plotPCA - how to add labels to a PCA plot
2
3
Entering edit mode
al-ash ▴ 50
@al-ash-12112
Last seen 5.9 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").

Thanks in advance!

plotPCA deseq2 labels • 45k views
ADD COMMENT
6
Entering edit mode
@james-w-macdonald-5106
Last seen 11 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)

 

 

 

 

ADD COMMENT
1
Entering edit mode
ADD REPLY
0
Entering edit mode

thanks! I used this approach in the end.

ADD REPLY
3
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

ADD COMMENT
1
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.

ADD REPLY

Login before adding your answer.

Traffic: 702 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