---
title: "cnmap: Get the vector map of China"
author: "Panfeng Zhang"
date: "`r Sys.Date()`"
output: 
  html_document:
    highlight: textmate
    keep_md: true
    number_sections: no
    theme: united
    toc: yes
    toc_float: yes
vignette: >
  %\VignetteIndexEntry{cnmap: Get the vector map of China}
  %\VignetteEngine{knitr::rmarkdown}
  %\VignetteEncoding{UTF-8}
---

```{r, include = FALSE, message=FALSE}
knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)
```

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:
```{r,eval=FALSE}
install.packages("cnmap")
```

## Usage 1
```{r, dpi=150}
library(ggplot2)
library(sf)
library(cnmap)

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

## Usage 2
```{r}
map2 <- getMap(code = "100000", subRegion = TRUE) 
ggplot(data = map2) + geom_sf()
```

## Usage 3
```{r}
map3 <- getMap(name = "吉林省", subRegion = TRUE)
ggplot(data = map3) + geom_sf()

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

ggplot(data = map3) + 
  geom_sf(aes(fill = name)) +
  geom_sf_label(aes(label = name))
```

## Usage 4
```{r}
map4 <- getMap(name = "长春市", subRegion = TRUE)
ggplot(data = map4) + geom_sf()
```

## Usage 5
```{r}
map5 <- getMap(code = "220100", subRegion = TRUE) 
ggplot(data = map5) + geom_sf()
```

map5 is equivalent to map4.

## Usage 6
```{r}
map6 <- getMap(name = "香港特别行政区", subRegion = TRUE)
ggplot(data = map6) + geom_sf()
```