R Code for Regional Analysis: Mapping Population and Bus Stops using Open Data with Leaflet 地域分析のためのRコード: 将来推計人口メッシュとバス停配置のLeafletによるインタラクティブ地図可視化(OSM版)

Read full text
Authors: Yasutoshi Moteki
Cited by: 12

Abstract

地域分析のためのRコード: 将来推計人口メッシュとバス停配置のLeafletによるインタラクティブ地図可視化 概要 本リポジトリは、統計的な実績・推計人口(面データ)と公共交通インフラ(点データ)を地図上に重ね合わせ、地域における公共交通の供給状況を客観的に把握・分析するためのRスクリプトを公開するものである。例として、愛知県一宮市の1kmメッシュ人口データとバス停位置データを使用した可視化を行っている。 1. 開発の背景と目的 持続可能な地域公共交通のあり方を検討する際、需要(人口)と供給(インフラ)の実態を科学的に把握することは、実効性のある対話の出発点となる。本スクリプトは、単に効率性を追求するだけでなく、地域のニーズに基づいた柔軟な援助や政策的判断を行うための「科学的な判断材料」を提供することを目的としている。 既存のツールには実務上・研究上の以下のような課題が存在する。 国土交通省「地域公共交通計画に関するツール(現状可視化ツール)」との比較: 強力な分析機能を備えているが、利用には自治体関係者等のID発行が必要であり、研究者や市民、あるいは迅速な検証を求める現場担当者が即座にアクセスして分析を開始するにはハードルがある。 国土交通省「現状可視化ツール」 https://mobility-update.mlit.go.jp/support/transport/visualization/ RESAS(地域経済分析システム)との比較: ブラウザ上の操作が煩雑であり、同様の分析を他地域で繰り返したり、将来推計人口(2050年等)と比較したりする際の「分析の再現性」や作業効率に難点がある。 RESAS https://resas.go.jp/ 本スクリプトは、オープンデータとR言語を組み合わせることで、事前のID登録や費用負担といった利用上の障壁を最小化し、高度な再現性を備えた政策科学のための分析環境を提供することを目指している。 2. アイデアの参照と独自性 将来人口メッシュと交通網の重ね合わせという視覚的分析のアイデアについては、以下の先行事例を参考にさせていただいた。 神奈川大学 岩田真一郎氏「コミュニティバス路線上の人口密度の可視化」 https://shinichiro-iwata.github.io/geospatial-data-visualization/community-bus-visualization.html 本スクリプトは、これらの優れたアイデアに基づきつつ、実装面においてはGeminiによるコード支援に基づき、以下の特徴を持つよう独自に作成したものである。 sfおよびtidyverseを用いた現代的で堅牢な地理空間演算ロジック。 leafletを活用した、軽量でインタラクティブなWebマップ形式での出力。 行政区域での切り抜き時に発生しがちな幾何学的エラー(GEOMETRYCOLLECTION等)を、st_collection_extractを用いて自動的に処理・回避する実務的なコード構成。 3. 技術的特長 レイヤー構造の統合:人口規模を暖色系(YlOrRd)、バス停を寒色系(Blue)で配色し、供給の状況を視覚的に明示。 動的な情報表示:マウスオーバー(label機能)により、地図上を操作するだけで特定のポイントのバス停名を即座に確認可能。 将来推計(各年)への対応:用いる人口データの列名(PTN_2015 〜 PTN_2050)を変更するだけで、現在から将来までの変化をシームレスに分析可能。 データの詳細 本解析の基盤として、国土数値情報から提供されている「行政区域」および「バス停留所」の最新シェープファイルを使用し、特定の自治体範囲(例:一宮市)へと空間的な切り抜き処理を行っている。 人口統計データには愛知県を対象とした「1kmメッシュ将来推計人口」を採用しており、2015年の実績値(PTN_2015)から2050年の推計値(PTN_2050)までを包含しているため、時間軸を切り替えた動的な比較分析が可能である。 空間演算の手続きにおいては、行政境界でメッシュを切り抜く際に生じる幾何学的な断片(点や線)を排除するため、st_collection_extract関数を用いてPOLYGON(面)属性のみを厳密に抽出している。 可視化のインターフェースにはLeafletを採用しており、人口規模に応じた階級区分図(Choropleth Map)の上にバス停位置を重畳させることで、供給の過不足を科学的に検証できる構造を実現している。 分析用のデータ入手先 本分析には、国土数値情報ダウンロードサイトから取得した以下のデータを使用する。 行政区域データ (N03) https://nlftp.mlit.go.jp/ksj/gml/datalist/KsjTmplt-N03-v3_1.html バス停留所データ (P11) https://nlftp.mlit.go.jp/ksj/gml/datalist/KsjTmplt-P11-2022.html 将来推計人口メッシュデータ https://nlftp.mlit.go.jp/ksj/gml/datalist/KsjTmplt-mesh1000h30.html ※「愛知県」を選択し、1km_mesh_suikei_2018_shape_23.zip をダウンロードすること。 【実行手順と注意点】 上記URLより対象地域(例:愛知県)のデータをそれぞれダウンロードする。 ダウンロードしたZIPファイルを解凍し、構成ファイル(N03-20_23_200101.shp、P11-22_23.shp、1km_mesh_2018_23.shp など)をRの作業フォルダに配置する。 スクリプト内のファイル名が、実際のダウンロードファイル名と一致しているか確認して実行する。 実行結果の地図は、RStudio内の「Viewer」タブ(またはデフォルトのWebブラウザ)に出力される。 ※本ページでの出力例は愛知県一宮市である。背景地図にはOpenStreetMapを用いている。 Rコードのカスタマイズ(将来推計への対応) 本資料に同梱されているRコードは、初期設定として「2015年の男女計・総数人口」を示す PTN_2015 を描画するように指定している。分析の目的に応じて、Rコード中の PTN_2015 と記述されている箇所を、データ定義書にある他のフィールド名に変更することで、特定の年齢階級や将来推計など、別の区分をシームレスに可視化することが可能である。 高齢者人口(65歳以上): PTN_2015 を PTC_2015 に変更。 年少人口(0〜14歳): PTN_2015 を PTA_2015 に変更。 2050年の将来推計人口(総数): PTN_2015 を PTN_2050 に変更。 地図タイルのカスタマイズ:国土地理院地図への対応 本スクリプト(レコード 20016119)に含まれるRツールにおいても、Leafletの機能を活用することで、背景地図をデフォルトのOpenStreetMapから国土地理院地図(地理院地図)へと容易に切り替えることが可能である。特に人口メッシュやバス停の分布を重ねる際、地理院地図の「淡色地図」を用いることで、背景の道路や建物情報の主張を抑え、分析の主眼である「公共交通の空白地帯(Blank Zone)」をより鮮明に特定できるようになる。 【コードの変更例】 スクリプト第4節の addProviderTiles() を、以下のように addTiles() へ書き換えることで地理院地図(淡色地図)を適用できる。 R # 変更前(デフォルトのOpenStreetMap) blank_zone_map % addProviderTiles(providers$OpenStreetMap.Mapnik) %>% # 変更後(地理院地図・淡色地図の指定) blank_zone_map % addTiles( urlTemplate = "https://cyberjapandata.gsi.go.jp/xyz/pale/{z}/{x}/{y}.png", attribution = "地理院地図" ) %>% これにより、行政境界や人口統計データとの視覚的な整合性が高まり、自治体における実務的な政策評価資料としての説得力が向上する。この部分を反映した別バージョン「地理院地図版」も公開している(https://doi.org/10.5281/zenodo.20045301)。 [English] R Code for Regional Analysis: Mapping Population and Bus Stops using Open Data with Leaflet Description This repository provides an R script for overlaying statistical population data (actual and estimated) with public transportation infrastructure. By visualizing the relationship between "demand" (population) and "supply" (bus stops), this tool enables objective analysis of public transport coverage within a region. The provided example visualizes 1km mesh population data and bus stop locations in Ichinomiya City, Aichi Prefecture. 1. Background and Objectives: For Scientific Policy-Making Scientific assessment of the gap between population demand and infrastructure supply is a critical starting point for effective policy dialogue. This script is designed not merely to seek mechanical efficiency but to provide a scientific foundation for nuanced policy judgments, such as determining the need for flexible assistance or subsidies tailored to specific regional requirements. By leveraging Open Data and R, this script aims to provide a highly accessible and reproducible analysis environment for policy science, minimizing barriers such as the need for account registration or financial costs. Current existing tools face several practical and research-related challenges: Comparison with the MLIT "Regional Public Transport Planning: Current Status Visualization Tool": While powerful, this tool requires an ID issued primarily to government officials. This creates a barrier for independent researchers, citizens, or on-site staff who need immediate access to analysis. MLIT Regional Public Transport Planning: Current Status Visualization Tool https://mobility-update.mlit.go.jp/support/transport/visualization/viewer/ Comparison with RESAS (Regional Economy Society Analyzing System): Although RESAS allows for data overlay, its browser-based interface can be cumbersome. It lacks the efficiency and reproducibility required for repeating analyses across different regions or comparing future population estimates (e.g., for the year 2050) through automated workflows. RESAS https://resas.go.jp/ This R-based approach utilizes open data to provide a framework for policy science that is ID-free, accessible, and highly reproducible. 2. References and Originality The concept of overlaying population mesh data with transport networks was inspired by the work of Shinichiro Iwata (Kanagawa University): Shinichiro Iwata, "Community Bus Visualization" https://shinichiro-iwata.github.io/geospatial-data-visualization/community-bus-visualization.html While building upon these conceptual foundations, the implementation of this script was independently developed with the assistance of Gemini, featuring: A modern and robust geospatial processing logic using sf and tidyverse. Interactive web map output utilizing the leaflet package. A practical code structure that automatically handles geometric errors (such as GEOMETRYCOLLECTION issues) during administrative boundary clipping by using st_collection_extract. 3. Key Features Integrated Layer Structure: Uses warm colors (YlOrRd) for population density and cool colors (Blue) for bus stop locations to visually clarify the status of supply. Dynamic Information Display: The mouse-over (label) function enables users to instantly identify specific bus stop names by simply hovering over the map. Support for Future Estimates: By simply changing the target column (e.g., from PTN_2015 to PTN_2050), users can seamlessly analyze shifts from current facts to future projections. Data Definition The analysis utilizes the latest shapefiles for administrative boundaries and bus stop locations provided by the "National Land Numerical Information" service. Population statistics are based on the "1km Mesh Future Population Estimates" for Aichi Prefecture, covering data from 2015 actuals (PTN_2015) to 2050 projections (PTN_2050), enabling dynamic comparative analysis across various time horizons. In the spatial processing workflow, geometric fragments (points or lines) generated during the intersection of meshes with administrative boundaries are filtered using the st_collection_extract function to strictly extract POLYGON attributes. The visualization interface uses the leaflet package to create choropleth maps of population density overlaid with bus stop points, providing a structured way to scientifically verify the status of public transport supply. Data Acquisition and Execution Procedures [Data Sources for Analysis] This analysis utilizes the following datasets from the National Land Numerical Information (NLNI) download site: Administrative Boundary Data (N03) https://nlftp.mlit.go.jp/ksj/gml/datalist/KsjTmplt-N03-v3_1.html Bus Stop Data (P11) https://nlftp.mlit.go.jp/ksj/gml/datalist/KsjTmplt-P11-2022.html Future Population Projection Mesh Data https://nlftp.mlit.go.jp/ksj/gml/datalist/KsjTmplt-mesh1000h30.html Select "Aichi Prefecture" and download 1km_mesh_suikei_2018_shape_23.zip. Execution Procedures and Notes Download the data for the target region (e.g., Aichi Prefecture) from the URLs above. Unzip the downloaded files and place the component files (e.g., N03-20_23_200101.shp, P11-22_23.shp, 1km_mesh_2018_23.shp) into your R working directory. Ensure the filenames in the script match the actual downloaded filenames before execution. The generated map will be output to the "Viewer" tab in RStudio or your default web browser. The example output shown on this page uses Ichinomiya City, Aichi Prefecture. OpenStreetMap is used as the background map. Customizing the R Code (Supporting Future Projections) The provided R code is configured by default to render PTN_2015 (Total Population, Male and Female, for the year 2015). By replacing PTN_2015 in the script with other field names from the Data Definition Document, you can seamlessly visualize different segments such as specific age groups or future projections. Elderly Population (65+): Change PTN_2015

Publication details

Journal / source
Zenodo (CERN European Organization for Nuclear Research)
Publication date
4 May 2026
Language
EN