--- title: "Plot Prefectural Choropleth Maps" description: "Join prefecture-level GDP data to a Japan map and map one fill variable." output: rmarkdown::html_vignette vignette: > %\VignetteIndexEntry{Plot Prefectural Choropleth Maps} %\VignetteEngine{knitr::rmarkdown} %\VignetteEncoding{UTF-8} --- ```{r, include = FALSE} knitr::opts_chunk$set( collapse = TRUE, comment = "#>", message = FALSE, fig.width = 7, fig.height = 5, dpi = 120, fig.bg = "white", dev.args = list(bg = "white") ) jpmap_build_full_vignettes <- identical(tolower(Sys.getenv("JPMAP_FULL_VIGNETTES")), "true") || identical(tolower(Sys.getenv("IN_PKGDOWN")), "true") jpmap_has_boundary_data <- jpmap_build_full_vignettes && nrow(jpmap::available_jpmap_data()) > 0 ``` This example uses `jp_prefecture_gdp`, a bundled prefecture-level GDP dataset. The map uses one fill variable: GDP per capita in Japanese yen. ```{r} library(tidyverse) library(jpmap) gdp <- jp_prefecture_gdp |> select(pref_code, prefecture, gdp_per_capita_jpy) ``` ```{r prefectural-gdp, eval = jpmap_has_boundary_data} plot_jpmap( "prefecture", data = gdp, values = "gdp_per_capita_jpy", color = "grey35", linewidth = 0.25 ) + scale_fill_gradient( low = "#D9E8FF", high = "#001040", name = "GDP per capita\n(JPY)" ) + labs( title = "Prefecture GDP per capita", caption = "GDP data: OECD 2021 values tabulated on Wikipedia." ) + theme( legend.background = element_rect(fill = "white", color = NA), plot.title = element_text(face = "bold", color = "#001040"), plot.caption = element_text(color = "#2C2A29", hjust = 0, size = 8) ) ``` `plot_jpmap()` joins by a shared column. Here both the map and `gdp` have `pref_code`, so no extra join argument is needed.