R Code for Regional Analysis: Interactive Visualization of Future Population Projection Mesh Data with Leaflet 地域分析のためのRコード: 将来推計人口メッシュのLeafletによるインタラクティブ地図可視化

Read full text
Authors: Yasutoshi Moteki
Cited by: 2
References: 1

Abstract

地域分析のためのRコード: 将来推計人口メッシュのleafletによるインタラクティブ地図可視化 概要(Description) 将来推計人口メッシュデータを1km単位の高解像度で可視化し、地域の未来予測を視覚的に把握可能にすることを主目的とする。jpmeshパッケージ等の仕様変更に左右されにくいよう、シェープファイルを直接読み込む実装を採用しており、解析の再現性と長期的な安定性を重視している。わずか数十行の極めて簡潔なコードで構成されているため、プログラミングの習熟度を問わず、内容の理解や他データへの応用が容易である。専門的なGISソフトを介さずRのみで完結するため、証拠に基づく政策立案(EBPM)や住民参加型GIS(PPGIS)の現場における実用的な分析テンプレートとして機能する。なお、RESAS(地域経済分析システム)等のウェブサイトでも将来推計人口メッシュの閲覧は可能であるが、本スクリプトのようにRコードを用いる利点は、分析プロセスの完全な再現性が担保されること、および手元で元データを直接保管・管理し、必要に応じて高度な加工が可能である点にある。 背景と謝辞 本スクリプトは、以下の書籍で紹介されているメッシュデータ可視化の考え方に着想を得て作成したものである。 書誌情報:藤井亮輔・鈴木康司 (2025). 『超入門!Rでできるビジュアル統計学:学会・論文発表に役立つデータ可視化マニュアル』 (第2版). 金芳堂. 同書は、Rを用いた統計可視化の基礎から応用までを網羅した非常に優れたガイドである。 本スクリプトの目的と経緯 同書のコードをベースとしつつ、パッケージの仕様変更への対応として jpmesh パッケージを利用せず、よりインタラクティブなWeb地図(Leaflet)の表示を実装した代替スクリプトとして開発した。 当初、同書のコードはパッケージのアップデートによりそのままでは動作しない状態であったが、筆者の問い合わせを経て、現在は発行元のサイトに修正コードが掲載されている。本スクリプトは、その解決のプロセスにおいて独自に生成AI(Gemini)のコード支援を受け、Leafletパッケージを用いたインタラクティブな実装として構築したものである。本スクリプト含め、南山大学のゼミ(プロジェクト研究)で地域分析に必要なコードやオープンデータの分析方法をLMSにアップロードして、ゼミ生に共有している。本コードはその一つを精査し、背景・関連情報含め整理し、公開するものである。 分析用のデータ入手先 国土数値情報ダウンロードサイト https://nlftp.mlit.go.jp/ksj/gml/datalist/KsjTmplt-mesh1000h30.html 愛知県を選び、1km_mesh_suikei_2018_shape_23.zipをダウンロードする。 それを解凍し、1km_mesh_2018_23.shpなどの構成ファイルをRの作業フォルダに置く。 Rコードのカスタマイズ(別の区分の描画) 本資料に同梱されているRコードは、初期設定として「2020年の男女計・総数人口」を示す PTN_2020 を描画するように指定している。 分析の目的に応じて、Rコード中の PTN_2020 と記述されている箇所を、データ定義書(https://nlftp.mlit.go.jp/ksj/gml/datalist/mesh500_1000_h30_datalist.pdf)にある他のフィールド名に変更することで、特定の年齢階級や年度の将来推計など、別の区分を可視化することが可能である。 【Rコードの変更例】 高齢者人口(65歳以上)の分布を可視化したい場合 Rコード中の PTN_2020 を PTC_2020 に変更する。 子供人口(0〜14歳)の分布を可視化したい場合 Rコード中の PTN_2020 を PTA_2020 に変更する。 2050年の将来推計人口(総数)を可視化したい場合 Rコード中の PTN_2020 を PTN_2050 に変更する。 【関連リソース(人流データの可視化)】 本スクリプト(シェープファイルを用いた静的な人口推計の可視化)と併せて、地域の短期的な人の動きを捉えるためのツールとして、CSV形式の「1kmメッシュ別人流データ」を外部依存なしで可視化する派生的なコードも公開している。分析の目的に応じて、以下の関連リソースも活用されたい。 関連レコード: R Code for Regional Analysis: Visualizing Open Human Mobility Data with Leaflet DOI: https://doi.org/10.5281/zenodo.19976728 [English] R Code for Regional Analysis: Interactive Visualization of Future Population Projection Mesh Data with Leaflet Description The primary objective of this script is to visualize future population projection mesh data at a high resolution of 1km, enabling a visual understanding of regional forecasts. To ensure reproducibility and long-term stability of the analysis, the script adopts a method of direct shapefile loading, making it less susceptible to specification changes in packages such as jpmesh. Comprising only a few dozen lines, the code is extremely concise, making it easy to understand and adapt for other datasets regardless of the user's programming proficiency. It functions as a practical analysis template for Evidence-Based Policy Making (EBPM) and Participatory GIS (PPGIS) workshops, as it can be completed entirely within R without the need for specialized GIS software. While future population projection mesh maps are accessible via web platforms such as RESAS (Regional Economy Society Analyzer System), the primary advantages of utilizing R code lie in the guaranteed reproducibility of the analysis process and the ability to locally store, manage, and perform advanced manipulations on the raw data. Background & Acknowledgments This script was inspired by the concepts of mesh data visualization introduced in the following book: Bibliographic Information: Fujii, R., & Suzuki, K. (2025). Cho-nyumon! R de dekiru bijuaru tokeigaku: Gakkai ronbun happyo ni yakudatsu deta kashika manyuaru [Super intro! Visual statistics with R: Data visualization manual for academic and journal presentations] (2nd ed.). Kinpodo. The aforementioned book is an excellent guide covering the basics to applications of statistical visualization using R. Purpose and History of this Script Based on the code from the book, this script was developed as an alternative to implement interactive web map (Leaflet) visualization without relying on the jpmesh package, in response to package specification changes. While the original code in the book temporarily became non-functional due to package updates (a corrected version is now available on the publisher's website following an inquiry), this script was created during that resolution process. It utilizes Leaflet for an interactive implementation, developed with the code assistance of Gemini, a generative AI. This code is part of a series of resources shared via LMS with students in the "Project Research" seminar at Nanzan University to teach regional analysis and open data analysis methods. This specific version has been refined and organized with relevant background information for public release. Data Source for Analysis Data can be obtained from the National Land Numerical Information Download Service: URL: https://nlftp.mlit.go.jp/ksj/gml/datalist/KsjTmplt-mesh1000h30.html Steps: Select "Aichi Prefecture" and download 1km_mesh_suikei_2018_shape_23.zip. Setup: Extract the ZIP file and place the constituent files (including .shp, .shx, .dbf, and .prj) in your R working directory. Customizing the R Code (Visualizing Other Categories) By default, the provided R script is configured to visualize the total population for 2020 (PTN_2020). By changing the PTN_2020 parameter in the R code to other field names listed in the data dictionary (https://nlftp.mlit.go.jp/ksj/gml/datalist/mesh500_1000_h30_datalist.pdf), it is possible to visualize other classifications, such as specific age groups or future population projections for different years. [Examples of Code Modification] To visualize the elderly population (65 years and over): Change PTN_2020 to PTC_2020 in the R code. To visualize the child population (0-14 years): Change PTN_2020 to PTA_2020 in the R code. To visualize the future estimated population for 2050: Change PTN_2020 to PTN_2050 in the R code. [Related Resource: Human Mobility Data (Derivative Script)] Along with this script for static population projection analysis using shapefiles, we have also published a derivative and specialized script for visualizing "1km Mesh Human Mobility Data" from CSV files. This derivative version is further optimized for high portability, implementing coordinate calculations through pure arithmetic without relying on external spatial packages. Please utilize the following related resource depending on your analytical objectives: Title: R Code for Regional Analysis: Visualizing Open Human Mobility Data with Leaflet DOI: https://doi.org/10.5281/zenodo.19976728

Publication details

Journal / source
Zenodo (CERN European Organization for Nuclear Research)
Publication date
27 April 2026