The ggmapcn package provides various tools for visualizing geographic
data in China and beyond. This vignette demonstrates the basic and
advanced usage of geom_mapcn() and
geom_world() for plotting administrative boundaries and
combining geographic data.
To plot a map of China with province boundaries, use the
geom_mapcn() function. The map uses the Azimuthal Equal
Distance projection by default.
Here’s a comprehensive example demonstrating how to plot province boundaries, buffer zones, and coastlines on the same map:
ggplot() +
  geom_buffer_cn(mainland_dist = 40000) +
  geom_buffer_cn(mainland_dist = 20000, fill = "#BBB3D8") +
  geom_mapcn(fill = "white") +
  geom_boundary_cn() +
  theme_bw()
#> Warning: attribute variables are assumed to be spatially constant throughout
#> all geometries
#> Warning: attribute variables are assumed to be spatially constant throughout
#> all geometriesThe geom_world() function allows you to visualize global
data, while geom_mapcn() overlays China for detailed
analysis.
# Define projections
china_proj <- "+proj=aeqd +lat_0=35 +lon_0=105 +ellps=WGS84 +units=m +no_defs"
# Combine world map as a background and China map as overlay
ggplot() +
  # World map as background
  geom_world(fill = "gray90", color = "gray70", linewidth = 0.2) +
  coord_proj(
    crs = "+proj=merc",
    xlim = c(-180, 180),
    ylim = c(-90, 90)
  ) +
  # Overlay China map
  geom_mapcn(
    fill = "lightblue",
    color = "black",
    linewidth = 0.5
  ) +
  geom_boundary_cn(color = "red", linewidth = 0.6) +
  theme_minimal()
#> Coordinate system already present. Adding new coordinate system, which will
#> replace the existing one.
#> Warning: Duplicated aesthetics after name standardisation: colour and linewidth
#> Duplicated aesthetics after name standardisation: colour and linewidth
#> Duplicated aesthetics after name standardisation: colour and linewidth
#> Duplicated aesthetics after name standardisation: colour and linewidth
#> Duplicated aesthetics after name standardisation: colour and linewidth
#> Duplicated aesthetics after name standardisation: colour and linewidthThis example demonstrates filtering for China and its neighboring countries, highlighting China in red.
# Define neighboring countries
china_neighbors <- c("CHN", "AFG", "BTN", "MMR", "LAO", "NPL", "PRK", "KOR",
                     "KAZ", "KGZ", "MNG", "IND", "BGD", "TJK", "PAK", "LKA", "VNM")
# Plot world map with filtered countries
ggplot() +
  geom_world(fill = "gray90", color = "gray70", linewidth = 0.2) +
  geom_world(
    filter = china_neighbors,
    filter_attribute = "SOC",
    fill = "lightblue",
    color = "black",
    linewidth = 0.5
  ) +
  geom_world(
    filter = "CHN",
    filter_attribute = "SOC",
    fill = "red",
    color = "black",
    linewidth = 0.8
  ) +
  coord_proj(
    crs = "+proj=merc",
    xlim = c(60, 140),
    ylim = c(-10, 60)
  ) +
  theme_minimal()