我有微生物组数据与OTUs鉴定到最低的分类水平可能。一些OTUs被识别为属,另一些被识别为科,订单等。我需要创建一个堆叠的条形图。
我的问题是:
如何为我的数据创建一个具有最佳分类分辨率的条形图?
谢谢!
发布于 2022-05-13 17:16:57
你可以把所有的属,科等,都不到相对丰度的5%归入一个类别。这样,任何低计数的OTUs都会合并成一个类别,从而使您的传奇变得更干净。或者你可以移除你所有的不知名的属,但是最好记录下因为这个原因被移除的百分比或数量,或者读/分类群。
下面是一些示例代码,用于组合小于所需百分比的otus。
plot<-transform_sample_counts(phyloseq.object, function(x) 100 * x/sum(x))
glom <- tax_glom(plot, taxrank = 'class')
glom # should list taxa as phyla
data_glom<- psmelt(glom) # create dataframe from phyloseq object
data_glom$class <- as.character(data_glom$class) #convert to character
#simple way to rename phyla with < 5% abundance
data_glom$class[data_glom$Abundance < 0.05] <- "< 5% abundance"
#Count phyla to set color palette
Count = length(unique(data_glom$class)); Count
unique(data_glom$class) #add into line below
data_glom$class <- factor(data_glom$class, levels = c("class", "class", "class", "class", "< 5% abundance"))
spatial_plot <- ggplot(data_glom, aes(x=Sample, y=Abundance, fill=class)) + facet_grid(~variable, scales = "free")
spatial_plot + geom_bar(aes(), stat="identity", position="stack") + labs (title = "title, x="label", y= "Relative Abundance (%)", ) + scale_fill_manual(values =c("color","color","color","color","etc.")+ theme (legend.position="bottom", plot.title = element_text(hjust=0.5, size=15),axis.text = element_text(size = 15),axis.title = element_text(size = 15), legend.text=element_text(size=12),legend.title = element_text(size=15)) + guides(fill=guide_legend(nrow=4))
https://stackoverflow.com/questions/72078329
复制相似问题