科学の箱

科学・IT・登山の話題

R

Rで日付データをhistgramで表示するときのポイント

投稿日:

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”,,,といった期間を意味する文字列である。

同じ関数であってもデータ型により引数も異なることは覚えておいたほうがよい。

メタ情報

inarticle



メタ情報

inarticle



-R
-

執筆者:


comment

メールアドレスが公開されることはありません。 * が付いている欄は必須項目です

関連記事

no image

Rでグラフを作成するときに参考にするサイト

金子 邦彦 研究室 Web ページ バイオスタティスティクス 奥村 晴彦研究室 Related posts:Rでのラインの表示サンプルサイズによる有意の違いRで日付データをhistgramで表示すると …

no image

大気汚染データの観測

コーセラのDeveloping Data Productで知りたい場所の緯度経度を入力すると過去の観測データからオゾン濃度とPM25汚染濃度を予測するコードを紹介していた。Video Lectureの …

no image

factorと数値型の変換-2

factorと数値型の変換でとりあえず区切り文字付き数字の変換方法についてめどは立ったが、そもそも区切り文字付き数字がなぜfactorになるのかがわからない。文字列にするにはパラメータを指定する必要が …

no image

Rで型が不明なときの対処方法

データセットならstrを使う > str(iris) ‘data.frame’:   150 obs. of  5 variables:  $ Sepal.Length: num  5.1 4. …

no image

Rでのランダムデータ作成 – 上級編

平均が異なるランダムデータを作成する > x <- rnorm(12, mean=rep(1:3,each=4), sd=0.2) > y <- rnorm(12, mean= …

2014年7月
« 6月   8月 »
 123456
78910111213
14151617181920
21222324252627
28293031  

side bar top



アーカイブ

カテゴリー