Plot PCA with ellipses
1
0
Entering edit mode
Matan G. ▴ 60
@matan-g-22483
Last seen 3.3 years ago

Hello,

I'm trying to add ellipses after plotting PCA with two colored groups. I've used this line to generate the PCA:

DEGsT_PCA <- plotPCA((vsd)[DEGsT_ind, samples_for_mat], intgroup ="condition")

And now I'd like to add ellipses around the two groups of the "condition". When I treat "DEGsT_PCA" as a ggplot component and add:

DEGsT_PCA + stat_ellipse()

I get the following warning:

Warning message: Computation failed in stat_ellipse(): could not find function "mat2df"

Does anyone have a solution for this?

Best

pca • 9.3k views
ADD COMMENT
0
Entering edit mode
@mikelove
Last seen 18 hours ago
United States

It looks like you are trying to add a ggplot2 element, but I'm not sure if you loaded the ggplot2 package.

library(ggplot2)

This can be a bit confusing, but packages in R can make use of other packages without loading them for you. There are various options for how packages depend on each other, but in this case, ggplot2 isn't loaded when DESeq2 is loaded.

ADD COMMENT
1
Entering edit mode

Wouldn't one also need to add geom_point() ? There is nothing to draw an ellipse around.

Also a group must be defined, around what the ellipse should be drawn?

something like this here?

ggplot(tmp, aes(PC1, PC2, color=sample, shape=treatment, group = outcome)) +
  geom_point(size=3) +
  stat_ellipse()
ADD REPLY
0
Entering edit mode

Hi Assa,

When using "plotPCA" the way I did, I get the groups color coded and defined. I've also tried the method you mentioned earlier but still getting the same result.

Thank you

ADD REPLY
0
Entering edit mode

Hi Michael, Thanks for replying.

Even when loading ggplot2 separately just before applying PCA and adding the component, I get the same warning and no addition of ellipses.

Maybe I'm not even in the right direction in the method I'm using. Not sure how to solve this.

Best

ADD REPLY
1
Entering edit mode

Can you try this? It works fine for me, so I'm not sure what would be the issue.

dds <- makeExampleDESeqDataSet(n=2000)
vsd <- vst(dds)
library(ggplot2)
plotPCA(vsd) + stat_ellipse()
ADD REPLY
0
Entering edit mode

Well, I tried it and it gave me the same error. I then just restarted R and now everything works.

Thank you for everything.

Best

ADD REPLY

Login before adding your answer.

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