减少多个barplot R中条的宽度 [英] reduce width of bars in multiple barplot R
问题描述
我需要在以下多个条形图中减小条形的宽度:
I need to reduce the width of the bars in the below multiple barplot:
我尝试按照此处更改条形图(R)中的条形图,但似乎使用多个条形图(即,在我的情况下,每个变量4个条形图),功能space
不起作用.
I tried to use the space
option as per here Change width of bars in barchart (R) but it seems that with multiple barplot (i.e. in my case 4 bars per each variable) the function space
does not work.
以下是一些伪造的数据,可以重现该图:
Here's some fake data that reproduce the plot:
mat_example = matrix(rnorm(40), 4, 10)
barplot(mat_example[,c(1:10)], beside = TRUE)
谢谢您的任何建议.
推荐答案
在help(barplot)
中有以下段落:
space:空间量(以平均条形宽度的分数表示) 在每个小节之前离开.可以是一个或一个 每个酒吧的人数. 如果身高"是一个矩阵而身旁"是 "TRUE","space"可以由两个数字指定,其中 首先是同一组中的条形之间的空间, 组之间的间隔第二.如果未给出 明确地,如果"height"是矩阵,则默认为"c(0,1)" 并且旁边"为真",否则为0.2.
space: the amount of space (as a fraction of the average bar width) left before each bar. May be given as a single number or one number per bar. If ‘height’ is a matrix and ‘beside’ is ‘TRUE’, ‘space’ may be specified by two numbers, where the first is the space between bars in the same group, and the second the space between the groups. If not given explicitly, it defaults to ‘c(0,1)’ if ‘height’ is a matrix and ‘beside’ is ‘TRUE’, and to 0.2 otherwise.
因此,在您的情况下,这应该可行:
So in your case this should work:
barplot(table, beside=TRUE, space=c(0, 2))
以您的示例为例:
mat_example <- matrix(rnorm(40), 4, 10)
barplot(mat_example[,c(1:10)], beside=TRUE, space=c(0, 5))
这篇关于减少多个barplot R中条的宽度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!