I have an array of data - arr = c(1,2,3,4,5,6,1,2,3,4)
.
I draw a histogram and get the following graph
The frequency of 1,2,3,4 is going to be 2 for each of those numbers, but the graph shows different result — it shows 4 for the bin between 1 and 2. Can someone explain why ?
Also, if I plot the probability density function — how are the y-axis and x-axis values for the density plot calculated ?
Finally, I got the graph as expected with the following code -
h<-hist(x, breaks=10, col="red", xlab="random numbers", + main="Histogram with Normal Curve") xfit<-seq(min(x),max(x),length=40) yfit<-dnorm(xfit,mean=mean(x),sd=sd(x)) yfit <- yfit*diff(h$mids[1:2])*length(x) lines(xfit, yfit, col="blue", lwd=2) xfit