Centering Values on Bars in Histogram in R

后端 未结 3 821
感情败类
感情败类 2021-01-12 01:49

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(         


        
3条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-12 02:44

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

提交回复
热议问题