Search
Question: plotPCA - how to add labels to a PCA plot
0
gravatar for al-ash
10 months ago by
al-ash0
al-ash0 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!

ADD COMMENTlink modified 10 months ago by Federico Marini90 • written 10 months ago by al-ash0
1
gravatar for James W. MacDonald
10 months ago by
United States
James W. MacDonald45k 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 10 months ago by James W. MacDonald45k
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 10 months ago by Michael Love15k

thanks! I used this approach in the end.

ADD REPLYlink written 10 months ago by al-ash0
1
gravatar for Federico Marini
10 months ago by
Germany
Federico Marini90 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 10 months ago by Federico Marini90

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 10 months ago by al-ash0
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 2.2.0
Traffic: 231 users visited in the last hour