I have this bar graph in MATLAB, created using the bar
command:
I was wondering if there is any way to get rid of empty spaces between 2478 and 2886, and between 4314 and 5130
If I can get the bars to have an equal amount of space in between them that would be perfect.
A standard bar chart should have gaps between bars that are slightly narrower than the bars. The exceptions to this are the exception of histograms and clustered bar charts.
If we want to change the thickness of the bars then size argument under geom_bar function of ggplot2 package can be used and it can be set according to our need starting from 1.
As described in the documentation of bar
,
bar(x,y)
draws the bars at the locations specified byx
.
which means that this behavior is intended: Each bar is drawn at the exact position specified by x
.
To get equally spaced bars, you can use the categorical
function, which converts x
to a data type which is intended for discrete categories.
That way, you tell MATLAB that x
is not a numerical vector where x(i)
is the x
-coordinate of the i
-th element, but rather a simple label for that value.
bar(categorical(x), y)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With