Rでヒストグラムはhist()関数を使って描画する。この時与えるデータによりブレーク引数が異なることがわかった。
まず下記がデフォルトのhist()関数のヘルプである。
hist(x, breaks = "Sturges",
freq = NULL, probability = !freq,
include.lowest = TRUE, right = TRUE,
density = NULL, angle = 45, col = NULL, border = NULL,
main = paste("Histogram of" , xname),
xlim = range(breaks), ylim = NULL,
xlab = xname, ylab,
axes = TRUE, plot = TRUE, labels = FALSE,
nclass = NULL, warn.unused = TRUE, ...)
http://stat.ethz.ch/R-manual/R-devel/library/graphics/html/hist.html
次にこちらがDateをヒストグラムで描画するときのヘルプとなる。
## S3 method for class 'POSIXt'
hist(x, breaks, ...,
xlab = deparse(substitute(x)),
plot = TRUE, freq = FALSE,
start.on.monday = TRUE, format)
## S3 method for class 'Date'
hist(x, breaks, ...,
xlab = deparse(substitute(x)),
plot = TRUE, freq = FALSE,
start.on.monday = TRUE, format)
breaksについては以下のように説明している。
breaks |
a vector of cut points or number giving the number of intervals which x is to be cut into or an interval specification, one of "days", "weeks", "months", "quarters" or "years", plus "secs", "mins", "hours" for date-time objects. |
Dateのデータである場合にはbreaksに指定するのは “days”, “weeks”,,,といった期間を意味する文字列である。
同じ関数であってもデータ型により引数も異なることは覚えておいたほうがよい。