#来自小明的数据分析笔记
source("D:/R/work/pca_and_ggplot2.R")
getwd()
library(ggplot2)
library(ggpubr)
library(cowplot)
df<-read.csv("D:/R_4_1_0_working_directory/env001/iris.csv")
library(readxl)
df <- read_excel("PCA.xlsx")
df<-read_xlxs
View()
df
#pca.ncg<-.pca(data = df[,c(1,2,3,4)], ##
pca.ncg<-.pca(data = df[,c(1:9)],##
is.log = FALSE)#不对数据进行转化,基因表达量可能会转化数据
.scatter.density.pc(pcs = pca.ncg$sing.val$v[, 1:3], ##几个变量几个主成分,1:3表示展示1-3个主成分
pc.var = pca.ncg$variation,
strokeColor = 'gray30',
strokeSize = .2,
pointSize = 2,
alpha = .6,
title = "昆虫科的主成分分析(PCA)", ##
group.name = "草原类型", # legned name
group=df$classification, #
color=c("red","blue","green","pink")) -> p
pca.ncg<-.pca(data = df[,c(1:9)],##
is.log = FALSE)#不对数据进行转化,基因表达量可能会转化数据
.scatter.density.pc(pcs = pca.ncg$sing.val$v[, 1:3], ##几个变量几个主成分,1:3表示展示1-3个主成分
pc.var = pca.ncg$variation,
strokeColor = 'gray30',
strokeSize = .2,
pointSize = 2,
alpha = .6,
title = "基于昆虫科的主成分分析", ##
group.name = "草原类型", # legned name
group=df$classification, #
color=c("red","blue","green","yellow")) -> p
do.call(
gridExtra::grid.arrange,
c(p,ncol=4,nrow=1))
png(filename = "PCA322.png",width = 3560,
height = 3000,units = "px",bg="white",res=300)#创作画布
do.call(
gridExtra::grid.arrange,
c(p,ncol=4,nrow=1))#拓印画布
dev.off()
do.call(
gridExtra::grid.arrange,
c(p,ncol=2,nrow=2))
.scatter.density.pc(pcs = pca.ncg$sing.val$v[, 1:2], ##
pc.var = pca.ncg$variation,
strokeColor = 'gray30',
strokeSize = .2,
pointSize = 2,
alpha = .6,
title = "A", ##
group.name = "B", # legned name
group=df$classification, #
color=c("red","blue","green")) -> p1
do.call(
gridExtra::grid.arrange,
c(p1,ncol=2))