Thanks go also to Dunlap, Blais and Duchesne.
I am forwarding the last email of Bill D., since it has an interesting
information
on the hist.factor function.
Aldi
On Thu, 24 Oct 2002, Aldi Kraja wrote:
y <- sample(1:max1, size = n, replace = T)
hist(y, main = "The rolling die", probability = T)
In addition, you may prefer hist.factor() for
discrete data. It makes one bar for each value
seen in the data, never lumping adjacent values
together. It can be fooled by integer data that
is missing some intermediate values, like
hist.factor(c(1,2,14,15))
If you want to ensure that all possible values
are in the plot, change your data into a factor
with the desired levels (in which case hist()
will call hist.factor()):
hist(factor(c(1,2,14,15), levels=1:15))
For a six sided die you won't notice the difference
because no lumping takes place. For a 10 sided die
with not many samples you will:
hist(sample(10, replace=T, size=10)) # 4 bars
hist(factor(sample(10, replace=T, size=10), levels=1:10)) # 10 bars,
some empty
|