科学の箱

科学・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でのラインの表示

Rでラインを引くために関数がいくつか用意されている。 abline() 画像全体に線を引く segments() 始点と終点を指定してその間に線を引く points() “点” …

no image

条件付きでレコードを取得する

データフレームでは条件付きでレコードを取得できる。 以下のようなフォーマットのデータフレームを考える id name height vector1 <- c(1, 2, 3, 4, 5) vec …

no image

Rに関するmemo

グループ毎に度数分布を作成する by(housing$VAL, housing$SERIALNO, length) グループで平均値を計算するための式 DT[,mean(pwgtp15),by=SEX …

no image

rvestで読み込むcssを調べる方法

rvestで対象とするhtmlのブロックは下記のように取得できる。 http://blog.rstudio.com/2014/11/24/rvest-easy-web-scraping-with-r/ …

no image

Rによるやさしい統計学/5-統計的検定-2

練習問題-2 勉強時間と定期試験の点数についてデータを作成する。 study_time <- c(1, 3, 10, 12, 6, 3, 8, 4, 1, 5) point <- c(20 …

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

side bar top



アーカイブ

カテゴリー