运行 R 中数据帧列表上的 PCA
Running PCA on list of dataframes in R
我有个小问题。我有三个数据框,它们的列名彼此相同。我尝试对这三个数据帧使用 lapply 运行 三个不同的 PCA。但是它没有用。我在这里附上了我的代码。感谢任何帮助。
library(factoextra)
library(FactoMineR)
mtcars
listA<-mtcars%>%
nest(-cyl)
listA$data # Here I created 3 list of dataframes based on cylinder capacity
lapply(listA$data,function(x[,1:6]) fviz_pca_biplot(PCA(x), label = "var", # Then tried to run separate PCA for each list; selecting column 1:6 in each dataframe
geom.ind="point",
pointsize=4,
alpha.ind = 0.8,
col.ind =x[[9]], # Here I tried to make color by 'gear type"
col.var = 'black',
select.var = list(contrib=30),
repel=TRUE,
mean.point=FALSE,
#habillage = as.factor(B$Class),
theme_classic()))
我们需要为 theme_classic()
指定参数名称,即 ggtheme
out <- lapply(listA$data,function(x) fviz_pca_biplot(PCA(x[, 1:6]), label = "var", # Then tried to run separate PCA for each list; selecting column 1:6 in each dataframe
geom.ind="point",
pointsize=4,
alpha.ind = 0.8,
col.ind = x[[9]], # Here I tried to make color by 'gear type"
col.var = 'black',
select.var = list(contrib=30),
repel=TRUE,
mean.point=FALSE,
habillage = as.factor(x[[9]]),
ggtheme = theme_classic()))
我有个小问题。我有三个数据框,它们的列名彼此相同。我尝试对这三个数据帧使用 lapply 运行 三个不同的 PCA。但是它没有用。我在这里附上了我的代码。感谢任何帮助。
library(factoextra)
library(FactoMineR)
mtcars
listA<-mtcars%>%
nest(-cyl)
listA$data # Here I created 3 list of dataframes based on cylinder capacity
lapply(listA$data,function(x[,1:6]) fviz_pca_biplot(PCA(x), label = "var", # Then tried to run separate PCA for each list; selecting column 1:6 in each dataframe
geom.ind="point",
pointsize=4,
alpha.ind = 0.8,
col.ind =x[[9]], # Here I tried to make color by 'gear type"
col.var = 'black',
select.var = list(contrib=30),
repel=TRUE,
mean.point=FALSE,
#habillage = as.factor(B$Class),
theme_classic()))
我们需要为 theme_classic()
ggtheme
out <- lapply(listA$data,function(x) fviz_pca_biplot(PCA(x[, 1:6]), label = "var", # Then tried to run separate PCA for each list; selecting column 1:6 in each dataframe
geom.ind="point",
pointsize=4,
alpha.ind = 0.8,
col.ind = x[[9]], # Here I tried to make color by 'gear type"
col.var = 'black',
select.var = list(contrib=30),
repel=TRUE,
mean.point=FALSE,
habillage = as.factor(x[[9]]),
ggtheme = theme_classic()))