Search code examples
rvisualizationpca

How to plot with fviz_pca_ind() without showing the legend?


I want the legend to disappear. Above is an example of what I did with the iris dataset in R. I could not find a variable in the documentation of fviz_pca_ind() to omit the legend.

library(factoextra)
library(FactoMineR)
pca_iris <- PCA(iris[ ,-5])
iris$species <- as.factor(iris$Species)
pca_n.macros_plot <- fviz_pca_ind(pca_iris, 
             pointshape = 21,habillage = iris$species,
             palette = "jco",label="none",
             geom.ind = c("point"),geom = c("point"),
             title="PCA iris")

Solution

  • As per the documentation of fviz_pca,

    the output class is gg or ggplot. Hence, below code should work for you.

    pca_n.macros_plot + theme(legend.position = "none")