# Is there a way to plot individual ellipses with polygon() over a fviz_pca_biplot?

This biplot has got rather polluted with all the confidences ellipses in it:

``````pca <- prcomp(q_agua.active, scale = TRUE)
pontos <- as.factor(q_agua\$LOCAL)

fviz_pca_biplot(pca,
geom.ind = "point",
pointshape = 21,
pointsize = 3,
fill.ind = pontos,
title = "Componentes Principais e Pontos de Coleta",
col.var = "black")+
labs(fill = "Pontos de Coleta",
x = "Dimensão 1 (34,81%)",
y = "Dimensão 2 (21,16%)")
``````

So I studied how to create those ellipses with correlation matrices:

``````tab <- matrix(c(pca\$x[,1], pca\$x[,2]), ncol=2)

cP4 <- cor(tab[37:47,])
cP5 <- cor(tab[48:58,])
``````

Everything works well. But when I add the command to plot it, it returns an error:

``````fviz_pca_biplot(pca,
geom.ind = "point",
pointshape = 21,
pointsize = 3,
fill.ind = pontos,
title = "Componentes Principais e Pontos de Coleta",
col.var = "black")+
labs(fill = "Pontos de Coleta",
x = "Dimensão 1 (34,81%)",
y = "Dimensão 2 (21,16%)")+
polygon(ellipse(cP4*max(abs(pca\$rotation))*1,
centre = colMeans(tab[37:47,]),
level = 0.95))

Error in polygon(ellipse(cP4 * max(abs(pca\$rotation)) * 1, centre = colMeans(tab[37:47,  :
plot.new has not been called yet
``````

Is there a way to make this work, without the need to create the graphics from scratch?
I'm pretty new to this so any idea will help me to learn more.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.