0

我使用 RStudio 创建了宏基因组数据的条形图

plot_bar(mp3, "Sampletype", fill = "Family", title = title)

但是我在酒吧内得到了线条。我需要没有任何线条的清晰栏。怎么做?

点击下面的情节链接

图书馆(“phyloseq”);packageVersion("phyloseq")

图书馆(“生物格式”);packageVersion("biomformat")

图书馆(“ggplot2”);包版本(“ggplot2”)

图书馆(“phyloseq”);packageVersion("phyloseq")

图书馆(“生物格式”);packageVersion("biomformat")

图书馆(“ggplot2”);包版本(“ggplot2”)

biom1 = biomformat::read_biom(biom_file = "otu_table.json.biom")

mp0 = import_biom(biom1,parseFunction = parse_taxonomy_greengenes)

tax_table(mp0) <- tax_table(mp0)[, 1:7]

treeFile1 = "rep_set.tre"

tree1 = read_tree(treeFile1)

树1

类(树1)

mp2 = merge_phyloseq(mp1, tree1) mp2 repseqFile = "seqs_rep_set.fasta"

bs1 = Biostrings::readDNAStringSet(repseqFile) names(bs1) <- gsub("\s.​​+$", "", names(bs1))

总和(名称(bs1)%in%分类名称(mp2))mp3 = merge_phyloseq(mp2,bs1)

plot_bar(mp3,“样本类型”,填充=“家庭”,标题=标题)

4

1 回答 1

1

plot_bar从用于绘图的phyloseq包中。您可以通过在控制台中键入ggplot来查看代码,这会产生:plot_barplot_bar

function (physeq, x = "Sample", y = "Abundance", fill = NULL, title = NULL, 
          facet_grid = NULL) {
    mdf = psmelt(physeq)
    p = ggplot(mdf, aes_string(x = x, y = y, fill = fill))
    p = p + geom_bar(stat = "identity", position = "stack", color = "black")
    p = p + theme(axis.text.x = element_text(angle = -90, hjust = 0))
    if (!is.null(facet_grid)) {
        p <- p + facet_grid(facet_grid)
    }
    if (!is.null(title)) {
        p <- p + ggtitle(title)
    }
    return(p)
}

如您所见,该函数包含以下语句:

geom_bar(stat = "identity", position = "stack", color = "black")

color="black"争论是导致黑线的原因。这是一个非常基本的条形图,您可以根据以下代码创建自己的函数:

library(phyloseq)

my_plot_bar = function (physeq, x = "Sample", y = "Abundance", fill = NULL, title = NULL, 
                        facet_grid = NULL) {
    mdf = psmelt(physeq)
    p = ggplot(mdf, aes_string(x = x, y = y, fill = fill))
    p = p + geom_bar(stat = "identity", position = "stack")
    p = p + theme(axis.text.x = element_text(angle = -90, hjust = 0))
    if (!is.null(facet_grid)) {
        p <- p + facet_grid(facet_grid)
    }
    if (!is.null(title)) {
        p <- p + ggtitle(title)
    }
    return(p)
}

请注意,唯一的变化是我删除了color="black". 您现在可以运行my_plot_bar而不是plot_bar获得没有黑线的条形图。

my_plot_bar(mp3, "Sampletype", fill = "Family", title = title)
于 2018-01-18T07:07:11.877 回答