跟著 Cell 學(xué)作圖 | 主坐標(biāo)分析(PCoA)及其可視化(vegan)
Title:Targeted suppression of human IBD-associated gut microbiota commensals by phage consortia for treatment of intestinal inflammation
DOI:10.1016/j.cell.2022.07.003
22
本期圖片
Principal coordinate analyses (PCoA), Bray-Curtis dissimilarity, colored according to (E) disease or (F) Kp abundance
原文詳見:https://mp.weixin.qq.com/s/uVBypI7bDS17LCrK80Vesw
# Load package
library(vegan)
library(ggplot2)
library(ggthemes)
# Load data
otu <- read.table('otu.txt',row.names = 1,header = T)
group <- read.table('group.txt',header = T)
# creat data
group$bacteria <- runif(55,0,20)
#pcoa
# vegdist函數(shù)薄声,計算距離;method參數(shù),選擇距離類型
distance <- vegdist(otu, method = 'bray')
# 對加權(quán)距離進(jìn)行PCoA分析
pcoa <- cmdscale(distance, k = (nrow(otu) - 1), eig = TRUE)
## plot data
# 提取樣本點坐標(biāo)
plot_data <- data.frame({pcoa$point})[1:2]
# 提取列名茅坛,便于后面操作恐锣。
plot_data$ID <- rownames(plot_data)
names(plot_data)[1:2] <- c('PCoA1', 'PCoA2')
# eig記錄了PCoA排序結(jié)果中魁袜,主要排序軸的特征值(再除以特征值總和就是各軸的解釋量)
eig = pcoa$eig
#為樣本點坐標(biāo)添加分組信息
plot_data <- merge(plot_data, group, by = 'ID', all.x = TRUE)
head(plot_data)
# figure1
ggplot(data = plot_data, aes(x=PCoA1, y=PCoA2, fill=group)) +
geom_point(shape = 21,color = 'black',size=4) +
scale_fill_manual(values = c('#73bbaf','#d15b64','#592c93'))+
labs(x=paste("PCoA 1 (", format(100 * eig[1] / sum(eig), digits=4), "%)", sep=""),
y=paste("PCoA 2 (", format(100 * eig[2] / sum(eig), digits=4), "%)", sep=""))+
geom_hline(yintercept=0, linetype=4) +
geom_vline(xintercept=0 ,linetype=4)+
theme_few()+
theme(legend.position = c(0.9, 0.2),
legend.title = element_blank(),
legend.background = element_rect(colour ="black"))
ggsave('pcoa1.pdf',width = 4,height = 4)
# figure2
ggplot(data = plot_data, aes(x=PCoA1, y=PCoA2, fill=bacteria)) +
geom_point(shape = 21,color = 'black',size=4) +
scale_fill_gradient(low = '#f2fe32',high = '#180f7c')+
labs(x=paste("PCoA 1 (", format(100 * eig[1] / sum(eig), digits=4), "%)", sep=""),
y=paste("PCoA 2 (", format(100 * eig[2] / sum(eig), digits=4), "%)", sep=""))+
geom_hline(yintercept=0, linetype=4) +
geom_vline(xintercept=0 ,linetype=4)+
theme_few()+
theme(legend.title = element_blank(),
legend.position = c(0.8, 0.15),
legend.direction = "horizontal")
ggsave('pcoa2.pdf',width = 4.5,height = 4)
[圖片上傳失敗...(image-8ca347-1664257358177)]
[圖片上傳失敗...(image-ae566a-1664257358177)]
往期內(nèi)容
- 即將滿員苹丸!CNS圖表復(fù)現(xiàn)|生信分析|R繪圖 資源分享&討論群介劫!(內(nèi)附推文合集)
- 跟著 Nature Communication 學(xué)作圖 | 熱圖+格子注釋(通路富集相關(guān))
- 跟著 Nature Communication 學(xué)作圖 | 百分比堆積柱狀圖+卡方檢驗
- ggbiplot | 帶箭頭的主成分分析(PCA)圖繪制
[圖片上傳失敗...(image-8067ef-1664257358177)]