Exact number of bins in Histogram in R

后端 未结 5 1063
Happy的楠姐
Happy的楠姐 2020-12-01 08:24

I\'m having trouble making a histogram in R. The problem is that I tell it to make 5 bins but it makes 4 and I tell to make 5 and it makes 8 of them.

data &l         


        
5条回答
  •  被撕碎了的回忆
    2020-12-01 08:49

    Building on the answer from Rob Hyndman:

    Maybe a more generic solution would be to make the breaks considering the minimun and maximun values of the data, and the number of breaks = number_of_bins+1.

    hist(data,breaks=seq(min(data),max(data),l=number_of_bins+1), 
         freq=FALSE,col="orange",
         main="Histogram",xlab="x",ylab="f(x)",yaxs="i",xaxs="i")
    

提交回复
热议问题