当数据不是数字时如何创建PCA图

问题描述

我正在尝试使用prcomp和ggbiplot创建PCA图。但是,prcomp要求我的数据框为数字。当我通过as.numeric()将数据框强制转换为数字时,prcomp函数可以工作,但是ggbiplot却不能。相反,我得到下面写的错误代码。我以前从未创建过PCA图。有人可以帮我用这个数据框创建一个吗?

“名称(df.v)

我的代码如下:

as.numeric(df)
pca <- prcomp(pca_df,center = TRUE,scale. = TRUE)
ggbiplot(pca,labels = rownames(pca))

如果尚未安装,则需要ggbiplot软件包。

install.packages("devtools")
library('devtools')
install_github("vqv/ggbiplot")
library(ggbiplot)

我的数据框如下:

structure(list(A = c(500,30,6210,460,120,190,110,60,70,4890,210,1100,170,1200,50,8350,790,2110,90,560,830,700,140,2610,21640,3730,10370,320,750,10620,1130,90),B = c(3830,3610,12320,5440,2040,2860,3810,1820,2710,3540,4730,5650,7260,6080,4070,4050,7170,3500,5020,6310,3100,4580,3360,6300,3680,3420,1190,3160,7550,1920,7900,6000,9040,3750,5300,14380,4330,7280,3690),C = c(660,80,3530,220,160,180,100,12520,970,1050,7130,130,2080,200,710,34780,7200,16980,600,1120,9230,360,130),D = c(1710,4060,1290,1860,1510,1250,3800,1090,4850,1950,3110,2290,2500,1780,1930,2450,3340,1730,1620,1310,650,1650,18880,4200,7920,960,1530,9750,1800,5340,1260),E = c(1790,880,4320,530,620,900,1480,2220,1170,1970,890,7230,820,1720,870,1360,1060,1560,850,260,1080,800,9340,9400,11540,1980,2490,15390,2230,610),F = c(1710,5530,150,13510,2480,290,1890,6850,1370,270,490,570,340,20960,1880,4630,1150,10060,3240,120),G = c(720,20,3590,40,12260,410,6070,2060,240,15870,4720,20270,1030,1270,8760,50),H = c(220,3910,310,250,12550,3950,6110,9650,2250,510,17740,22050,2150,23250,390,230,120)),row.names = c(NA,-41L),class = c("tbl_df","tbl","data.frame"))

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...