跟著 Cell 學作圖 | 主坐標分析(PCoA)及其可視化(vegan)

跟著 Cell 學作圖 | 主坐標分析(PCoA)及其可視化(vegan)

pcoa.jpg

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

本期圖片

Snipaste_2022-09-27_00-52-33.png

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')
# 對加權距離進行PCoA分析
pcoa <- cmdscale(distance, k = (nrow(otu) - 1), eig = TRUE)

## plot data
# 提取樣本點坐標
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

#為樣本點坐標添加分組信息
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)容

  1. 即將滿員!CNS圖表復現(xiàn)|生信分析|R繪圖 資源分享&討論群!(內(nèi)附推文合集)
  2. 跟著 Nature Communication 學作圖 | 熱圖+格子注釋(通路富集相關)
  3. 跟著 Nature Communication 學作圖 | 百分比堆積柱狀圖+卡方檢驗
  4. ggbiplot | 帶箭頭的主成分分析(PCA)圖繪制

[圖片上傳失敗...(image-8067ef-1664257358177)]

?著作權歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

相關閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容