Objective: to practice PCA analysis with prcomp function
data set: R comes with iris data set
error reporting content: when removing the “species” column in Iris data set with data frame index, errors are always reported, as follows:
> iris_data <- [,-5]
Error: Unexpected'[' in "iris_data <- ["
Oh, it’s really a very low-level error. The reason for the error is that the data set is not indicated. After modification, the code is as follows:
iris_data <- iris[,-5]
the second similar problem:
original code:
fviz_pca_ind(iris.pca,
geom.ind = ("point", "text"), # show points only (nbut not "text")
col.ind = iris$Species, # color by groups
palette = c("#00AFBB", "#E7B800", "#FC4E07"),
addEllipses = TRUE, # Concentration ellipses
legend.title = "Groups"
)
report errors:
Error: Unexpected',' in:
"fviz_pca_ind(iris.pca,
geom.ind = ("point","
Modified code: added “C” in front
fviz_pca_ind(iris.pca,
geom.ind = c("point", "text"), # show points only (nbut not "text")
col.ind = iris$Species, # color by groups
palette = c("#00AFBB", "#E7B800", "#FC4E07"),
addEllipses = TRUE, # Concentration ellipses
legend.title = "Groups"
)