Assign colors to different columns in PCA chart.

Hi, I am starting to use this program and I am just beginning to familiarize myself with this language.

My problem is that I have a data matrix with 12 columns, that is, 12 variables and I need to make a PCA graph where each variable has a different color.

With the help of a tutorial I wrote the following code:

datos= Nogal_sequia_pca
attach(Nogal_sequia_pca)
summary(datos)

myPr <- prcomp(datos[1:12], scale = TRUE)
myPr
summary(myPr)
plot(myPr, type = "l")

biplot(myPr, scale = 0)
str(myPr)
myPr$x
datos2 <- cbind(datos, myPr$x[, 1:2])
head(datos2)

install.packages("ggplot2")
library(ggplot2)

Then, the rest of the tutorial does not help me since the graph separates by color according to another column with categorical variables.

I enclose an image with the data matrix. Beforehand thank you very much!

Hi!

To help us help you, could you please prepare a reproducible example (reprex) illustrating your issue? Please have a look at this guide, to see how to create one:

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.