Bing Image Creator で生成: Closeup photo of strawberry flowers, background is white mountain, photo
の続きです。
まず、make_date() 関数で year と month から date という名前で日付を表す変数を作成しましょう。
total のグラフを描いてみます。
current, future, level ともに同じような動きをしていることがわかります。
景気ウォッチャー調査のデータの他に株価のデータも加えてみたいと思います。
e-stat.go.jp 政府統計の総合窓口の中から、景気動向指数の中に東証株価指数(TOPIX)のデータがあるので、それをダウンロードしました。
このようにCSVファイルを加工しました。
これを R に読み込みます。
この tpx といデータフレームに date という変数を加えます。
inner_join() 関数で df に tpx を結合させます。
topix のグラフを描いてみます。
TOPIX の推移のグラフができました。
今回は以上です。
次回は
です。
初めから読むには、
です。
今回のコードは以下になります。
#
# year と month から date を作る
df <- df_raw |>
mutate(date = make_date(year, month, 28)) |>
relocate(date)
#
# totalのグラフ
df |>
ggplot(aes(x = date, y = total, group = type)) +
geom_line(aes(color = type))
#
# TOPIXのファイルを読み込む
tpx <- read_csv("topix_202410.csv",
skip = 7)
#
# tpx の整形
tpx <- tpx |>
mutate(date = make_date(year, month, 28)) |>
select(date, topix)
tpx
#
# tpx を df に結合
df <- df |>
inner_join(tpx, by = "date")
df |>
select(date, total, topix)
#
# topix のグラフ
df |>
ggplot(aes(x = date, y = topix)) +
geom_line()
#