How to change the space between bars in a barplot in R?


By default, the space between bars is equal irrespective of the number of bars in the plot. If we want to have different space between bars then space arguments need to be used inside the barplot function but the first value does not make an impact because the first space is fixed between Y-axis and the first bar. For example, if we have a vector x that contains three values then the barplot with different space between bars can be created by using the below command −

barplot(x,space=c(0.5,0.1,0.5))

Example

 Live Demo

x<-rpois(4,5)
x

Output

[1] 3 8 4 4

Example

barplot(x)

Output

Example

barplot(x,space=c(0.01,0.1,0.5,0.1))

Output

Example

barplot(x,space=c(0.1,0.2,0.2,0.5))

Output

Updated on: 06-Feb-2021

460 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements