First, I cannot use your dataset, since you did not make it available to us. So I made one available down below
First, this is very easily done in the library(FactoMineR)
.
Load data frame
df <- read.table("https://pastebin.com/raw/6aukL6YW", header=T)
library(FactoMineR) # load package
names(df) notice I have one column called "treatment", the others are columns filled with data
Run the PCA
x <- PCA(df,quali.sup=1) # the quali.sup= is referring to "which column do you want to refer to as a category (and each category is automatically assigned a color), in your case, this would be "population"
you can also make a scatterplot with the plot.PCA()
command directly integrated in the FactoMineR package
plot.PCA(x, axes=c(1, 2), cex=1,choix="ind", habillage=1) # habillage is referring the which column you want to treat as a factor, and it also will assign different colors, (again in your case, "population
and this plot automatically adds a legend
Finally, you can make a plot which could tell you which variable is causing the most variation in your data set , again, with plot.PCA()
plot.PCA(x, choix='var',select='contrib 2') # top 2 contributors of variation, the rest are not shown in bold, could do 5, 10, etc..
And there you go...
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…