canvasXpress 画pca
library(ggplot2)
library(ggrepel)
library(RColorBrewer)
library(ggpubr)
library(plyr)
library(canvasXpress)
a <- read.table('infile.txt',
header = TRUE,
row.names = 1)
data <- t(a)
group <- read.table('groupfile.txt',
header = TRUE)
colnames(group)[1] <- "samplenames"
pca_data <- prcomp(data, scale = TRUE)
screeplot(pca_data, type = "lines")
summary(pca_data)
rownames(pca_data$x)
x_per <- round(summary(pca_data)$importance[2, 1]*100, 1)
y_per <- round(summary(pca_data)$importance[2, 2]*100, 1)
df_sample <- data.frame(samplenames=rownames(pca_data$x), pca_data$x)
colnames(group)[1] <- 'samplenames'
df_sample <- join(df_sample,group, by = "samplenames")
df_sample2 <- smalltools::col_to_rowname(df_sample,1)
canvasXpress(data = df_sample2,
varAnnot = df_sample2,
colorBy = "Group",
fillBy = "Group",
ellipseBy = "Group",
graphType = "Scatter2D",
title = "",
xAxis = list("PC1"),
yAxis = list("PC2"),
setMaxX = 60,
setMinX = -60,
setMaxY = 50,
setMinY = -50,
colorScheme = "GGPlot")
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/1a2591a097d5066bca7687c14a36ab85.jpeg#pic_center)