reduce width of bars in multiple barplot R

社会主义新天地 提交于 2020-07-03 06:52:20

问题


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 (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)

Thank you for any suggestions.


回答1:


In help(barplot) there is this paragraph:

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))

With your example:

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



来源:https://stackoverflow.com/questions/50188638/reduce-width-of-bars-in-multiple-barplot-r

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!