[生信分析-11]3行代码搞定PCA聚类分析

# 下载相关R包
> install.packages("devtools")
> library(devtools)
# 上面是下面的依赖包,只有运行了上述代码,才有以下
> install_github("vqv/ggbiplot")
> library(ggbiplot)
# 设置工作路径到数据存放的文件夹下
> setwd("C:\\Users\\Administrator\\Desktop\\教程文件夹")
# 读数据,数据需要提前整理,大家修改文件名
> df = read.csv("pca.csv", header= T,row.names=1)
# 样本分组,需要大家修改
> group=c(rep("OH",9),rep("OL",9))
# 正式分析代码
> result <- prcomp(df, scale = TRUE)
# 完成PCA分析
# 画落石图
> ggscreeplot(result)
# 作PCA图
> ggbiplot(result, obs.scale = 1, var.scale = 1, groups =group, ellipse = TRUE, circle = TRUE, var.axes = F)
# 美化
> ggbiplot(result, obs.scale = 1, var.scale = 1, groups =group, ellipse = TRUE, circle = TRUE, var.axes = F) + scale_color_brewer(palette = "Set1") + theme(legend.direction = 'horizontal', legend.position = 'top')