从 R 中的条形图中删除线条
Removing lines from barplot in R
我使用 RStudio 为宏基因组数据创建了条形图
plot_bar(mp3, "Sampletype", fill = "Family", title = title)
但是我在 bar.I 中得到线条需要没有任何线条的清晰条。怎么做?
图书馆("phyloseq");包版本("phyloseq")
图书馆("biomformat");包版本("biomformat")
图书馆("ggplot2");包版本("ggplot2")
图书馆("phyloseq");包版本("phyloseq")
图书馆("biomformat");包版本("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
class(树1)
mp2 = merge_phyloseq(mp1, tree1)
mp2
repseqFile = "seqs_rep_set.fasta"
bs1 = Biostrings::readDNAStringSet(repseqFile)
名称(bs1) <- gsub("\s.+$", "", 名称(bs1))
sum(名称(bs1) %in% taxa_names(mp2))
mp3 = merge_phyloseq(mp2, bs1)
plot_bar(mp3, "Sampletype", fill = "Family", title = title)
phyloseq
包中的 plot_bar
使用 ggplot
进行绘图。您可以通过在控制台中键入 plot_bar
来查看 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", 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)
我使用 RStudio 为宏基因组数据创建了条形图
plot_bar(mp3, "Sampletype", fill = "Family", title = title)
但是我在 bar.I 中得到线条需要没有任何线条的清晰条。怎么做?
图书馆("phyloseq");包版本("phyloseq")
图书馆("biomformat");包版本("biomformat")
图书馆("ggplot2");包版本("ggplot2")
图书馆("phyloseq");包版本("phyloseq")
图书馆("biomformat");包版本("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
class(树1)
mp2 = merge_phyloseq(mp1, tree1) mp2 repseqFile = "seqs_rep_set.fasta"
bs1 = Biostrings::readDNAStringSet(repseqFile) 名称(bs1) <- gsub("\s.+$", "", 名称(bs1))
sum(名称(bs1) %in% taxa_names(mp2)) mp3 = merge_phyloseq(mp2, bs1)
plot_bar(mp3, "Sampletype", fill = "Family", title = title)
phyloseq
包中的 plot_bar
使用 ggplot
进行绘图。您可以通过在控制台中键入 plot_bar
来查看 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", 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)