PCA
2022-02-02 本文已影响0人
余绕
library(ggpubr)
library(ggthemes)
library(gmodels)
data<- read.csv('Documents.csv',sep = ",",header = T, row.names = 1)
head(data)
## CK_1 CK_2 CK_3 ff_1 ff_2 ff_3 X2_1 X2_2 X2_3
## A1 0.997 0.826 0.963 1.154 1.209 1.251 0.849 0.964 0.785
## A2 0.899 0.933 0.828 1.174 1.197 1.248 0.927 0.870 0.924
## A3 0.956 0.918 0.985 1.102 1.166 1.123 0.942 0.916 0.892
## A4 0.847 0.800 0.879 1.014 1.181 1.073 1.139 1.019 1.047
## A5 0.807 0.860 0.860 1.197 1.132 1.157 0.995 1.008 0.984
## A6 0.802 0.848 0.831 1.181 1.293 1.333 1.017 0.859 0.836
pca.info <- fast.prcomp(data) #计算PCA
head(pca.info$rotation)
PC1 PC2 PC3 PC4 PC5 PC6 PC7 PC8 PC9
## CK_1 -0.2457120 -0.3916791546 -0.184711326 0.25556333 -0.20855518 0.54288907 0.3400128 -0.4720976 0.10036671
## CK_2 -0.2398894 -0.3979242732 0.001259835 -0.33241476 -0.41773793 -0.40334507 0.3048059 0.1126560 -0.48043521
## CK_3 -0.2433020 -0.4086936533 0.197493608 0.07863573 0.61132026 -0.14806624 0.3678744 0.3210061 0.30752843
## ff_1 0.4738034 -0.0073809534 0.484306510 -0.45144249 0.09074063 -0.00211779 0.3169145 -0.4679174 0.09738058
## ff_2 0.4663091 0.0005589496 0.144334086 0.65148767 0.04900114 -0.03443670 0.3033427 0.1083170 -0.47953163
## ff_3 0.4743796 -0.0060860825 -0.615903649 -0.19285910 -0.13489913 0.02689424 0.3756398 0.3213497 0.30838793
pca.data <- data.frame(sample = rownames(pca.info$rotation),
Type = c(rep("ck", 3), rep("FF", 3),rep("x2",3)),
pca.info$rotation)#设置各个分组的样本数
#开始画图
ggscatter(pca.data, x = "PC1", y = "PC2",
color = "Type",
ellipse = T,
size = 2, palette = c("mediumaquamarine", "violet","tomato"), #可以修改点的大小和颜色,颜色代码可以去网上搜索
label = "sample", repel = TRUE, main = "PCA plot") + theme_base()
#可以修改图的名称,label = "sample"用于显示各个点对应的样本名
#由于每个组的点数码太少,所以不能进行eclipse画图(即用圈圈把同一组画在一起)。 Too few points to calculate an ellipse
image.png