2016-04-25 120 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轴分组为好。