Plot PC1 and PC4 in plotPCA function
1
0
Entering edit mode
synat.keam • 0
@1d56a66c
Last seen 8 months ago
Australia

Dear Michael and others,

Hope you all are well. Does anyone know whether we can plot PC1 vs. PC3/PC4 in plotPCA?

Kind Regards,

synat

DESeq2 plotPCA • 3.0k views
ADD COMMENT
2
Entering edit mode

I edited the plotPCA code a little to do just this! First I added a "nPC" variable to the function:

function (object, intgroup = "condition", ntop = 500, returnData = FALSE, nPC = 2)

It defaults to two, so it behaves just as the original if you don't specify.

Then you need to change the following line:

d <- data.frame(PC1 = pca$x[, 1], PC2 = pca$x[, 2], group = group, intgroup.df, name = colnames(object))

to:

d <- cbind(pca$x[,seq_len(min(nPC, ncol(pca$x))), drop = FALSE], data.frame(group = group, intgroup.df, name = colnames(object)))

It's just pulling more columns from the pca$x data frame in the prcomp object, while keeping everything else in the data frame. I didn't change anything to be able to plot these additional PCs, as I usually use this to get a conveniently formatted data frame using returnData=T. But because the data is there, it wouldn't be too hard to change.

Hope this helps!

ADD REPLY
0
Entering edit mode

Thanks, dear for your help.

Kind Regards,

synat

ADD REPLY
0
Entering edit mode

This is so simple and elegant it should be incorporated into the plotPCA function! A small modification to make it run smoothly is:

attr(d, "percentVar") <- percentVar[1:2]

to

attr(d, "percentVar") <- percentVar[1:nPC]
ADD REPLY
1
Entering edit mode
@mikelove
Last seen 3 days ago
United States

This has been asked before, see the Note in the function man page.

ADD COMMENT
0
Entering edit mode

Thanks you, Dr. Michael. Kind Regards,

ADD REPLY

Login before adding your answer.

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