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
  )


}

Ngram

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]
)

グラフ

Ngram

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

  • 雑誌のみと図書+雑誌では出現頻度に差がある
    • 「図書については刊行年代が1960年代まで、雑誌については刊行年代が1990年代までの資料を主に対象としています。」
    • 雑誌のみを使用することとする

地価

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()

  • 工業・調区・宅見(宅地見込地)が1991年がピーク
  • その他(住宅・商業・全用途)は1990年にピーク
  • 準工業のmaxが一番大きい
    • 準工業:市街化区域及びその他の都市計画区域内の準工業地域において、居住用若しくは商業用の建物又は工場等の敷地の用に供されている土地をいう。
    • 準工業地域:主に軽工業の工場等の環境悪化の恐れのない工業の義務の利便を図る地域。危険性、環境悪化が大きい工場のほかは、ほとんど建てられる。  住宅や商店など多様な用途の建物が建てられる  

Ngram+地価

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 = "年"
  )

  • 分かりずらい
    • 首都改造計画と東京圏の地価のmaxが1987以前に来るが、1987=100にしていたら変化が見づらい
# 東京圏

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

value(ngram) × value(率)

# 東京圏

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 = ""
  )

value(ngram) × index(価格)*100

# 東京圏

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

index(ngram) × index(価格)

# 東京圏

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

index(ngram)*100 × value(率)

# 東京圏

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