« The Swimmer: Deconstructing the American Nightmare | Main | 家計調査 »

August 10, 2025

Geminiは、Rのスクリプトを書くことができる。

```{r}
# データの読み込み
fbank_data <- read_csv("data/20250614MEISAI-2.csv")

# グラフ作成に必要なパッケージを読み込みます
library(dplyr)
library(ggplot2)

# 取引日のデータ型をDate型に変換
fbank_data$取引日 <- as.Date(fbank_data$取引日, format = "%Y年%m月%d日)")
```

```{r}
# 月別引き落とし額を集計
monthly_withdrawals <- fbank_data %>%
# 支払金額がNAでない行をフィルタリング
filter(!is.na(支払金額)) %>%
# 取引日から「年月」を抽出して新しい列を作成
mutate(年月 = format(取引日, "%Y-%m")) %>%
# 年月でグループ化し、支払金額の合計を算出
group_by(年月) %>%
summarise(
合計支払金額 = sum(支払金額, na.rm = TRUE)
) %>%
# 年月順に並び替え
arrange(年月)

# 月別引き落とし額の棒グラフを作成
ggplot(monthly_withdrawals, aes(x = 年月, y = 合計支払金額)) +
geom_bar(stat = "identity", fill = "steelblue") +
labs(
title = "月別引き落とし額の推移",
x = "年月",
y = "合計引き落とし額 (円)"
) +
theme_minimal(base_family="HiraKakuProN-W3") +
theme(axis.text.x = element_text(angle = 45, hjust = 1))
```

 

Screenshot-20250901-at-113850

 

標準的な日付形式に素データを変換する必要があるようだったので、これもGeminiに質問してみた。format引数をスクリプトに追加したらうまく動いた。

 

Screenshot-20250810-at-211331

|

« The Swimmer: Deconstructing the American Nightmare | Main | 家計調査 »

g. 情報技術」カテゴリの記事

e. 統計」カテゴリの記事

f. 統計言語R」カテゴリの記事