--- title: "Adding_Basic_Map" output: rmarkdown::html_vignette vignette: > %\VignetteIndexEntry{Adding_Basic_Map} %\VignetteEngine{knitr::rmarkdown} %\VignetteEncoding{UTF-8} --- ```{r, include = FALSE} knitr::opts_chunk$set( collapse = TRUE, comment = "#>" ) ``` ```{r setup} library(ggmapcn) ``` ## 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. ```{r example1, fig.alt='Basic Map'} ggplot() + geom_mapcn() + theme_minimal() ``` ## 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: ```{r example2, fig.alt='Map of China'} ggplot() + geom_buffer_cn(mainland_dist = 40000) + geom_buffer_cn(mainland_dist = 20000, fill = "#BBB3D8") + geom_mapcn(fill = "white") + geom_boundary_cn() + theme_bw() ``` ## 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. ```{r example3, fig.alt='Map of world'} # 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() ``` ## Example 3: Filtering China and Its Neighbors This example demonstrates filtering for China and its neighboring countries, highlighting China in red. ```{r example4, fig.alt='Map of China'} # 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() ```