1

I am running PCA of my data (that consists of 8 groups. The ordering is important for the consistency between figures. However, it seems that fviz_pca_ind() function automatically sorts my groups by alphabetical order, instead of keeping the order from the original data frame.

pca.res <- PCA(df, graph = FALSE)
fviz_pca_ind(pca.res, geom = "point", habillage = sample_info$Diet, addEllipses = TRUE, palette = c("#000000", "#757575", "#70b4d8", "#054784", "#fce119", "#efbb00", "#ef8f00", "#bfbfbf"), title = "Plasma amino acid concentrations")

Basically, I simply need it to keep the group order exactly as it appears in the sample_info$Diet variable that is used for habillage.

Currently, the groups are ordered: high-prot, LeuIle, LNAA,..., WT, Thr. What I need is: WT, LNAA, LeuIle, ..., high-prot.

camille
  • 16,432
  • 18
  • 38
  • 60
WegrzynAB
  • 11
  • 3
  • Please, make a reproducible example. https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example – bbiasi May 25 '19 at 22:53

1 Answers1

0
df$Label <- factor(df$Label , levels=c("WT", "LNAA", "LeuIle"))
pca.plot <- fviz_pca_ind(pca.res,
                       .....
                       col.ind = df$Label,
                       .....
Waldi
  • 39,242
  • 6
  • 30
  • 78
Pedro
  • 1