如何在 barplot() 中将条形名称的标签设置为较小的字体?
How make labels for bar names a smaller font size in barplot()?
在下面使用 barplot() 函数:
barplot(
norm_clade_counts[[tax_level]][ok,all],
col = mycols(length(ok)),
las = 2,
names.arg = paste(sample_type[all], sample_name[all])
)
legend(
"bottomleft", bty = "n", pch = 19,
col = mycols(length(ok))[1:length(ok)],
cex = 1, inset = c(1,0),
legend = rownames(clade_counts[[tax_level]])[ok]
)
我得到的条形图看起来像这样,其中条的名称在 window 中不完全可见。如何更改这些标签的字体大小?
您可以通过修改 mar
(边距)图形参数来增加底部边距。
# What are the margins currently?
# The `mar` graphical parameter has the form c(bottom, left, top, right)
# These are the number of (fractional) lines on each side of the plot.
default_margins <- par("mar")
default_margins
#> [1] 5.1 4.1 4.1 2.1
# Make the bottom margin larger
new_margins <- default_margins + c(4, 0, 0, 0)
par(mar = new_margins)
barplot(GNP ~ Year, data = longley, las = 2, xlab = "", ylab = "")
# Reset the margins
par(mar = default_margins)
由 reprex package (v2.0.1)
创建于 2022-03-09
在下面使用 barplot() 函数:
barplot(
norm_clade_counts[[tax_level]][ok,all],
col = mycols(length(ok)),
las = 2,
names.arg = paste(sample_type[all], sample_name[all])
)
legend(
"bottomleft", bty = "n", pch = 19,
col = mycols(length(ok))[1:length(ok)],
cex = 1, inset = c(1,0),
legend = rownames(clade_counts[[tax_level]])[ok]
)
我得到的条形图看起来像这样,其中条的名称在 window 中不完全可见。如何更改这些标签的字体大小?
您可以通过修改 mar
(边距)图形参数来增加底部边距。
# What are the margins currently?
# The `mar` graphical parameter has the form c(bottom, left, top, right)
# These are the number of (fractional) lines on each side of the plot.
default_margins <- par("mar")
default_margins
#> [1] 5.1 4.1 4.1 2.1
# Make the bottom margin larger
new_margins <- default_margins + c(4, 0, 0, 0)
par(mar = new_margins)
barplot(GNP ~ Year, data = longley, las = 2, xlab = "", ylab = "")
# Reset the margins
par(mar = default_margins)
由 reprex package (v2.0.1)
创建于 2022-03-09