# Color samples in PCA plot

Hello,

I am using Rstudio for PCA on geochemical data (quanti.var = elements ) and I want to color my points by the sample they refer to.
Could anyone help me, I saw some tutorials onligne but it doesn't work.

Tkank you

We really need a lot more information. See

We really need a lot more information. We need some idea of the data and the code you are using to perform the PCA. See

I see ... here is the script that I used

=> matrice_cor_<-cor(data[,1:10], use = "everything")
=> corrplot(matrice_cor_budget, method = "number", type = "upper")
=> res<-PCA(budget, scale.unit=TRUE, ncp=5, graph = FALSE,quali.sup = c(10:10))
10 being the sample's name column
=> fviz_eig(res, choice = "variance", addlabels = TRUE)
=> corrplot(res[["var"]][["cos2"]],is.corr = FALSE)
[score plot] => plot.PCA(res, axes=c(1, 2), choix="ind", habillage = 10,
label=c("ind", "ind.sup", "quali"),new.plot=TRUE, title="score plot")
here is the probleme , it doesn't take into account the column 10 (samples)
the error displayed ( Error in plot.PCA(res, axes = c(1, 2), choix = "ind", habillage = 1, label = c("ind", :
The variable Echantillon is not quantitative)

My dataset include 9 quantitative variables ( elements : Ca, Fe, Si, Li, Ba ... + Distance from the mineralization) the 10th column represents the sample name for each row ( 400 row by sample).

I am sorry but that is, basically, incomprehensible.

We need clean code, just post the actual code between ```
and supply some sample data

A handy way to supply sample data is to use the dput() function. See ?dput. If you have a very large dataset then something like head(dput(myfile), 100) will likely supply enough data for us to work with.

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

If you have a query related to it or one of the replies, start a new topic and refer back with a link.