LoginSignup
4
3

More than 5 years have passed since last update.

Rパッケージopenairによるカレンダープロットでの料金可視化

Last updated at Posted at 2017-08-29

openairパッケージ

もともとは大気汚染データの可視化で作成されたパッケージのようですが、
株価の推移やパブリッククラウドの課金データの可視化にも役立ちそうです。
rmarkdownやshinyでレポートの可視化&自動化をやっている方でしたら便利にご利用いただけるかと思います。

利用手順

ドコモの株価を取得しカレンダープロットしてみたいと思います。

パッケージインストールと読み込み

install.packages("openair")
library("openair")

ドコモの株価取得し、データフレームに変換

install.packages("quantmod")
library("quantmod")
docomo <- getSymbols("9432.T",src="yahooj",auto.assign=FALSE, from = "2000-04-01")
docomo_df <- data.frame(date=index(docomo), coredata(docomo))

カレンダープロット

calendarPlot(docomo_df, pollutant = "YJ9432.T.Adjusted")

以下のようにプロットできます。
横のバーが株価を示しており、カレンダーはそれにあわせた株価の色を示しています。
cal1.png

引数で西暦を指定できます。

calendarPlot(docomo_df, pollutant = "YJ9432.T.Adjusted", year = 2017)

cal2.png

バーの色も指定できます。
以下は株価が高ければ赤、安ければ緑。
limits = で株価の範囲指定もしています。

docomo_df %>% calendarPlot(pollutant = "YJ9432.T.Adjusted", year = 2016, cols = c("#ffffff", "#adff2f", "red"), limits = c(3000, 5500))
cal3.png

dataクラスと値さえあれば利用できるのでとても簡単です。

※追記
日本語の列名が入っているとうまく表示されませんね。
Rはここらへんがな~

4
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
3