简体   繁体   English

减少多个条形图 R 中条的宽度

[英]reduce width of bars in multiple barplot R

I need to reduce the width of the bars in the below multiple barplot:我需要减少下面多个条形图中条形的宽度:

在此处输入图片说明

I tried to use the space option as per here Change width of bars in barchart (R) but it seems that with multiple barplot (ie in my case 4 bars per each variable) the function space does not work.我尝试按照此处使用space选项更改条形图 (R) 中条的宽度,但似乎有多个条形图(即在我的情况下,每个变量有 4 个条)函数space不起作用。

Here's some fake data that reproduce the plot:这是一些重现情节的假数据:

mat_example = matrix(rnorm(40), 4, 10)
barplot(mat_example[,c(1:10)], beside = TRUE)

Thank you for any suggestions.谢谢你的任何建议。

In help(barplot) there is this paragraph:help(barplot)有这一段:

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.如果 'height' 是一个矩阵并且 'beside' 是 'TRUE',则 'space' 可以由两个数字指定,其中第一个是同一组中条形之间的间距,第二个是组之间的间距。 If not given explicitly, it defaults to 'c(0,1)' if 'height' is a matrix and 'beside' is 'TRUE', and to 0.2 otherwise.如果没有明确给出,如果 'height' 是一个矩阵并且 'beside' 是 'TRUE',则默认为 'c(0,1)',否则为 0.2。

So in your case this should work:所以在你的情况下,这应该有效:

barplot(table, beside=TRUE, space=c(0, 2))

With your example:以你的例子:

mat_example <- matrix(rnorm(40), 4, 10)
barplot(mat_example[,c(1:10)], beside=TRUE, space=c(0, 5))

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM