geom_mapcn provides a flexible interface for visualizing China's administrative boundaries.
Users can select administrative levels (province, city, or county), apply custom projections,
and filter specific regions.
Usage
geom_mapcn(
data = NULL,
admin_level = "province",
crs = "+proj=aeqd +lat_0=35 +lon_0=105 +ellps=WGS84 +units=m +no_defs",
color = "black",
fill = "white",
linewidth = 0.5,
filter_attribute = NULL,
filter = NULL,
...
)Arguments
- data
An
sfobject containing China's map data. IfNULL, the function loads the package's default map. Users can select provincial, municipal, or county-level maps using theadmin_levelparameter.- admin_level
A character string specifying the administrative level of the map. Options are
"province"(default),"city", or"county". The corresponding GeoJSON files (China_sheng.geojson,China_shi.geojson,China_xian.geojson) must be located in the package'sextdatafolder.- crs
Coordinate Reference System (CRS). Defaults to
"+proj=aeqd +lat_0=35 +lon_0=105 +ellps=WGS84 +units=m +no_defs". Users can specify other CRS strings (e.g.,"EPSG:4326").- color
Border color. Default is
"black".- fill
Fill color. Default is
"white".- linewidth
Line width for borders. Default is
0.5.- filter_attribute
Column name for filtering regions (e.g.,
"name_en").- filter
Character vector of values to filter specific regions (e.g.,
c("Beijing", "Shanghai")).- ...
Additional parameters passed to
geom_sf.
Examples
# Plot provincial map
ggplot() +
geom_mapcn() +
theme_minimal()
# Filter specific provinces
ggplot() +
geom_mapcn(filter_attribute = "name_en", filter = c("Beijing", "Shanghai"), fill = "red") +
theme_minimal()
# Use a Mercator projection
ggplot() +
geom_mapcn(crs = "+proj=merc", linewidth = 0.7) +
theme_minimal()