According to the codes and names of county-level and above administrative divisions released in 2022 by the Ministry of Civil Affairs of the People’s Republic of China, the online vector map files were retrieved from the website (available at: http://datav.aliyun.com/portal/school/atlas/area_selector). This study was supported by the National Natural Science Foundation of China (NSFC, Grant No. 42205177).

Installation

Install the latest CRAN release via command:

install.packages("cnmap")

Usage 1

library(ggplot2)
library(sf)
#> Linking to GEOS 3.13.1, GDAL 3.11.4, PROJ 9.7.0; sf_use_s2() is TRUE
library(cnmap)

map1 <- getMap(name = "中国")
ggplot(data = map1) + geom_sf()

Usage 2

map2 <- getMap(code = "100000", subRegion = TRUE) 
ggplot(data = map2) + geom_sf()

Usage 3

map3 <- getMap(name = "吉林省", subRegion = TRUE)
ggplot(data = map3) + geom_sf()


map3 <- getMap(name = "吉林省", subRegion = TRUE)
head(map3)
#> Simple feature collection with 6 features and 9 fields
#> Geometry type: MULTIPOLYGON
#> Dimension:     XY
#> Bounding box:  xmin: 123.3045 ymin: 40.86635 xmax: 128.3179 ymax: 45.2523
#> Geodetic CRS:  WGS 84
#> # A tibble: 6 × 10
#>   adcode name  childrenNum level parent subFeatureIndex center centroid acroutes
#>    <int> <chr>       <int> <chr> <chr>            <int> <list> <list>   <list>  
#> 1 220100 长春市……          11 city  "{ \"…               0 <dbl>  <dbl>    <int>   
#> 2 220200 吉林市……           9 city  "{ \"…               1 <dbl>  <dbl>    <int>   
#> 3 220300 四平市……           5 city  "{ \"…               2 <dbl>  <dbl>    <int>   
#> 4 220400 辽源市……           4 city  "{ \"…               3 <dbl>  <dbl>    <int>   
#> 5 220500 通化市……           7 city  "{ \"…               4 <dbl>  <dbl>    <int>   
#> 6 220600 白山市……           6 city  "{ \"…               5 <dbl>  <dbl>    <int>   
#> # ℹ 1 more variable: geometry <MULTIPOLYGON [°]>
ggplot(data = map3) + 
  geom_sf() +
  geom_sf_label(aes(label = name))
#> Warning in st_point_on_surface.sfc(sf::st_zm(x)): st_point_on_surface may not
#> give correct results for longitude/latitude data


ggplot(data = map3) + 
  geom_sf(aes(fill = name)) +
  geom_sf_label(aes(label = name))
#> Warning in st_point_on_surface.sfc(sf::st_zm(x)): st_point_on_surface may not
#> give correct results for longitude/latitude data

Usage 4

map4 <- getMap(name = "长春市", subRegion = TRUE)
ggplot(data = map4) + geom_sf()

Usage 5

map5 <- getMap(code = "220100", subRegion = TRUE) 
ggplot(data = map5) + geom_sf()

map5 is equivalent to map4.

Usage 6

map6 <- getMap(name = "香港特别行政区", subRegion = TRUE)
ggplot(data = map6) + geom_sf()