Jorge Mendoza Ruiz
Jorge Mendoza Ruiz

Reputation: 316

Change legend attributes in fviz functions from Factoextra

I am running a PCA in R and ploting the results using fviz functions from Factoextra package. I want to change legend attributes like title and values using this code

    acp<-PCA(params_alpha, scale.unit = TRUE, ncp=5, quali.sup=c(1,2))

    plot1<-fviz_pca_biplot(acp, geom=c("point"), pointsize=1, col.var="black", axes=c(1,2), habillage=2)+
   theme(legend.text = element_text("Lobulo"))

I have two main problems here: first, when I run the code I get this error:

    In grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font family not found in Windows font database  

I tried to solve it using this post Can't change fonts in ggplot/geom_text but it was not effective. The other problem about this code is that legend attributes have not changed at all. enter image description here

I just want to change legend title and values but I don't know how. I´d be so grateful if you can help me.

Upvotes: 6

Views: 9345

Answers (1)

Jorge Mendoza Ruiz
Jorge Mendoza Ruiz

Reputation: 316

I kept researching and could find a solution for the problem. This is the code I used

    plot1<-fviz_pca_biplot(acp, geom.ind="point", pointsize=1, col.var="black", axes=c(1,2), col.ind=params_alpha$lob ,pointshape=19) +
    scale_color_manual(name = "Lobulo", labels = c("Frontal", "Occipital", "Parietal", "Temporal"),
                 values= c("red","blue","orange","forestgreen"))

I also made some changes in order to adjust points shape and color. I hope it is useful for someone else. enter image description here

This link is also useful https://rstudio-pubs-static.s3.amazonaws.com/323416_ab58ad22d9e64ba2831569cf3d14a609.html

Upvotes: 6

Related Questions