r - 如何重新排序 Plot_composition Microbiome 上的结果
问题描述
我得到了一个具有不同门类的情节组合,其他类别如下:
pseq <- Merge_Final_pourcent %>% aggregate_taxa(level = "Phylum")
ps1.com.fam <- microbiome::aggregate_top_taxa(pseq, "Phylum", top = 11)
ps1.com.fam.rel <- microbiome::transform(ps1.com.fam, "compositional")
svg(file="phylum.svg")
plot_composition(ps1.com.fam.rel) + theme(legend.position = "bottom") +
scale_fill_brewer("Phylum", palette = "Paired") + theme_bw() +
theme(axis.text.x = element_text(angle = 90)) +
ggtitle("Relative abundance") + theme(legend.title = element_text(size = 18))
dev.off()
我尝试将类别归为 Other :所以我尝试更改我的 phyloseq 并仅通过 Z_other 转换名称 other 但它也从 phyloseq 对象和情节中消失:
essai<-as.data.frame(tax_table(ps1.com.fam.rel))
essai$unique <- sub("Other", "Z_Other", essai$unique)
essai$Phylum <- sub("Other", "Z_Other", essai$Phylum)
rownames(essai) <- sub("Other", "Z_Other", rownames(essai))
tax_table(ps1.com.fam.rel) <- as.matrix(essai)
essai<-as.data.frame(otu_table(ps1.com.fam.rel))
rownames(otu_table(ps1.com.fam.rel)) <- sub("Other", "Z_Other", rownames(otu_table(ps1.com.fam.rel)))
otu_table(ps1.com.fam.rel) <- as.matrix(essai)
svg(file="0_1phylum_BMP.svg")
plot_composition(ps1.com.fam.rel) + theme(legend.position = "bottom") +
scale_fill_brewer("Phylum", palette = "Paired") + theme_bw() +
theme(axis.text.x = element_text(angle = 90)) +
ggtitle("Relative abundance") + theme(legend.title = element_text(size = 18))
dev.off()
解决方案
我的建议是尝试使用factor
. 也许这可能会有所帮助。
essainoo <- subset(essai, essai$Phylum!="Other")
neworder <- c(unique(essainoo$Phylum),"Other")
essai$Phylum <- factor(essai$Phylum, levels=neworder)
推荐阅读
- r - 使用多个数据框计算列表中的 sumproduct
- python - 我是否可以一次运行两个 python 进程,一个使用珊瑚 tpu,另一个只使用 cpu?
- java - 计算存储库中忽略抑制文件的检查样式错误数
- python - 在通过 Python 运行时维护 Excel 工作簿的 Power Query 连接
- loops - 如何使用行的循环变量实现awk?
- python-3.x - 如何使用包含数字的键对字典进行排序
- r - 如何重新排序R中的行值?
- coldfusion - 使用 getPageContext().getRequest().getParameterValues() 时如何防止 unicode 字符损坏?
- digital-ocean - 是否可以在 python 应用程序平台中安装节点?
- docker - Docker 中的 GitLab 在 chgrp 上失败