### Installing ggmapcn R Package Source: https://github.com/rimagination/ggmapcn/blob/main/docs/index.html This snippet provides instructions for installing the development version of the 'ggmapcn' package directly from GitHub. It requires the 'devtools' package to be installed first, which is commented out as an optional prerequisite. ```R # install.packages("devtools") devtools::install_github("Rimagination/ggmapcn", force = TRUE) ``` -------------------------------- ### Installing ggmapcn R Package from GitHub Source: https://github.com/rimagination/ggmapcn/blob/main/README.md This snippet demonstrates how to install the development version of the `ggmapcn` package directly from GitHub using the `devtools` package. The `force = TRUE` argument ensures that the package is reinstalled even if a previous version exists on the system. ```R devtools::install_github("Rimagination/ggmapcn", force = TRUE) ``` -------------------------------- ### Loading ggmapcn Library - R Source: https://github.com/rimagination/ggmapcn/blob/main/docs/articles/Adding_Basic_Map.html Loads the `ggmapcn` package, which is required to use its mapping functions. This is a prerequisite for all subsequent examples that utilize `ggmapcn` functionalities. ```R library(ggmapcn) ``` -------------------------------- ### Plotting Basic China Map with ggmapcn in R Source: https://github.com/rimagination/ggmapcn/blob/main/docs/index.html This example demonstrates how to generate a basic map of China displaying province boundaries using the 'ggmapcn' package. It integrates with 'ggplot2' to create the plot and applies a minimal theme for a clean appearance. ```R library(ggplot2) library(ggmapcn) ggplot() + geom_mapcn() + theme_minimal() ``` -------------------------------- ### Example Plotting Buffered Layers with geom_buffer_cn in R Source: https://github.com/rimagination/ggmapcn/blob/main/docs/reference/geom_buffer_cn.html This R example demonstrates how to integrate `geom_buffer_cn` into a `ggplot()` object to create a map displaying buffered areas around China's boundaries. It illustrates setting specific buffer distances for both the mainland and the ten-segment line, and applies `theme_minimal()` for a clean visual presentation. ```R if (FALSE) { # \dontrun{ ggplot() + geom_buffer_cn( mainland_dist = 10000, ten_line_dist = 5000 ) + theme_minimal() } # } ``` -------------------------------- ### Visualizing Simulated Spatial Data with geom_loc in R Source: https://github.com/rimagination/ggmapcn/blob/main/docs/reference/geom_loc.html This example demonstrates how to generate a random dataset with longitude and latitude, then visualize it using `geom_loc` in combination with `geom_boundary_cn` from the `ggmapcn` package. It shows how to map a categorical variable to point color and customize point size and transparency within a `ggplot2` framework. ```R # Generate a random dataset with latitude and longitude set.seed(123) data_sim <- data.frame( Longitude = runif(100, 80, 120), Latitude = runif(100, 28, 40), Category = sample(c("Type A", "Type B", "Type C"), 100, replace = TRUE) ) # Visualize the data with China's boundaries ggplot() + geom_boundary_cn() + geom_loc( data = data_sim, lon = "Longitude", lat = "Latitude", mapping = aes(color = Category), size = 1, alpha = 0.7 ) + theme_minimal() ``` -------------------------------- ### Plotting Default World Map with `geom_world` in R Source: https://github.com/rimagination/ggmapcn/blob/main/docs/reference/geom_world.html This example demonstrates the simplest usage of `geom_world` to plot a basic world map using its default settings. It combines `ggplot()` with `geom_world()` and `theme_minimal()` for a clean visualization. ```R ggplot() + geom_world() + theme_minimal() ``` -------------------------------- ### Plotting Default Provincial Map in R Source: https://github.com/rimagination/ggmapcn/blob/main/docs/reference/geom_mapcn.html This example demonstrates how to plot a basic provincial-level map of China using `geom_mapcn` with its default settings. It initializes a ggplot object, adds the map layer, and applies a minimal theme for a clean visualization. ```R ggplot() + geom_mapcn() + theme_minimal() ``` -------------------------------- ### Applying Mercator Projection to Map in R Source: https://github.com/rimagination/ggmapcn/blob/main/docs/reference/geom_mapcn.html This example illustrates how to change the coordinate reference system (CRS) of the map to Mercator projection. It sets the `crs` parameter to `"+proj=merc"` and adjusts the border line width, demonstrating flexibility in map rendering. ```R ggplot() + geom_mapcn(crs = "+proj=merc", linewidth = 0.7) + theme_minimal() ``` -------------------------------- ### Using Custom DEM Data with basemap_dem in R Source: https://github.com/rimagination/ggmapcn/blob/main/docs/reference/basemap_dem.html This example demonstrates how to integrate custom digital elevation model (DEM) data into `basemap_dem` by providing a `terra` raster object. It shows how to load a local DEM file (or use a built-in example) and then render it as a base map layer in `ggplot2`, offering flexibility for users with their own elevation datasets. ```R dem_path <- system.file("extdata", "gebco_2024.tif", package = "ggmapcn") # Use the built-in DEM data ggplot() + basemap_dem(data = terra::rast(dem_path), within_china = FALSE) + theme_minimal() ``` -------------------------------- ### Customizing Map Styles with Transparency and Borders in R Source: https://github.com/rimagination/ggmapcn/blob/main/docs/reference/geom_world.html This example showcases advanced aesthetic customization of the world map using `geom_world`. It sets a light blue fill, dark blue borders, increased line width, and applies transparency (`alpha`) to the map, then uses `theme_void()` for a minimalist background. ```R ggplot() + geom_world(fill = "lightblue", color = "darkblue", linewidth = 1, alpha = 0.8) + theme_void() ``` -------------------------------- ### Adding Buffer Zones Around China's Borders in R Source: https://github.com/rimagination/ggmapcn/blob/main/docs/index.html This example shows how to add buffer zones around China's borders using 'geom_buffer_cn()'. It allows specifying different buffer distances and fill colors for each zone, providing a visual representation of areas at varying proximities to the national boundaries. ```R ggplot() + geom_buffer_cn(mainland_dist = 40000) + geom_buffer_cn(mainland_dist = 20000, fill = "#BBB3D8") + geom_mapcn(fill = "white") + geom_boundary_cn() + theme_minimal() ``` -------------------------------- ### Adding Default Vegetation Map to ggplot2 (R) Source: https://github.com/rimagination/ggmapcn/blob/main/docs/reference/basemap_vege.html This example demonstrates how to add the default vegetation raster map of China to a ggplot2 plot using `basemap_vege` without any custom parameters. It initializes a ggplot object and adds the vegetation layer along with a minimal theme for a clean visualization. ```R ggplot() + basemap_vege() + theme_minimal() ``` -------------------------------- ### Adding China Elevation Map with basemap_dem in R Source: https://github.com/rimagination/ggmapcn/blob/main/docs/articles/Adding_Spatial_Data.html This example demonstrates how to add a digital elevation model (DEM) raster map of China using `basemap_dem`. It applies the previously defined `china_proj` for accurate projection and uses `tidyterra::scale_fill_hypso_c` to color the elevation data with a hypsometric palette, including custom breaks and limits for the legend. ```R ggplot() + basemap_dem(crs = china_proj, within_china = TRUE) + geom_boundary_cn(crs = china_proj) + tidyterra::scale_fill_hypso_c( palette = "dem_print", breaks = c(0, 2000, 4000, 6000), limits = c(0, 7000) ) + labs(fill = "Elevation (m)") + theme_minimal() + theme(legend.position = "bottom") ``` -------------------------------- ### Adding Spatial Point Data with geom_loc in R Source: https://github.com/rimagination/ggmapcn/blob/main/docs/articles/Adding_Spatial_Data.html This example demonstrates how to use `geom_loc` to add spatial point data to a ggplot. It generates simulated point data with a 'Category' variable and then plots these points on a map of China, coloring them by their respective categories. This function supports both `sf` objects and tabular data frames. ```R set.seed(123) data_sim <- data.frame( Longitude = runif(100, 80, 120), Latitude = runif(100, 28, 40), Category = sample(c("Type A", "Type B", "Type C"), 100, replace = TRUE) ) ggplot() + geom_boundary_cn() + geom_loc( data = data_sim, lon = "Longitude", lat = "Latitude", mapping = aes(color = Category), size = 1, alpha = 0.7 ) + theme_bw() ``` -------------------------------- ### Plotting China Boundaries with Default Settings (R) Source: https://github.com/rimagination/ggmapcn/blob/main/docs/reference/geom_boundary_cn.html This R code snippet uses `ggplot2` and `ggmapcn` to plot China's national boundaries with default visual settings. It provides a basic map without additional navigational elements, serving as a fundamental example of `geom_boundary_cn()` usage. ```R ggplot() + geom_boundary_cn() + theme_minimal() ``` -------------------------------- ### Displaying Full Rectangular DEM Area with basemap_dem in R Source: https://github.com/rimagination/ggmapcn/blob/main/docs/reference/basemap_dem.html This example demonstrates how to use `basemap_dem` to display the full rectangular digital elevation model (DEM) area surrounding China. It integrates with `ggplot2` and utilizes `tidyterra::scale_fill_hypso_tint_c` to apply a hypsometric tint scale, providing a visual representation of elevation across the broader region. ```R china_proj <- "+proj=aeqd +lat_0=35 +lon_0=105 +ellps=WGS84 +units=m +no_defs" ggplot() + basemap_dem(within_china = FALSE) + tidyterra::scale_fill_hypso_tint_c( palette = "gmt_globe", breaks = c(-10000, -5000, 0, 2000, 5000, 8000) ) + theme_minimal() ``` -------------------------------- ### Adding China Vegetation Map with basemap_vege in R Source: https://github.com/rimagination/ggmapcn/blob/main/docs/articles/Adding_Spatial_Data.html This snippet illustrates the use of `basemap_vege` to overlay a vegetation raster map of China onto a ggplot. It adds a color-coded layer representing different vegetation types, providing a quick way to visualize China's ecological landscape. The `guides(fill = guide_none())` call removes the legend for the fill aesthetic. ```R ggplot() + basemap_vege() + guides(fill = guide_none()) + theme_bw() ``` -------------------------------- ### Plotting World Map with WGS84 Projection in R Source: https://github.com/rimagination/ggmapcn/blob/main/docs/reference/coord_proj.html This example demonstrates how to create a world map using `ggplot2` and `ggmapcn::coord_proj`. It sets a WGS84 (longitude/latitude) projection with full global limits and disables plot expansion, providing a basic, unexpanded view of the world. ```R ggplot() + geom_world() + coord_proj( crs = "+proj=longlat +datum=WGS84", xlim = c(-180, 180), ylim = c(-90, 90), expand=FALSE ) + theme_minimal() ``` -------------------------------- ### Filtering Specific Provinces in R Source: https://github.com/rimagination/ggmapcn/blob/main/docs/reference/geom_mapcn.html This example shows how to filter and display only specific provinces (Beijing and Shanghai) on the map. It uses the `filter_attribute` and `filter` parameters to select regions by their English names and customizes the fill color to red. ```R ggplot() + geom_mapcn(filter_attribute = "name_en", filter = c("Beijing", "Shanghai"), fill = "red") + theme_minimal() ``` -------------------------------- ### Filtering Specific Countries with `geom_world` in R Source: https://github.com/rimagination/ggmapcn/blob/main/docs/reference/geom_world.html This example illustrates how to filter and display only a specific set of countries using the `filter` argument. It defines a vector of ISO 3166-1 alpha-3 country codes (`china_neighbors`) and passes it to `geom_world` to highlight China and its surrounding nations. ```R china_neighbors <- c("CHN", "AFG", "BTN", "MMR", "LAO", "NPL", "PRK", "KOR", "KAZ", "KGZ", "MNG", "IND", "BGD", "TJK", "PAK", "LKA", "VNM") ggplot() + geom_world(filter = china_neighbors) + theme_minimal() ``` -------------------------------- ### Customizing Vegetation Map Colors in ggplot2 (R) Source: https://github.com/rimagination/ggmapcn/blob/main/docs/reference/basemap_vege.html This example illustrates how to customize the colors of the vegetation map by providing a `custom_colors` data frame to `basemap_vege`. The data frame maps numeric codes to specific vegetation types and their corresponding hexadecimal color codes, allowing for tailored visual representation and a custom legend title. ```R custom_colors <- data.frame( code = 0:11, type = c( "Non-vegetated", "Needleleaf forest", "Needleleaf and broadleaf mixed forest", "Broadleaf forest", "Scrub", "Desert", "Steppe", "Grassland", "Meadow", "Swamp", "Alpine vegetation", "Cultivated vegetation" ), col = c( "#8D99B3", "#97B555", "#34BF36", "#9ACE30", "#2EC6C9", "#E5CE0E", "#5BB1ED", "#6494EF", "#7AB9CB", "#D97A80", "#B87701", "#FEB780" ) ) ggplot() + basemap_vege(color_table = custom_colors) + labs(fill = "Vegetation type group") + theme_minimal() ``` -------------------------------- ### Displaying China's DEM and Boundaries with basemap_dem in R Source: https://github.com/rimagination/ggmapcn/blob/main/docs/reference/basemap_dem.html This example illustrates how to display only the digital elevation model (DEM) within China's administrative boundaries, along with the country's borders, using `basemap_dem` and `geom_boundary_cn`. It applies a custom Azimuthal Equidistant projection and `tidyterra::scale_fill_hypso_c` for a specific elevation color scale, focusing the map on China's landmass. ```R ggplot() + basemap_dem(crs = china_proj, within_china = TRUE) + geom_boundary_cn(crs = china_proj) + tidyterra::scale_fill_hypso_c( palette = "dem_print", breaks = c(0, 2000, 4000, 6000), limits = c(0, 7000) ) + labs(fill = "Elevation (m)") + theme_minimal() ``` -------------------------------- ### Plotting South China Sea Islands with Custom Projection in R Source: https://github.com/rimagination/ggmapcn/blob/main/docs/reference/coord_proj.html This example focuses on displaying a small map of the South China Sea Islands. It utilizes `geom_boundary_cn()` for specific boundaries and applies the previously defined `china_proj` CRS with `coord_proj`, setting tight longitude and latitude limits and disabling expansion for a precise view. ```R ggplot() + geom_boundary_cn() + theme_bw() + coord_proj( crs = china_proj, expand = FALSE, xlim = c(105, 123), ylim = c(2, 23) ) ``` -------------------------------- ### Adding Buffer Zones and Coastlines to China Map - R Source: https://github.com/rimagination/ggmapcn/blob/main/docs/articles/Adding_Basic_Map.html Creates a comprehensive map of China by adding two buffer zones around the mainland with specified distances and fill colors. It then overlays province boundaries and includes coastlines, applying a black and white theme for clarity. ```R ggplot() + geom_buffer_cn(mainland_dist = 40000) + geom_buffer_cn(mainland_dist = 20000, fill = "#BBB3D8") + geom_mapcn(fill = "white") + geom_boundary_cn() + theme_bw() ``` -------------------------------- ### Plotting a Basic Map of China with ggmapcn Source: https://github.com/rimagination/ggmapcn/blob/main/README.md This R code snippet shows how to generate a basic map of China using the `ggmapcn` package. It loads the `ggplot2` and `ggmapcn` libraries, then uses `ggplot()` in conjunction with `geom_mapcn()` to draw the province boundaries, applying a minimal theme for a clean visual presentation. ```R library(ggplot2) library(ggmapcn) ggplot() + geom_mapcn() + theme_minimal() ``` -------------------------------- ### Initializing ggmapcn and Defining Custom Projection in R Source: https://github.com/rimagination/ggmapcn/blob/main/docs/articles/Adding_Spatial_Data.html This snippet loads the `ggmapcn` package, which is essential for using its spatial visualization functions. It also defines `china_proj`, a custom Azimuthal Equidistant projection string centered on China, crucial for consistent spatial transformations across different map layers. ```R library(ggmapcn) # Define Azimuthal Equidistant projection centered on China china_proj <- "+proj=aeqd +lat_0=35 +lon_0=105 +ellps=WGS84 +units=m +no_defs" ``` -------------------------------- ### Overlaying China on World Map - R Source: https://github.com/rimagination/ggmapcn/blob/main/docs/articles/Adding_Basic_Map.html Visualizes global data with China overlaid for detailed analysis. This snippet defines a custom Azimuthal Equal Distance projection for China, plots a world map as a background using Mercator projection, and then overlays the China map with its boundaries. ```R # 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() ``` -------------------------------- ### Filtering and Highlighting China and Neighbors on World Map - R Source: https://github.com/rimagination/ggmapcn/blob/main/docs/articles/Adding_Basic_Map.html Demonstrates how to filter and highlight specific countries on a world map using `geom_world()`. It defines a list of China's neighboring countries, plots the world map, then overlays the neighbors, and finally highlights China in red using `filter` and `filter_attribute` parameters. ```R # 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() ``` -------------------------------- ### Plotting Basic Map of China - R Source: https://github.com/rimagination/ggmapcn/blob/main/docs/articles/Adding_Basic_Map.html Generates a basic map of China with province boundaries using the `geom_mapcn()` function. The map uses the Azimuthal Equal Distance projection by default and applies a minimal theme for a clean visualization. ```R ggplot() + geom_mapcn() + theme_minimal() ``` -------------------------------- ### Adding Buffer Zones Around China's Borders Source: https://github.com/rimagination/ggmapcn/blob/main/README.md This snippet shows how to add buffer zones around China's borders using `geom_buffer_cn()`, allowing for visualization of areas at specified distances from the mainland. It layers multiple buffer zones with different distances and fills, then overlays the main map and boundaries, all with a minimal theme for better visualization. ```R ggplot() + geom_buffer_cn(mainland_dist = 40000) + geom_buffer_cn(mainland_dist = 20000, fill = "#BBB3D8") + geom_mapcn(fill = "white") + geom_boundary_cn() + theme_minimal() ``` -------------------------------- ### Adding Mainland Borders and Coastlines to China Map Source: https://github.com/rimagination/ggmapcn/blob/main/README.md This R code demonstrates how to enhance a China map by adding distinct mainland borders and coastlines using `geom_boundary_cn()`. It first plots the map with no fill, then overlays boundaries with specified colors and line widths for both mainland and coastline features, applying a minimal theme for clarity. ```R ggplot() + geom_mapcn(fill = NA) + geom_boundary_cn( mainland_color = "black", mainland_size = 0.5, coastline_color = "skyblue", coastline_size = 0.5 ) + theme_minimal() ``` -------------------------------- ### Applying Custom Projection and Limits with coord_proj in R Source: https://github.com/rimagination/ggmapcn/blob/main/docs/articles/Adding_Spatial_Data.html This snippet showcases `coord_proj`, a wrapper for `coord_sf`, to apply a custom projection (`china_proj`) and define map limits using WGS84 longitude and latitude coordinates. It plots a world map and then clips it to the specified `xlim` and `ylim`, automatically transforming these limits to the target CRS for accurate visualization. ```R ggplot() + geom_world(fill = "lightblue") + coord_proj( crs = china_proj, xlim = c(60, 140), ylim = c(10, 50) ) + theme_minimal() ``` -------------------------------- ### Plotting Focused Map with Azimuthal Equidistant Projection in R Source: https://github.com/rimagination/ggmapcn/blob/main/docs/reference/coord_proj.html This snippet illustrates creating a focused map, specifically centered on China, using an Azimuthal Equidistant projection. It defines a custom `china_proj` CRS and applies it with `coord_proj` to display a specific longitude and latitude range, filling the world geometry with light blue. ```R china_proj <- "+proj=aeqd +lat_0=35 +lon_0=105 +ellps=WGS84 +units=m +no_defs" ggplot() + geom_world(fill = "lightblue") + coord_proj( crs = china_proj, xlim = c(60, 140), ylim = c(-10, 50) ) + theme_minimal() ``` -------------------------------- ### Highlighting Specific Regions on a Background Map in R Source: https://github.com/rimagination/ggmapcn/blob/main/docs/reference/geom_world.html This snippet demonstrates how to create a layered map where a background world map is displayed with muted colors, and a specific country (China) is highlighted with distinct fill, color, and line width. This is achieved by adding two `geom_world` layers. ```R ggplot() + geom_world(fill = "gray80", color = "gray50", alpha = 0.5) + geom_world(filter = c("CHN"), fill = "red", color = "black", linewidth = 1.5) + theme_minimal() ``` -------------------------------- ### Plotting China Boundaries with Compass and Scale Bar (R) Source: https://github.com/rimagination/ggmapcn/blob/main/docs/reference/geom_boundary_cn.html This R code snippet extends the basic boundary plot by adding a compass and a scale bar using `geom_boundary_cn`'s built-in options (`compass = TRUE`, `scale = TRUE`). This enhances the map's navigability and interpretability without requiring external packages. ```R ggplot() + geom_boundary_cn(compass = TRUE, scale = TRUE) + theme_minimal() ``` -------------------------------- ### Adding Mainland Borders and Coastlines to China Map in R Source: https://github.com/rimagination/ggmapcn/blob/main/docs/index.html This code demonstrates how to overlay mainland borders and coastlines onto the China map using 'geom_boundary_cn()'. It provides options to customize the color and size of both the mainland and coastline boundaries, allowing for clear visual differentiation. ```R ggplot() + geom_mapcn(fill = NA) + geom_boundary_cn( mainland_color = "black", mainland_size = 0.5, coastline_color = "skyblue", coastline_size = 0.5 ) + theme_minimal() ``` -------------------------------- ### Customizing China Map Projection and Styling Source: https://github.com/rimagination/ggmapcn/blob/main/README.md This snippet illustrates how to apply a custom Albers projection and specific styling to the China map using `geom_mapcn()`. It sets a detailed `crs` (Coordinate Reference System) string, and customizes the `color`, `fill`, and `size` of the map features, followed by applying a minimal theme. ```R ggplot() + geom_mapcn(crs = "+proj=aea +lat_1=25 +lat_2=47 +lat_0=0 +lon_0=105 +x_0=0 +y_0=0 +datum=WGS84 +units=m +no_defs", color = "black", fill = "white", size = 0.7) + theme_minimal() ``` -------------------------------- ### Defining geom_loc Function Signature in R Source: https://github.com/rimagination/ggmapcn/blob/main/docs/reference/geom_loc.html This snippet illustrates the function signature for `geom_loc`, detailing its parameters. It accepts a data source, column names for longitude and latitude (if tabular), a target Coordinate Reference System (CRS), aesthetic mappings, and additional arguments to be passed to `ggplot2::geom_sf()`. ```R geom_loc( data, lon = NULL, lat = NULL, crs = "+proj=aeqd +lat_0=35 +lon_0=105 +ellps=WGS84 +units=m +no_defs", mapping = aes(), ... ) ``` -------------------------------- ### Customizing Compass and Scale Bar for China Boundary Plot (R) Source: https://github.com/rimagination/ggmapcn/blob/main/docs/reference/geom_boundary_cn.html This R code snippet demonstrates how to add highly customized compass arrows and scale bars to a China boundary map using `ggspatial` functions directly. It allows for precise control over their appearance and placement, overriding `geom_boundary_cn`'s default options for more advanced map design. ```R ggplot() + geom_boundary_cn() + ggspatial::annotation_north_arrow( location = "br", style = ggspatial::north_arrow_minimal() ) + ggspatial::annotation_scale( location = "tr", width_hint = 0.3 ) + theme_minimal() ``` -------------------------------- ### Defining `geom_world` Function Signature in R Source: https://github.com/rimagination/ggmapcn/blob/main/docs/reference/geom_world.html This snippet defines the function signature for `geom_world`, outlining its default parameters for data, CRS, colors, line width, and filtering attributes. It serves as a reference for how to call the function with its various customizable options. ```R geom_world( data = NULL, crs = "+proj=longlat +datum=WGS84", color = "black", fill = "white", linewidth = 0.5, filter_attribute = "SOC", filter = NULL, ... ) ``` -------------------------------- ### Applying Mercator Projection with `geom_world` in R Source: https://github.com/rimagination/ggmapcn/blob/main/docs/reference/geom_world.html This snippet shows how to apply a custom coordinate reference system (CRS) to the world map using the `crs` argument. It specifically uses the `"+proj=merc"` string to project the map onto a Mercator projection. ```R ggplot() + geom_world(crs = "+proj=merc") + theme_minimal() ``` -------------------------------- ### Plotting China Boundary with Custom Projection in R Source: https://github.com/rimagination/ggmapcn/blob/main/docs/articles/Adding_Spatial_Data.html This R code snippet extends a ggplot2 plot by adding the geographical boundary of China using `geom_boundary_cn()`. It then applies a black and white theme with `theme_bw()` and sets a custom coordinate projection using `coord_proj()`. The projection uses a `china_proj` CRS, disables expansion, and defines specific longitude (`xlim`) and latitude (`ylim`) limits for the plot. ```R geom_boundary_cn() + theme_bw() + coord_proj( crs = china_proj, expand = FALSE, xlim = c(105, 126), ylim = c(2, 23) ) ``` -------------------------------- ### Customizing China Map Projection and Styling in R Source: https://github.com/rimagination/ggmapcn/blob/main/docs/index.html This snippet illustrates how to apply a custom Albers projection to the China map and customize its visual styling. It allows setting specific colors for borders and fill, as well as line thickness, enhancing the map's aesthetic and geographic accuracy. ```R ggplot() + geom_mapcn(crs = "+proj=aea +lat_1=25 +lat_2=47 +lat_0=0 +lon_0=105 +x_0=0 +y_0=0 +datum=WGS84 +units=m +no_defs", color = "black", fill = "white", size = 0.7) + theme_minimal() ``` -------------------------------- ### Defining China Boundary Plotting Parameters in R Source: https://github.com/rimagination/ggmapcn/blob/main/docs/reference/geom_boundary_cn.html This snippet defines the `geom_boundary_cn` function signature, outlining all available parameters for customizing the plotting of China's various boundaries (mainland, coastline, ten-segment line, SAR, undefined) and optional map elements like compass and scale bar. It specifies default values for CRS, colors, sizes, and linetypes, allowing users to tailor the map's visual representation. ```R geom_boundary_cn( crs = "+proj=aeqd +lat_0=35 +lon_0=105 +ellps=WGS84 +units=m +no_defs", compass = FALSE, scale = FALSE, mainland_color = "black", mainland_size = 0.5, mainland_linetype = "solid", coastline_color = "blue", coastline_size = 0.3, coastline_linetype = "solid", ten_segment_line_color = "black", ten_segment_line_size = 0.5, ten_segment_line_linetype = "solid", SAR_boundary_color = "grey", SAR_boundary_size = 0.5, SAR_boundary_linetype = "dashed", undefined_boundary_color = "black", undefined_boundary_size = 0.5, undefined_boundary_linetype = "longdash", ... ) ``` -------------------------------- ### Function Signature: basemap_vege (R) Source: https://github.com/rimagination/ggmapcn/blob/main/docs/reference/basemap_vege.html This snippet shows the function signature for `basemap_vege`, detailing its parameters for adding a vegetation map of China to a ggplot2 plot. It includes options for custom color tables, coordinate reference systems, and rendering performance, along with a variadic argument for additional parameters. ```R basemap_vege( color_table = NULL, crs = NULL, maxcell = 1e+06, use_coltab = TRUE, na.rm = FALSE, ... ) ``` -------------------------------- ### Defining geom_buffer_cn Function in R Source: https://github.com/rimagination/ggmapcn/blob/main/docs/reference/geom_buffer_cn.html This R function `geom_buffer_cn` is designed to generate a ggplot2 layer for visualizing buffered regions around China's mainland and ten-segment line boundaries. It allows users to specify buffer distances, a custom coordinate reference system (CRS), and visual properties like fill and border colors, while also supporting additional `geom_sf` parameters. ```R geom_buffer_cn( mainland_dist = 20000, ten_line_dist = NULL, crs = "+proj=aeqd +lat_0=35 +lon_0=105 +ellps=WGS84 +units=m +no_defs", color = NA, fill = "#D2D5EB", ... ) ``` -------------------------------- ### Function Signature: coord_proj in R Source: https://github.com/rimagination/ggmapcn/blob/main/docs/reference/coord_proj.html This snippet shows the function signature for `coord_proj`, detailing its parameters for specifying coordinate reference systems, longitude/latitude limits, expansion behavior, and default CRS for input coordinates. It serves as the primary interface for configuring custom map projections within `ggplot2`. ```R coord_proj( crs = NULL, xlim = NULL, ylim = NULL, expand = TRUE, default_crs = "EPSG:4326", ... ) ``` -------------------------------- ### Function Signature for basemap_dem in R Source: https://github.com/rimagination/ggmapcn/blob/main/docs/reference/basemap_dem.html This snippet presents the function signature for `basemap_dem`, outlining its parameters such as `data` for custom DEM, `crs` for coordinate reference system, `within_china` for boundary clipping, `maxcell` for rendering performance, and `na.rm` for missing values. It defines the structure for calling the function. ```R basemap_dem( data = NULL, crs = NULL, within_china = FALSE, maxcell = 1e+06, na.rm = FALSE, ... ) ``` -------------------------------- ### Defining geom_mapcn Function in R Source: https://github.com/rimagination/ggmapcn/blob/main/docs/reference/geom_mapcn.html This snippet defines the `geom_mapcn` function, which is used to plot China's administrative boundaries within a ggplot2 framework. It allows customization of data source, administrative level, coordinate reference system, visual properties like color and fill, and filtering options. ```R 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, ... ) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.