SNP PCA 3d图绘制代码_R

rm(list=ls())
library(RColorBrewer)
library(calibrate)
library(genefilter)
library(gplots)
library(rio)
library(ggsci)
library(eoffice)
library(ggplot2)
library(scatterplot3d)
df=import("pca/snp.pca.csv",header=T)
color <-c("#E64B35FF","#4DBBD5FF","#00A087FF","#3C5488FF","#F39B7FFF","#8491B4FF","#B09C85FF")
df$group=factor(df$group)
colors <- color[as.numeric(df$group)]
p=ggplot(data=df,mapping=aes(pc1,pc3))
p=df
pp=scatterplot3d(p[,3:5], color=colors,angle=65, pch=16, axis = TRUE,label.tick.marks = TRUE,xlab="PC1(31.2%)",ylab="PC2(29.6%)",zlab="PC3(22.7%)")
legend("right", legend=levels(p$group), col=c("#E64B35FF","#4DBBD5FF","#00A087FF","#3C5488FF",
                                              "#F39B7FFF","#8491B4FF","#B09C85FF"), pch=16, xpd=T, horiz=F)#
text(pp$xyz.convert(p[,3:5]),labels=p$sample,cex=0.4,col = colors,adj=c(1,-1,font=2))#给散点加文字,adj让文字在点上
topptx(filename = "PCA_plot_3d_with_label.pptx")

参考https://www.jianshu.com/p/3759d2651102

你可能感兴趣的:(SNP PCA 3d图绘制代码_R)