Looking to have the values of x-axis plotted in the center of the bars in R.
Having issues finding a way to make this possible, code is below:
hist(sample_avg, breaks =7, ylim=c(0,2000),
main = 'Histogram of Sample Average for 1 Coin Flip', xlab= 'Sample Average')
This is just for a coin flip, so I have 6 possible values and want to have 6 buckets with the x-axis tick marks underneath each respective bar.
Any help is much appreciated.
hist()
returns the x coordinate of the midpoints of the bars in the mids
components, so you can do this:
sample_avg <- sample(size=10000,x=seq(1,6),replace=TRUE)
foo <- hist(sample_avg, breaks =7, ylim=c(0,2000),
main = 'Histogram of Sample Average for 1 Coin Flip', xlab= 'Sample Average',
xaxt="n")
axis(side=1,at=foo$mids,labels=seq(1,5))
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