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(
Not as nifty as you might have been hoping, but looks like the best thing is to use axes=F, then put in your own axes with the 'axis' command, specifying the tick marks you want to see.
Reference: https://stat.ethz.ch/pipermail/r-help/2008-June/164271.html
# when dealing with histogram of integers,
# then adding some residual ~ 0.001 will fix it all...
# example:
v = c(-3,5,5,4,10,8,8)
a = min(v)
b = max(v)
foo = hist(v+0.001,breaks=b-a,xaxt="n",col="orange",
panel.first=grid(),main="Histogram of v",xlab="v")
axis(side=1,at=foo$mids,labels=seq(a,b))
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))