My file's name is "aroma."
I want to have a score plot, so I type the below text..
res.pca <- PCA(aroma[,-1], graph = FALSE)
fviz_pca_ind(res.pca, col.ind = "cos2",
gradient.cols = c("#00AFBB", "#E7B800", "#FC4E07"),
repel = TRUE # Avoid text overlapping (slow if many points)
)
The result comes out like this. The sample names are named by 1,2,3,4.....which I don't expect.
Hi @Blueberry,
Welcome to the RStudio Community Forum.
This type of PCA plot uses the row names of the dataframe to label the plots. I cannot find any other way to specify them. In your case the row names are simply numbers from 1:nrow(aroma). So, try altering your dataframe like this before analysis and plotting:
row.names(aroma) <- aroma[, 1] # Copy first column of dataframe to row names
p.s. In future it is best to tell us which packages you are using. There are 12 packages which have a function PCA()!
library(psych)
library("FactoMineR")
library("factoextra")
library(missMDA)
aroma<-read.csv(file="GCMS_overview.csv",header = TRUE)
nb <- estim_ncpPCA(aroma,method.cv = "Kfold", verbose = FALSE)
Error in estim_ncpPCA(aroma, method.cv = "Kfold", verbose = FALSE) :
The following variables are not quantitative: Aroma.Compounds
The following variables are not quantitative: Fl1
The following variables are not quantitative: Fl2
The following variables are not quantitative: Fl3
The following variables are not quantitative: Fl4
The following variables are not quantitative: Fl5
The following variables are not quantitative: Fl6
The following variables are not quantitative: Fl7
The following variables are not quantitative: Fl8
The following variables are not quantitative: Fl9
The following variables are not quantitative: Fl10
The following variables are not quantitative: Fl11
The following variables are not quantitative: Fl12
The following variables are not quantitative: Fl13
The following variables are not quantitative: Fl14
The following variables are not quantitative: Fl15
The following variables are not quantitative: Fr1
The following variables are not quantitative: Fr2
The following variables are not quantitative: Fr3
Hi @Blueberry,
The error messages are telling you that all your columns are "not numeric" which means that they have probably been read in as "text" ("character"). Its hard to fix this without having a copy of your data file or a pasted copy of the dataframe aroma (screen shots are not suitable).
str(aroma) will show you the type of the various columns.
A few things to consider:
How have missing values been coded in your .csv file?
Are zero values actually "missing values"? If so, they will need to be converted to NA.
Do some columns have all missing values or all zeros? If so, those columns will contribute nothing to a PCA analysis; remove them from the dataframe before proceeding.
Text columns will need converting to numeric.
If these ideas are pretty new to you, its probably time to read a basic R primer (there are many free resources online).