Johann Horvat Johann Horvat - 8 months ago 65
R Question

Histogram of linear data

I'm doing some experiments on histograms of image data. At a first step I tried to make a linear vector with values from 0 to 255. When printing the histogram of this vector I'd assume that every value would have the same frequency. But the

function returns histograms where 0 has a higher frequency and 255 a lower than other values. Even when choosing a different bin size...

What am I doing wrong?

rampImageData<-rep(rep(0:255, each=4), each=512)
# hist(rampImageData, breaks=256)
# hist(rampImageData, breaks=128)
# hist(rampImageData, breaks=64)
# hist(rampImageData, breaks=32)

enter image description here


It is related to "binning".



"Unexpected" behaviour for a Uniform:

qplot(rampImageData, geom = 'histogram') # default bins = 30 

enter image description here

"Expected" behaviour for a Uniform:

qplot(rampImageData, geom = 'histogram', bins = 1)

enter image description here