Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Customization of pointshape within function fviz_pca from FactoExtra package

Tags:

r

pca

ggpubr

I have been struggling to make a change on the default point shape that comes in the output plot within the function fviz_pca from the R package FactoExtra.

The plot appears with a certain order* of point shapes which I want to customize.

*The corresponding shapes are respectively 16,17,15,12,0,8

    fviz_pca_biplot(PCA, axes = c(1, 2), 
            label="var", col.var = "black", #setas
            geom = "point", pointsize = 2, col.ind=PCADF$groups, 
            addEllipses = TRUE, ellipse.level = 0.95,
            ellipse.type ="confidence", palette = "aaas") + theme_minimal()

I tried add to the function:

  geom_point(aes(shape = c(19,20,21,22,23,24)))

and it returned me a error message:

Error in geom[1] : object of type 'environment' is not subsettable

Any advice to manage and customize the pointshapes within the function fviz_pca?

like image 620
Juliana Gonçalves Avatar asked May 21 '18 12:05

Juliana Gonçalves


1 Answers

We can use scale_shape_manual() just like with a ggplot2 object:

library(factoextra)

data(iris)
res.pca <- prcomp(iris[, -5],  scale = TRUE)

fviz_pca_ind(res.pca,axes = c(1, 2), 
             label="var", col.var = "black", #setas
             geom = "point", pointsize = 2, col.ind=iris$Species, 
             addEllipses = TRUE, ellipse.level = 0.95,
             ellipse.type ="confidence", palette = "aaas") + theme_minimal()+
  scale_shape_manual(values=c(19,20,21))

enter image description here

like image 180
J.Con Avatar answered Sep 22 '22 17:09

J.Con