The hardware and bandwidth for this mirror is donated by dogado GmbH, the Webhosting and Full Service-Cloud Provider. Check out our Wordpress Tutorial.
If you wish to report a bug, or if you are interested in having us mirror your free-software or open-source project, please feel free to contact us at mirror[@]dogado.de.

Adding_Basic_Map

library(ggmapcn)
#> Loading required package: ggplot2

Introduction

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.

Example 1: Basic Map of China

To plot a map of China with province boundaries, use the geom_mapcn() function. The map uses the Azimuthal Equal Distance projection by default.

ggplot() +
  geom_mapcn() +
  theme_minimal()
#> Warning in value[[3L]](cond): Attempt 1 failed to download China_xian.rda due
#> to error: Transferred a partial file [raw.githubusercontent.com]: end of
#> response with 3498652 bytes missing
#> Retrying in 5 seconds...
#> Warning in value[[3L]](cond): Attempt 2 failed to download China_xian.rda due
#> to error: Timeout was reached [raw.githubusercontent.com]: SSL/TLS connection
#> timeout
#> Retrying in 5 seconds...
#> Warning in value[[3L]](cond): Failed to download China_xian.rda after 3
#> attempts.

Basic Map

Example 2: Adding Buffer Zones and Coastlines

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 geometries

Map of China

Example 3: Overlaying China on a World Map

The 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 linewidth

Map of world

Example 3: Filtering China and Its Neighbors

This 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()

Map of China

These binaries (installable software) and packages are in development.
They may not be fully stable and should be used with caution. We make no claims about them.
Health stats visible at Monitor.