Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to combine multiple fviz_pca_biplot into one plot

i tried to combine multiple fviz_pca_biplot (factoextra package) plots into one plot using par(mfrow=c(2,2))
is there any way to create one plot from 4 plots?

new.pca <- prcomp(scaled_new, center=TRUE, scale.=TRUE)

new.k <- new[,4]
fviz_pca_biplot(new.pca, geom = "point", habillage = new.k, repel = "TRUE")

new.k1 <- new[,5]
fviz_pca_biplot(new.pca, geom = "point", habillage = new.k1, repel = "TRUE")

new.k2 <- new[,6]
fviz_pca_biplot(new.pca, geom = "point", habillage = new.k2, repel = "TRUE")

new.k3 <- new[,7]
fviz_pca_biplot(new.pca, geom = "point", habillage = new.k3, repel = "TRUE")

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

fviz_pca_biplot produces a ggplot object, which is drawn with the grid graphics system rather than the base R Graphics system. ~par` has no effect on grid graphics.

If you want to arrange multiple ggplots on a single page, it’s hard to beat the patchwork package. Just store each biplot then use patchwork to arrange them together.

Obviously, we don’t have your data, so I have made some random example plots to demonstrate.

C <- chol(S <- toeplitz(.9 ^ (0:31))) # Cov.matrix and its root
set.seed(17)
X <- matrix(rnorm(32000), 1000, 32)
Z <- X %*% C
new.pca <- prcomp(Z, center=TRUE, scale.=TRUE)

p1 <- fviz_pca_biplot(new.pca, geom = "point", habillage = 'none', repel = TRUE)
p2 <- fviz_pca_biplot(new.pca, geom = "point", habillage = 'none', repel = TRUE)
p3 <- fviz_pca_biplot(new.pca, geom = "point", habillage = 'none', repel = TRUE)
p4 <- fviz_pca_biplot(new.pca, geom = "point", habillage = 'none', repel = TRUE)

library(patchwork)

(p1 + p2) / (p3 + p4)

enter image description here

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading