愿武艺晴小朋友一定得每天都开心
## Identify the 10 most highly variable genes;提取前2000个基因的表达矩阵:
CLP_ProB_PreB <- FindVariableFeatures(CLP_ProB_PreB,selection.method = "vst",nfeatures = 2000)
top2000 <- head(VariableFeatures(CLP_ProB_PreB),2000)
top2000
#画个3D=三维PCA图
library(scatterplot3d)
data <- t(as.data.frame(AverageExpression(CLP_ProB_PreB,features = top2000,group.by =c("celltype","Sample"))))
#data = t(data) # 对数据进行转置,如果想对基因分组则不用转置
# PCA计算#不同记录的PC1~PC4 score数值
pca_result <- prcomp(data,center=TRUE,scale=T)# 一个逻辑值,指示在进行分析之前是否应该将变量缩放到具有单位方差
pca_result$x<-data.frame(pca_result$x)
# 准备样本分组数据文件
rio::export(data[,c(1,2)],"clipboard",row.names=TRUE) ###导出剪贴板
Sample<-rio::import("clipboard",header=TRUE)
# (Options)设置颜色,有几个分组就写几个颜色
colors <- c("blue","red","green","orange")
colors <- colors[as.numeric(as.factor(Sample[,2]))]
# (Options)设置点形状,仅供参考
shape<-c(15,19,9,18,7) #15,19,9,18,7淋系 #13,8,4,12 髓系
shape<-shape[as.numeric(as.factor(Sample[,1]))]
# 计算PC值,并替换列名,用来替换坐标轴上的标签
pVar <- pca_result$sdev^2/sum(pca_r