Adding text labels to PCA plot
1
0
Entering edit mode
John ▴ 30
@john-9676
Last seen 5.9 years ago
dds = makeExampleDESeqDataSet(betaSD=1)
vsd = varianceStabilizingTransformation(dds)
p = plotPCA(vsd)
print(p)

## Add text labels (for presentation graphics, consider additional
## layout operations that avoid overplotting, such as the FField package on CRAN)
names = colData(vsd)$sample

p = update(p, panel = function(x, y, ...) {
      lattice::panel.xyplot(x, y, ...);
      lattice::ltext(x=x, y=y, labels=names, pos=1, offset=1, cex=0.8)
    })
print(p)

This doesn't work:

Error in update.default(p, panel = function(x, y, ...) { : 

  need an object with call component

How can I make this work?

Thank you for the help.

J.

deseq2 • 8.9k views
ADD COMMENT
2
Entering edit mode

A quick answer would be something like this:

library(ggplot2)
p <- plotPCA(vsd)
p <- p + geom_text(aes_string(x = "PC1", y = "PC2", label = "name"), color = "black")
print(p)
ADD REPLY
0
Entering edit mode

Thanks Mike.

Also for others viewing the thread, if you get stuck trying to customize this plot, you can also directly use ggplot().

In the DESeq2 vignette search for the text: "It is also possible to customize the PCA plot using the ggplot function."

ADD REPLY
0
Entering edit mode
John ▴ 30
@john-9676
Last seen 5.9 years ago

Thanks a lot Mike.

ADD COMMENT

Login before adding your answer.

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