| Title: | Japan Maps with Insets for Okinawa and Ogasawara |
|---|---|
| Description: | Provides tools for drawing maps of Japan with prefecture and municipal boundaries. The plotting workflow mirrors the 'usmap' package and includes a transform that moves Okinawa and Ogasawara into visible inset locations. Boundary helpers build local 'GeoPackage' files from Japan's official MLIT N03 administrative area data <https://nlftp.mlit.go.jp/ksj/gml/datalist/KsjTmplt-N03-2024.html>. |
| Authors: | Yusaku Horiuchi [aut, cre] |
| Maintainer: | Yusaku Horiuchi <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.1.3 |
| Built: | 2026-07-04 10:14:02 UTC |
| Source: | https://github.com/yhoriuchi/jpmap |
Returns cartographic island/reef shapes for disputed territories or disputed maritime/EEZ-status areas discussed in Japan territorial-dispute references. These geometries are intentionally separate from the MLIT N03 administrative boundary data and are not authoritative legal boundary polygons.
jp_disputed_territories( territorial_disputes = TRUE, regions = c("prefectures", "prefecture", "municipalities", "municipality"), inset = TRUE, okinawa = TRUE, ogasawara = TRUE )jp_disputed_territories( territorial_disputes = TRUE, regions = c("prefectures", "prefecture", "municipalities", "municipality"), inset = TRUE, okinawa = TRUE, ogasawara = TRUE )
territorial_disputes |
Which disputed-territory shapes to include.
Use |
regions |
Boundary level whose columns should be mirrored: prefectures or municipalities. |
inset |
Inset behavior. Use |
okinawa |
Whether Okinawa should be moved when |
ogasawara |
Whether Ogasawara should be moved when |
An sf data frame.
Territory list based on https://en.wikipedia.org/wiki/Territorial_disputes_of_Japan. Shapes are derived from Natural Earth 1:10m land polygons and OpenStreetMap geometry.
jp_disputed_territories() jp_disputed_territories(c("senkaku", "takeshima"))jp_disputed_territories() jp_disputed_territories(c("senkaku", "takeshima"))
Reads Japan administrative boundary data and returns an sf object.
jp_map( regions = c("prefectures", "prefecture", "municipalities", "municipality"), include = c(), exclude = c(), data_year = NULL, inset = TRUE, okinawa = TRUE, ogasawara = TRUE, territorial_disputes = TRUE, data_dir = NULL )jp_map( regions = c("prefectures", "prefecture", "municipalities", "municipality"), include = c(), exclude = c(), data_year = NULL, inset = TRUE, okinawa = TRUE, ogasawara = TRUE, territorial_disputes = TRUE, data_dir = NULL )
regions |
Boundary level: prefectures or municipalities. |
include |
Regions to include by code, English name, or Japanese name. |
exclude |
Regions to exclude by code, English name, or Japanese name. |
data_year |
Boundary data year. The newest appropriate available file is used by default. For example, national prefecture maps prefer a national file, while one-prefecture municipal requests can use a matching prefecture file. |
inset |
Inset behavior. Use |
okinawa |
Whether Okinawa should be moved when |
ogasawara |
Whether Ogasawara should be moved when |
territorial_disputes |
Whether to include disputed-territory island/reef
shapes. Use |
data_dir |
Optional directory containing |
An sf data frame.
if (nrow(available_jpmap_data()) > 0) { jp_map("prefectures") jp_map("prefectures", okinawa = FALSE) jp_map("prefectures", territorial_disputes = FALSE) jp_map("municipalities", include = "Okinawa") jp_map("prefecture") jp_map("municipality", include = "Okinawa") }if (nrow(available_jpmap_data()) > 0) { jp_map("prefectures") jp_map("prefectures", okinawa = FALSE) jp_map("prefectures", territorial_disputes = FALSE) jp_map("municipalities", include = "Okinawa") jp_map("prefecture") jp_map("municipality", include = "Okinawa") }
jp_map_join() attaches columns from a user data frame to an sf
object returned by jp_map(). It is designed for common Japan-map keys,
including pref_code, jis_code, and municipality_code, and
keeps leading zeroes from getting in the user's way.
jp_map_join( map, data, by = NULL, values = NULL, unmatched = c("warning", "error", "ignore"), multiple = c("error", "first") )jp_map_join( map, data, by = NULL, values = NULL, unmatched = c("warning", "error", "ignore"), multiple = c("error", "first") )
map |
An |
data |
A data frame with one row per region to join. |
by |
Join column. If |
values |
Optional column expected to exist after joining. This is useful when checking data before passing it to a plotting function. |
unmatched |
What to do when user data rows do not match the map, or map
regions do not receive a data row. One of |
multiple |
What to do when |
An sf object with non-geometry columns from data joined to
map.
if (requireNamespace("dplyr", quietly = TRUE) && nrow(available_jpmap_data()) > 0) { data("jp_prefecture_gdp") gdp <- jp_prefecture_gdp |> dplyr::select(pref_code, gdp_per_capita_jpy) joined <- jp_map("prefecture") |> jp_map_join(gdp, by = "pref_code") "gdp_per_capita_jpy" %in% names(joined) }if (requireNamespace("dplyr", quietly = TRUE) && nrow(available_jpmap_data()) > 0) { data("jp_prefecture_gdp") gdp <- jp_prefecture_gdp |> dplyr::select(pref_code, gdp_per_capita_jpy) joined <- jp_map("prefecture") |> jp_map_join(gdp, by = "pref_code") "gdp_per_capita_jpy" %in% names(joined) }
jp_map_leaflet() creates a simple interactive web map from jpmap
boundaries. It uses literal longitude/latitude geography because Leaflet web
tiles expect WGS84 coordinates. Use plot_jpmap() when you want the
static Okinawa and Ogasawara inset layout.
jp_map_leaflet( regions = c("prefectures", "prefecture", "municipalities", "municipality"), include = c(), exclude = c(), data = data.frame(), values = NULL, by = NULL, data_year = NULL, territorial_disputes = TRUE, data_dir = NULL, palette = "Blues", fill = "grey92", color = "grey35", weight = 1, opacity = 1, fill_opacity = 0.75, na_color = "#D9D9D9", label = NULL, popup = NULL, tiles = TRUE, legend = TRUE, fit_bounds = TRUE, simplify_tolerance = NULL, disputed_fill = NULL, disputed_color = NULL, disputed_dots = FALSE, disputed_dot_radius = 5, ... )jp_map_leaflet( regions = c("prefectures", "prefecture", "municipalities", "municipality"), include = c(), exclude = c(), data = data.frame(), values = NULL, by = NULL, data_year = NULL, territorial_disputes = TRUE, data_dir = NULL, palette = "Blues", fill = "grey92", color = "grey35", weight = 1, opacity = 1, fill_opacity = 0.75, na_color = "#D9D9D9", label = NULL, popup = NULL, tiles = TRUE, legend = TRUE, fit_bounds = TRUE, simplify_tolerance = NULL, disputed_fill = NULL, disputed_color = NULL, disputed_dots = FALSE, disputed_dot_radius = 5, ... )
regions |
Boundary level: prefectures or municipalities. |
include |
Regions to include by code, English name, or Japanese name. |
exclude |
Regions to exclude by code, English name, or Japanese name. |
data |
Optional data frame to join to the map before drawing. |
values |
Optional column to use for polygon fill colors. |
by |
Optional join column passed to |
data_year |
Boundary data year. The newest appropriate available file is used by default. |
territorial_disputes |
Whether to include disputed-territory island/reef
shapes. Use |
data_dir |
Optional directory containing |
palette |
Palette name or color vector passed to Leaflet palette functions
when |
fill |
Polygon fill color used when |
color |
Polygon outline color. |
weight |
Polygon outline weight. |
opacity |
Polygon outline opacity. |
fill_opacity |
Polygon fill opacity. |
na_color |
Fill color for missing |
label |
|
popup |
|
tiles |
Whether to add default OpenStreetMap tiles. |
legend |
Whether to add a legend when |
fit_bounds |
Whether to zoom the widget to the map bounds. |
simplify_tolerance |
Optional tolerance passed to |
disputed_fill |
Optional fill color for disputed-territory shapes. When
|
disputed_color |
Optional outline color for disputed-territory shapes. When
|
disputed_dots |
Whether to draw circle markers on disputed-territory shapes. |
disputed_dot_radius |
Radius for disputed-territory circle markers. |
... |
Additional arguments passed to |
A leaflet htmlwidget.
if (requireNamespace("leaflet", quietly = TRUE) && requireNamespace("dplyr", quietly = TRUE) && nrow(available_jpmap_data()) > 0) { data("jp_prefecture_gdp") gdp <- jp_prefecture_gdp |> dplyr::select(pref_code, prefecture, gdp_per_capita_jpy) jp_map_leaflet( "prefecture", data = gdp, values = "gdp_per_capita_jpy", popup = "prefecture" ) }if (requireNamespace("leaflet", quietly = TRUE) && requireNamespace("dplyr", quietly = TRUE) && nrow(available_jpmap_data()) > 0) { data("jp_prefecture_gdp") gdp <- jp_prefecture_gdp |> dplyr::select(pref_code, prefecture, gdp_per_capita_jpy) jp_map_leaflet( "prefecture", data = gdp, values = "gdp_per_capita_jpy", popup = "prefecture" ) }
Joins user data to a Japan map object. This is a compact wrapper around
jp_map_join() kept for plotting workflows that call it internally.
jp_map_with_data(map, data, values = NULL, by = NULL)jp_map_with_data(map, data, values = NULL, by = NULL)
map |
An |
data |
A data frame containing a matching administrative code or name column. |
values |
Optional value column to check after joining. |
by |
Optional join column. If omitted, jpmap guesses from common columns. |
An sf object.
A sample data frame containing 2021 prefecture GDP per capita values.
A data frame with 47 rows and 6 variables:
Two-digit Japanese prefecture code.
Prefecture name in English.
Reference year.
GDP per capita in Japanese yen.
GDP per capita in U.S. dollars at PPP.
Source note.
OECD 2021 regional GDP per-capita values as tabulated at https://en.wikipedia.org/wiki/List_of_Japanese_prefectures_by_GDP_per_capita.
A sample data frame containing selected U.S. military installations in Japan with longitude/latitude coordinates and public approximate personnel figures where those figures have a clear source.
A data frame with 17 rows and 12 variables:
Installation or command name.
Primary U.S. military branch.
Japanese prefecture.
Municipality or municipalities.
Longitude in WGS84.
Latitude in WGS84.
Approximate public personnel figure, when available.
What the public figure counts.
Whether the figure describes an installation, regional total, command, or broader installation community.
Whether personnel is interpreted as a
base-specific figure.
Source URL.
Caveat for use in examples.
These values are intended for examples and are not an official personnel
accounting. Some rows describe broader installation, regional, command, or
community populations; see personnel_scope and
personnel_geography.
Public installation, command, and regional pages listed in the source_url
column, including https://en.wikipedia.org/wiki/Misawa_Air_Base,
https://en.wikipedia.org/wiki/Yokota_Air_Base, and
https://en.wikipedia.org/wiki/Okinawa_Island.
Returns the projected coordinate reference system used by jpmap.
jpmap_crs()jpmap_crs()
An sf::st_crs() object.
Helpers for locating and building the GeoPackage boundary data used by jpmap.
Boundary GeoPackage files can come from the separate jpmapdata package
or from files built locally with jpmap_build_data().
jpmap_data_dir(create = TRUE) available_jpmap_data(data_dir = NULL) jpmap_build_data( year = 2024, prefecture = NULL, destdir = jpmap_data_dir(), url = NULL, overwrite = FALSE, quiet = FALSE, simplify_tolerance = NULL )jpmap_data_dir(create = TRUE) available_jpmap_data(data_dir = NULL) jpmap_build_data( year = 2024, prefecture = NULL, destdir = jpmap_data_dir(), url = NULL, overwrite = FALSE, quiet = FALSE, simplify_tolerance = NULL )
create |
Whether to create the default data directory. |
data_dir |
Optional directory to scan for boundary data. |
year |
Boundary data year. |
prefecture |
Optional prefecture code, English name, or Japanese name. When supplied, only that prefecture's official MLIT N03 file is downloaded and built. |
destdir |
Directory where the generated GeoPackage should be written. |
url |
Optional source URL. By default, an MLIT N03 URL is constructed. |
overwrite |
Whether to overwrite an existing GeoPackage. |
quiet |
Whether to suppress messages from download and spatial reads/writes. |
simplify_tolerance |
Optional tolerance passed to |
jpmap_data_dir() returns a path, available_jpmap_data() returns a
data frame with year, pref_code, prefecture,
source, and path, and jpmap_build_data() invisibly returns
the generated file.
MLIT National Land Numerical Information N03 administrative area data: https://nlftp.mlit.go.jp/ksj/gml/datalist/KsjTmplt-N03-2024.html.
jpmap_data_dir(create = FALSE) available_jpmap_data() jpmap_build_data( year = 2024, prefecture = "Ehime", destdir = tempdir(), overwrite = TRUE, quiet = TRUE )jpmap_data_dir(create = FALSE) available_jpmap_data() jpmap_build_data( year = 2024, prefecture = "Ehime", destdir = tempdir(), overwrite = TRUE, quiet = TRUE )
Transforms geographic data to the jpmap projected coordinate system. When
inset = TRUE, Okinawa and Ogasawara are moved to visible inset
locations. Use okinawa = FALSE, ogasawara = FALSE,
inset = "okinawa", or inset = "ogasawara" to transport only one
island group.
jpmap_transform( data, input_names = c("lon", "lat"), output_names = input_names, inset = TRUE, okinawa = TRUE, ogasawara = TRUE )jpmap_transform( data, input_names = c("lon", "lat"), output_names = input_names, inset = TRUE, okinawa = TRUE, ogasawara = TRUE )
data |
An |
input_names |
Longitude and latitude column names for data frames. |
output_names |
Output coordinate column names for data frames. |
inset |
Inset behavior. Use |
okinawa |
Whether Okinawa should be moved when |
ogasawara |
Whether Ogasawara should be moved when |
An object of the same general type as data.
if (requireNamespace("tibble", quietly = TRUE)) { places <- tibble::tribble( ~place, ~lon, ~lat, "Tokyo", 139.767, 35.681, "Naha", 127.681, 26.212, "Ogasawara", 142.191, 27.094 ) places |> jpmap_transform(output_names = c("x", "y")) places |> jpmap_transform(output_names = c("x", "y"), inset = "okinawa") places |> jpmap_transform(output_names = c("x", "y"), ogasawara = FALSE) }if (requireNamespace("tibble", quietly = TRUE)) { places <- tibble::tribble( ~place, ~lon, ~lat, "Tokyo", 139.767, 35.681, "Naha", 127.681, 26.212, "Ogasawara", 142.191, 27.094 ) places |> jpmap_transform(output_names = c("x", "y")) places |> jpmap_transform(output_names = c("x", "y"), inset = "okinawa") places |> jpmap_transform(output_names = c("x", "y"), ogasawara = FALSE) }
Plots Japan prefecture or municipal boundaries using ggplot2.
plot_jpmap( regions = c("prefectures", "prefecture", "municipalities", "municipality"), include = c(), exclude = c(), data = data.frame(), values = NULL, labels = FALSE, label_color = "black", data_year = NULL, inset = TRUE, okinawa = TRUE, ogasawara = TRUE, territorial_disputes = TRUE, disputed_fill = NULL, disputed_color = NULL, disputed_linewidth = NULL, disputed_dots = FALSE, disputed_dot_fill = "#001040", disputed_dot_color = "white", disputed_dot_size = 1.25, disputed_dot_stroke = 0.2, inset_boxes = TRUE, inset_box_color = "grey50", inset_box_linewidth = 0.35, data_dir = NULL, xlim = NULL, ylim = NULL, x_breaks = ggplot2::waiver(), y_breaks = ggplot2::waiver(), x_labels = ggplot2::waiver(), y_labels = ggplot2::waiver(), fill = "grey92", color = "grey35", linewidth = 0.25, ... )plot_jpmap( regions = c("prefectures", "prefecture", "municipalities", "municipality"), include = c(), exclude = c(), data = data.frame(), values = NULL, labels = FALSE, label_color = "black", data_year = NULL, inset = TRUE, okinawa = TRUE, ogasawara = TRUE, territorial_disputes = TRUE, disputed_fill = NULL, disputed_color = NULL, disputed_linewidth = NULL, disputed_dots = FALSE, disputed_dot_fill = "#001040", disputed_dot_color = "white", disputed_dot_size = 1.25, disputed_dot_stroke = 0.2, inset_boxes = TRUE, inset_box_color = "grey50", inset_box_linewidth = 0.35, data_dir = NULL, xlim = NULL, ylim = NULL, x_breaks = ggplot2::waiver(), y_breaks = ggplot2::waiver(), x_labels = ggplot2::waiver(), y_labels = ggplot2::waiver(), fill = "grey92", color = "grey35", linewidth = 0.25, ... )
regions |
Boundary level: prefectures or municipalities. |
include |
Regions to include by code, English name, or Japanese name. |
exclude |
Regions to exclude by code, English name, or Japanese name. |
data |
Optional data frame to join to the map. |
values |
Column name in |
labels |
Whether to draw region labels. |
label_color |
Label text color. |
data_year |
Boundary data year. |
inset |
Inset behavior. Use |
okinawa |
Whether Okinawa should be moved when |
ogasawara |
Whether Ogasawara should be moved when |
territorial_disputes |
Whether to include disputed-territory island/reef
shapes. Use |
disputed_fill |
Optional fill color for disputed-territory shapes. When
|
disputed_color |
Optional outline color for disputed-territory shapes. When
|
disputed_linewidth |
Optional line width for disputed-territory shapes. |
disputed_dots |
Whether to draw dot markers on disputed-territory shapes. |
disputed_dot_fill |
Fill color for disputed-territory dot markers. |
disputed_dot_color |
Outline color for disputed-territory dot markers. |
disputed_dot_size |
Size for disputed-territory dot markers. |
disputed_dot_stroke |
Stroke width for disputed-territory dot markers. |
inset_boxes |
Whether to draw boxes around transported Okinawa and Ogasawara insets. |
inset_box_color |
Outline color for inset boxes. |
inset_box_linewidth |
Line width for inset boxes. |
data_dir |
Optional directory containing |
xlim, ylim
|
Optional longitude and latitude limits for the plot frame. |
x_breaks, y_breaks
|
Optional longitude and latitude axis breaks. |
x_labels, y_labels
|
Optional longitude and latitude axis labels. |
fill |
Boundary fill color when |
color |
Boundary line color. |
linewidth |
Boundary line width. |
... |
Additional arguments passed to |
A ggplot2 plot.
if (nrow(available_jpmap_data()) > 0) { plot_jpmap("prefecture") plot_jpmap("prefecture", ogasawara = FALSE) plot_jpmap("prefecture", territorial_disputes = FALSE) plot_jpmap( "prefecture", ogasawara = FALSE, xlim = c(122, 149), ylim = c(28.5, 47), x_breaks = seq(125, 145, 5), y_breaks = seq(30, 45, 5) ) plot_jpmap("prefecture", inset_boxes = FALSE) plot_jpmap("municipality", include = "Okinawa") }if (nrow(available_jpmap_data()) > 0) { plot_jpmap("prefecture") plot_jpmap("prefecture", ogasawara = FALSE) plot_jpmap("prefecture", territorial_disputes = FALSE) plot_jpmap( "prefecture", ogasawara = FALSE, xlim = c(122, 149), ylim = c(28.5, 47), x_breaks = seq(125, 145, 5), y_breaks = seq(30, 45, 5) ) plot_jpmap("prefecture", inset_boxes = FALSE) plot_jpmap("municipality", include = "Okinawa") }