2016-04-25 119 views
0

我使用名爲「phyloseq」的這個R軟件包來分析生物信息數據。Phyloseq生成的堆棧欄

otumat = matrix(sample(1:100, 100, replace = TRUE), nrow = 10, ncol = 10) 
otumat 

rownames(otumat) <- paste0("OTU", 1:nrow(otumat)) 
colnames(otumat) <- paste0("Sample", 1:ncol(otumat)) 
otumat 

taxmat = matrix(sample(letters, 70, replace = TRUE), nrow = nrow(otumat), ncol = 7) 
rownames(taxmat) <- rownames(otumat) 
colnames(taxmat) <- c("Domain", "Phylum", "Class", "Order", "Family", "Genus", 
         "Species") 
taxmat 

library("phyloseq") 
OTU = otu_table(otumat, taxa_are_rows = TRUE) 
TAX = tax_table(taxmat) 
OTU 
TAX 

physeq = phyloseq(OTU, TAX) 
physeq 

plot_bar(physeq, fill = "Family") 

所以生成的條形圖不會將同一個家族堆疊在一起。例如,樣本10中有兩個獨立的「I」塊。我使用ggplot2知道phyloseq plot圖。是否有人知道我可以添加到lot_bar(physeq,fill =「Family」)中的ggplot2關聯代碼將同一個家族堆疊在一起嗎?

enter image description here

回答

0

您需要重新排序被用於x軸的因素的水平。 physeq大概有一個名爲「Sample」的列(沒有安裝相關軟件包),您需要重新排列這個級別。

應該可以使用如下命令

physeq$Sample <- factor(physeq$Sample, levels = paste0("Sample", 1:10)) 

那麼就應該正確打印。

您可能需要挖掘,找到相關部分改變

0

事實上,對於中,​​功能確實已經在做什麼你問:

# preliminaries 
rm(list = ls()) 
library("phyloseq"); packageVersion("phyloseq") 
data("GlobalPatterns") 
gp.ch = subset_taxa(GlobalPatterns, Phylum == "Chlamydiae") 
# the function call that does what you're asking for 
plot_bar(gp.ch, fill = "Family") 

請參閱以下幫助教程有關詳情,範例:

https://joey711.github.io/phyloseq/plot_bar-examples.html

你也可以指定x軸分組爲好。