Drawing a Map of Japan in R

r
How to draw a map of Japan in R using the rnaturalearth and rnaturalearthhires packages.
Published

2026-01-31

Modified

2026-01-31

Note

Original Japanese version: Rで日本地図を描く

Installing and Loading Packages

install.packages("rnaturalearth")

If you use renv, install it with the following command.

renv::install("necountries")

Then load the package.

Drawing a Map of Japan

To draw the map, the rnaturalearthdata package is also required. The following code obtains and draws a map of Japan.

install.packages("rnaturalearthdata")
renv::install("rnaturalearthdata") # when using renv

It should work without explicitly loading the library, but I load it just in case.


Attaching package: 'rnaturalearthdata'
The following object is masked from 'package:rnaturalearth':

    countries110

Use the ne_countries() function to obtain map data for Japan, then draw it with plot().

japan <- ne_countries(
  scale = "medium",
  country = "Japan",
  returnclass = "sf"
)
plot(japan["geometry"])

The arguments are set as follows.

  • scale = "medium": obtains medium-resolution map data. small and large are also available.
  • country = "Japan": specifies map data for Japan.
  • returnclass = "sf": returns the map data as an sf object.

This lets you draw a map of Japan using R. Customize the map style and details as needed.

NoteOfficial Documentation

For details on the ne_countries() function, see the official documentation.

Drawing a Prefecture-Level Map of Japan

To draw a prefecture-level map of Japan, use the rnaturalearthhires package. Install it from GitHub or R-universe.

NoteWhy It Cannot Be Installed from CRAN

It seems that the package cannot be installed from CRAN because its size exceeds the recommended CRAN limit.

remotes::install_github("ropensci/rnaturalearthhires")

Or install it with the following code.

install.packages(
  "rnaturalearthhires",
  repos = "https://ropensci.r-universe.dev",
  type = "source"
)

If you use renv, install it with the following command.

renv::install("ropensci/rnaturalearthhires")

Load the package.

Obtain a prefecture-level map of Japan and draw it.

japan_prefectures <- ne_states(
  country = "Japan",
  returnclass = "sf"
)
plot(japan_prefectures["name_ja"])

The coastline is drawn neatly as well.

NoteOfficial Documentation

For details on the ne_states() function, see the official documentation.

References