Question: plotPCA - how to add labels to a PCA plot
1
gravatar for al-ash
2.4 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").

Thanks in advance!

deseq2 plotpca labels • 9.8k views
ADD COMMENTlink modified 2.4 years ago by Federico Marini120 • written 2.4 years ago by al-ash20
Answer: plotPCA - how to add labels to a PCA plot
2
gravatar for James W. MacDonald
2.4 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)

 

 

 

 

ADD COMMENTlink written 2.4 years ago by James W. MacDonald50k
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

ADD REPLYlink written 2.4 years ago by Michael Love23k

thanks! I used this approach in the end.

ADD REPLYlink written 2.4 years ago by al-ash20
Answer: plotPCA - how to add labels to a PCA plot
1
gravatar for Federico Marini
2.4 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

ADD COMMENTlink written 2.4 years ago by Federico Marini120

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 REPLYlink written 2.4 years ago by al-ash20
Please log in to add an answer.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 16.09
Traffic: 211 users visited in the last hour