library(dplyr)
##
## 次のパッケージを付け加えます: 'dplyr'
## 以下のオブジェクトは 'package:stats' からマスクされています:
##
## filter, lag
## 以下のオブジェクトは 'package:base' からマスクされています:
##
## intersect, setdiff, setequal, union
library(ggplot2)
library(tidyr)
library(directlabels)
## Warning: パッケージ 'directlabels' はバージョン 4.5.3 の R の下で造られました
library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ forcats 1.0.1 ✔ readr 2.1.5
## ✔ lubridate 1.9.4 ✔ stringr 1.5.2
## ✔ purrr 1.0.4 ✔ tibble 3.3.0
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag() masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(readxl)
library(patchwork)
## Warning: パッケージ 'patchwork' はバージョン 4.5.2 の R の下で造られました
df_toshozasshi <- read_excel(here::here("data\\cleaned\\Ngram\\toshozasshi_首都改造計画_リゾート法.xlsx"))
df_zasshi <- read_excel(here::here("data\\cleaned\\Ngram\\zasshi_首都改造計画_リゾート法.xlsx"))
df_ngram <- df_zasshi
f_read_landprice <- function(file_path){
# データの読み込み -------------------------------------
sheet_names <- excel_sheets(here::here(file_path))
list_df_raw <-
map(sheet_names[2:3], \(n_sheet){
df_ind <- read_excel(
here::here(file_path),
sheet = n_sheet
)
}) |>
setNames(sheet_names[2:3])
# データ整形 ------------------------------------------
list_df_clean <-
list_df_raw %>%
map(\(df){
df %>%
mutate(
id_level = as.numeric(str_sub(`...1`, 1, 2)),
id_region = as.numeric(str_sub(`...1`, 3, 7)),
id_use = as.numeric(str_sub(`...1`, 8, 8)),
id_type = as.numeric(str_sub(`...1`, 9, 9)),
.before = `...1`
) %>%
rename(
id_observation = ...1,
name_region = ...2,
name_use= ...3
) %>%
group_by(id_level, id_region) %>%
fill(name_region, .direction = "down") %>%
ungroup() %>%
slice(-1) %>%
#select(-id_observation) %>%
pivot_longer(
cols = !c(
id_observation,
id_level,
id_region,
id_use,
id_type,
name_region,
name_use
),
names_to = "year",
values_to = "value"
) %>%
mutate(
value = as.numeric(value)
)
})
# 和暦の修正 ------------------------------------------
list_df_analytic <-
list_df_clean %>%
map(\(df) {
df %>%
mutate(
gengo = str_sub(year, 1, 2),
wareki = str_sub(year, 3),
.after = id_use
) %>%
mutate(
wareki = str_replace(wareki, "元", "1"),
wareki = as.numeric(str_remove(wareki, "年")),
year = case_when(
gengo == "昭和" ~ wareki + 1925,
gengo == "平成" ~ wareki + 1988,
gengo == "令和" ~ wareki + 2018,
TRUE ~ NA_real_
)
)
})
# 戻り値 ---------------------------------------------
list(
raw = list_df_raw,
analytic = list_df_analytic
)
}
df_both_Ngram <- bind_rows(
df_toshozasshi %>% mutate(source = "図書+雑誌"),
df_zasshi %>% mutate(source = "雑誌")
) |>
rename(
year = "Keyword"
) |>
pivot_longer(
cols = c("首都改造計画", "リゾート法", "総合保養地域保護法"),
names_to = "word",
values_to = "value"
)
df_ngram_long <- df_zasshi |>
rename(year = Keyword) |>
pivot_longer(
cols = c(
"首都改造計画",
"リゾート法",
"総合保養地域保護法"
),
names_to = "word",
values_to = "frequency"
)
# 基準化
df_ngram_long <- df_ngram_long |>
group_by(word) |>
mutate(
index_1987 = frequency / frequency[year == 1987],
index_1980 = frequency / frequency[year == 1980],
index_1985 = frequency / frequency[year == 1985]
)
list_todofuken <- f_read_landprice(
"data/raw/land_price_todofukenchika.xlsx"
)
## New names:
## New names:
## • `` -> `...1`
## • `` -> `...2`
## • `` -> `...3`
list_kojichika <- f_read_landprice(
"data/raw/land_price_kojichika.xlsx"
)
## New names:
## New names:
## • `` -> `...1`
## • `` -> `...2`
## • `` -> `...3`
# 基準化
list_kojichika[["analytic"]][["価格推移表"]] <- list_kojichika[["analytic"]][["価格推移表"]] |>
group_by(id_observation) |>
mutate(
index_1980 = value / value[year == 1980],
index_1987 = value / value[year == 1987]
)
df_both_Ngram |> filter(
year >= 1975,
year <= 2000,
word == "首都改造計画"
) |>
ggplot(
aes(
x = year,
y = value,
color = source
)
) +
geom_line() +
labs(title = "「首都改造計画」の出現頻度") +
geom_point()
# 単語別出現頻度
plot_ngram <- df_ngram_long |> filter(
year >= 1975,
year <= 2000
) |>
ggplot(
aes(
x = year,
y = frequency,
color =word
)
) +
geom_line() +
labs(title = "単語別出現頻度")
plot_ngram
list_kojichika[["analytic"]][["変動率推移表"]] %>%
filter(id_level == 4, id_region == 13000, id_use == 7, id_type == 2) %>%
filter(year >= 1980, year <= 1996) |>
ggplot(aes(x = year, y = value)) +
geom_line() +
geom_point() +
theme_classic()
list_kojichika[["analytic"]][["変動率推移表"]] |>
filter(
id_level == 02,
id_use == 7
) |>
ggplot(
aes(
x = year,
y = value,
color = name_region
)
) +
labs(
title = "圏域別地価変動率の推移"
) +
geom_line() +
geom_point()
list_kojichika[["analytic"]][["価格推移表"]] |>
filter(
id_level == 02,
id_use == 7
) |>
ggplot(
aes(
x = year,
y = value,
color = name_region
)
) +
labs(
title = "圏域別地価変動の推移"
) +
geom_line() +
geom_point()
plot_tokyoken_chihoken_rate <- list_kojichika[["analytic"]][["変動率推移表"]] |>
filter(
id_level == 02,
id_use == 7,
id_region %in% c(01000, 03500),
year >= 1975,
year <= 2000
) |>
ggplot(
aes(
x = year,
y = value,
color = name_region
)
) +
labs(
title = "東京圏・地方圏 地価変動率の推移"
) +
geom_line()
plot_tokyoken_chihoken_rate
list_kojichika[["analytic"]][["価格推移表"]] |>
filter(
id_level == 02,
id_use == 7,
id_region %in% c(01000, 03500),
year >= 1975,
year <= 2000
) |>
ggplot(
aes(
x = year,
y = value,
color = name_region
)
) +
labs(
title = "東京圏・地方圏 地価変動の推移"
) +
geom_line() +
geom_point()
list_kojichika[["analytic"]][["変動率推移表"]] |>
filter(
id_level == 2,
id_region ==03000,
year >= 1975,
year <= 2000
) |>
ggplot(
aes(
x = year,
y = value,
color = name_use
)
) +
labs(
title = "名古屋圏 用途別 地価変動率の推移"
) +
geom_line() +
geom_point()
ggplot() +
geom_line(
data = df_ngram_long |>
filter(
year >= 1975,
year <= 2000
),
aes(
x = year,
y = frequency,
color = word
)
) +
geom_line(
data = list_kojichika[["analytic"]][["変動率推移表"]] |>
filter(
id_level == 02,
id_use == 7,
id_region %in% c(01000, 03500),
year >= 1975,
year <= 2000
),
aes(
x = year,
y = value,
color = name_region
)
) +
scale_y_continuous(
name = "Ngram頻度",
sec.axis = sec_axis(
~ . / 35,
name = "地価変動率 (%)"
)
) +
labs(
title = "出現頻度と地価変動率 1980年の値=100",
x = "年"
)
plot_ngram / plot_tokyoken_chihoken_rate +
plot_layout(heights = c(1.4, 1))
ggplot() +
geom_line(
data = df_ngram_long |>
filter(
year >= 1975,
year <= 2000
),
aes(
x = year,
y = index_1987,
color = word
)
) +
geom_line(
data = list_kojichika[["analytic"]][["価格推移表"]] |>
filter(
id_level == 02,
id_use == 7,
id_region %in% c(01000, 03500),
year >= 1975,
year <= 2000
),
aes(
x = year,
y = index_1987,
color = name_region
)
) +
labs(
title = "出現頻度と地価変動 198年の値=100",
x = "年"
)
# 東京圏
plot_syutokaizokeikaku_tokyokenrate <-
ggplot() +
geom_area(
data = df_ngram_long |>
filter(
year >= 1975,
year <= 2000,
word == "首都改造計画"
),
aes(
x = year,
y = index_1980,
color = word,
fill = word
)
) +
geom_line(
data = list_kojichika[["analytic"]][["価格推移表"]] |>
filter(
id_level == 02,
id_use == 7,
id_region == 01000,
year >= 1975,
year <= 2000
),
aes(
x = year,
y = index_1987,
color = name_region
)
) +
scale_fill_manual(
values = c(
"首都改造計画" = "#F4A261"
)
) +
scale_color_manual(
values = c(
"首都改造計画" = "#E76F51",
"東京圏" = "#2A9D8F"
)
) +
theme(
legend.title = element_blank()
)
plot_syutokaizokeikaku_tokyokenrate
# 地方圏
plot_sogohoyochiiki_chihokenrate <-
ggplot() +
geom_area(
data = df_ngram_long |>
filter(
year >= 1975,
year <= 2000,
word == "総合保養地域保護法"
),
aes(
x = year,
y = index_1987,
color = word
)
) +
geom_line(
data = list_kojichika[["analytic"]][["変動率推移表"]] |>
filter(
id_level == 02,
id_use == 7,
id_region == 01000,
year >= 1975,
year <= 2000
),
aes(
x = year,
y = value,
color = name_region
)
)
plot_syutokaizokeikaku_tokyokenrate
# 東京圏
plot_syutokaizo_tokyoken <-
ggplot() +
geom_area(
data = df_ngram_long |>
filter(
year >= 1975,
year <= 2000,
word == "首都改造計画"
),
aes(
x = year,
y = frequency,
color = word,
fill = word
),
alpha = 0.5,
color = NA
) +
geom_line(
data = list_kojichika[["analytic"]][["変動率推移表"]] |>
filter(
id_level == 02,
id_use == 7,
id_region == 01000,
year >= 1975,
year <= 2000
),
aes(
x = year,
y = value,
color = name_region
)
) +
scale_fill_manual(
values = c(
"首都改造計画" = "#F4A261"
)
) +
scale_color_manual(
values = c(
"東京圏" = "#2A9D8F"
)
) +
theme(
legend.title = element_blank()
) +
labs(
title = ""
)
# 東京圏
plot_syutokaizokeikaku_tokyoken <-
ggplot() +
geom_area(
data = df_ngram_long |>
filter(
year >= 1975,
year <= 2000,
word == "首都改造計画"
),
aes(
x = year,
y = frequency,
fill = word
),
alpha = 0.5,
color = NA
) +
geom_line(
data = list_kojichika[["analytic"]][["価格推移表"]] |>
filter(
id_level == 02,
id_use == 7,
id_region == 01000,
year >= 1975,
year <= 2000
),
aes(
x = year,
y = index_1980 * 100,
color = name_region
)
) +
scale_fill_manual(
values = c(
"首都改造計画" = "#F4A261"
)
) +
scale_color_manual(
values = c(
"東京圏" = "#2A9D8F"
)
) +
theme(
legend.title = element_blank()
) +
labs(
title = ""
)
plot_syutokaizokeikaku_tokyoken
# 東京圏
plot_syutokaizokeikaku_tokyoken <-
ggplot() +
geom_area(
data = df_ngram_long |>
filter(
year >= 1975,
year <= 2000,
word == "首都改造計画"
),
aes(
x = year,
y = index_1980,
color = word,
fill = word
),
alpha = 0.5,
color = NA
) +
geom_line(
data = list_kojichika[["analytic"]][["価格推移表"]] |>
filter(
id_level == 02,
id_use == 7,
id_region == 01000,
year >= 1975,
year <= 2000
),
aes(
x = year,
y = index_1987,
color = name_region
)
) +
scale_fill_manual(
values = c(
"首都改造計画" = "#F4A261"
)
) +
scale_color_manual(
values = c(
"東京圏" = "#2A9D8F"
)
) +
theme(
legend.title = element_blank()
) +
labs(
title = ""
)
plot_syutokaizokeikaku_tokyoken
# 地方圏
plot_syutokaizokeikaku_tokyokenrate <-
ggplot() +
geom_area(
data = df_ngram_long |>
filter(
year >= 1975,
year <= 2000,
word == "首都改造計画"
),
aes(
x = year,
y = index_1980,
color = word,
fill = word
),
alpha = 0.5,
color = NA
) +
geom_line(
data = list_kojichika[["analytic"]][["価格推移表"]] |>
filter(
id_level == 02,
id_use == 7,
id_region == 01000,
year >= 1975,
year <= 2000
),
aes(
x = year,
y = index_1987,
color = name_region
)
) +
scale_fill_manual(
values = c(
"首都改造計画" = "#F4A261"
)
) +
scale_color_manual(
values = c(
"東京圏" = "#2A9D8F"
)
) +
theme(
legend.title = element_blank()
) +
labs(
title = ""
)
plot_syutokaizokeikaku_tokyokenrate
# 東京圏
plot_syutokaizokeikaku_tokyokenrate <-
ggplot() +
geom_area(
data = df_ngram_long |>
filter(
year >= 1975,
year <= 2000,
word == "首都改造計画"
),
aes(
x = year,
y = index_1985 * 100,
color = word,
fill = word
),
alpha = 0.5,
color = NA
) +
geom_line(
data = list_kojichika[["analytic"]][["変動率推移表"]] |>
filter(
id_level == 02,
id_use == 7,
id_region == 01000,
year >= 1975,
year <= 2000
),
aes(
x = year,
y = value,
color = name_region
)
) +
scale_fill_manual(
values = c(
"首都改造計画" = "#F4A261"
)
) +
scale_color_manual(
values = c(
"東京圏" = "#2A9D8F"
)
) +
theme(
legend.title = element_blank()
) +
labs(
title = ""
)
plot_syutokaizokeikaku_tokyokenrate