Adding ellipse in PCAtools biplot
1
0
Entering edit mode
M Tuhin • 0
@4ad593ce
Last seen 14 months ago
Australia

Enter the body of text here

Hi All, I need some urgent help regrading pca analysis to show the clustering of my 13 samples based on treatment condition. I have run the code and generated a biplot which is showing the 13 points represent 13 samples but the problem is I want to draw an ellipse for 2/3 replicates under the same treatment. How can i do that? Could anyone help me in this regards?

Please help me with your experiences.

Finalized script for PCA using Bioconductor::PCAtools

Principle component analysis

Without data normalization

library(readxl)

df <- read_excel("tpp.xlsx")

colnames(df)

ta <- df[, 2:14]

ta <- as.matrix(ta)

metadata <- data.frame(row.names = colnames(ta))

metadata$Group <- rep(NA, ncol(ta))

metadata$Group[seq(1,2)] <- 'Batch 1 Control'

metadata$Group[seq(3,4)] <- 'Batch 1 P100'

metadata$Group[seq(5,7)] <- 'Batch 2 Control'

metadata$Group[seq(8,10)] <- 'Batch 2 P25'

metadata$Group[seq(11,13)] <- 'Batch 2 P100'

library(ggplot2)

library(ggrepel)

library(PCAtools)

tpp.pca <- pca(ta, metadata = metadata, scale = FALSE)

biplot(tpp.pca)

biplot(tpp.pca, pointSize = 5, lab = NULL, labSize = 4, colby = 'Group', shape = 'Group', legendPosition = 'right')

biplot(tpp.pca, pointSize = 3, lab = p$yvars, labSize = 4, colby = 'Group', shape = 'Group', legendPosition = 'right')

Adding ellipse is still not working

All of these codes are not producing ellipse

biplot(tpp.pca, pointSize = 5, lab = NULL, labSize = 4, colby = 'Group', shape = 'Group', legendPosition = 'right') + geom_point() + stat_ellipse(aes(group = 'Group'), type = "norm")

An incomplete ellipse is formed from the above code

biplot(tpp.pca, pointSize = 5, lab = NULL, labSize = 4, colby = 'Group', shape = 'Group', ellipse = TRUE, legendPosition = 'right')

Above code results in:

Too few points to create an ellipse

library(ggforce) also used (may be wrong way)

biplot(tpp.pca, pointSize = 5, lab = NULL, labSize = 4, colby = 'Group', shape = 'Group', ellipse = TRUE, legendPosition = 'right') +

ggforce::geom_mark_ellipse(aes(color = 'Group'))r

include your problematic code here with any corresponding output

please also include the results of running the following in an R session

sessionInfo( )

```

Biplot FactoMineR proteomics PCAtools ellipse • 1.1k views
ADD COMMENT
1
Entering edit mode
Kevin Blighe ★ 3.9k
@kevin
Last seen 8 days ago
Republic of Ireland

Hi,

Please increase the values for xlim and / or ylim.

Kind regards,

Kevin

ADD COMMENT
0
Entering edit mode

Hi kevin many thanks for your answer? How can I found the existing up and lower limit? If I increase these limits instead of NULL, will then the following code work?

biplot(tpp.pca, pointSize = 5, lab = NULL, labSize = 4, colby = 'Group', shape = 'Group', ellipse = TRUE, xlim = NULL, ylim = NULL legendPosition = 'right')

This is my existing graph. I want to have an ellipse around every cluster.

enter image description here

ADD REPLY
0
Entering edit mode

Hi, you can observe the values on the current axes, and then set new limits of greater absolute values via xlim and ylim, and then re-generate the plot.

ADD REPLY

Login before adding your answer.

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