Description Usage Arguments Details Value Note See Also Examples
Load the China map and do tiny modifications. Unlike the China map in packages
maps and mapdata, the dataset in this package is based on up-to-date
Chinese official data. And unlike some public data sources such as GADM, the
dataset in this package is compliant to Chinese official requirements.
cnmap0
, cnmap1
, cnmap2
, cnmap3
are convenient
wrappers for level
0 (nation), 1 (province), 2 (city/prefecture),
3 (county) respectively.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | cnmap(level = c("nation", "province", "city", "county"),
regions = NULL, simplify_level = 1, drop_fragment = FALSE,
preserve_topo = c("all", "major", "none"), fragment_area = 0.003,
output = c("spdf", "map", "df", "sf"))
cnmap0(regions = NULL, simplify_level = 1, drop_fragment = FALSE,
preserve_topo = c("all", "major", "none"), fragment_area = 0.003,
output = c("spdf", "map", "df", "sf"))
cnmap1(regions = NULL, simplify_level = 1, drop_fragment = FALSE,
preserve_topo = c("all", "major", "none"), fragment_area = 0.003,
output = c("spdf", "map", "df", "sf"))
cnmap2(regions = NULL, simplify_level = 1, drop_fragment = FALSE,
preserve_topo = c("all", "major", "none"), fragment_area = 0.003,
output = c("spdf", "map", "df", "sf"))
cnmap3(regions = NULL, simplify_level = 1, drop_fragment = FALSE,
preserve_topo = c("all", "major", "none"), fragment_area = 0.003,
output = c("spdf", "map", "df", "sf"))
|
level |
Character or integer, "nation" (0), "province" (1), "city" (2) or "county" (3). Default 'nation'. |
regions |
Character strings that fully/partially match ADCODE, NAME, NAME_LAB or NAME_EN fields. E.g., 'beijing' or '^110' to filter the map to Beijing area (case insensitive). It supports regular expression. Default NULL, indicating that all the regions will be shown. |
simplify_level |
Numeric (0 ~ 1), the proportion of points to retain when
applying polygon simplification. See rmapshaper:: |
drop_fragment |
Logical, whether drop small fragments in the map (typically
small islands). It is useful to reduce the object size by around 10%. Default FALSE.
|
preserve_topo |
Character ("all", "major", "none"), indicating how to preserve
the topology when applying polygon simplification algorithm (only effective when
|
fragment_area |
Numeric, the threshold area (in km^2) for "fragment" (only
effective when |
output |
Character, "spdf", "map", "df", "sf". Default "spdf"
( |
You can obtain maps by running the codes in examples.
By default, an sp::SpatialPolygonsDataFrame
object (output
== "spdf"). You can further process it by
map
objectmaps::SpatialPolygons2map()
ggplot2::fortify()
sf
objectsf::st_as_sf()
You can also directly load the map datasets
using data(cnmap0)
, data(cnmap1)
, data(cnmap2)
, or data(cnmap3)
.
But it is more recommended to call cnmap
() to enjoy the benefits by
its default settings.
Suppose you call cn0 <- data(cnmap0)
,
the data set will show in .GlobalEnv. You can then check its meta data by
cn0@data
(cn0, as a SpatialPolygonsDataFrame object, is of S4 class)
or slot(cn0, "data")
.
If you have issues with the character encoding, then try to switch to a Chinese
locale (Sys.setlocale("LC_CTYPE", "Chs")
).
Some key fields in map meta dataset:
ADCODE: The six-digit official administrative code
NAME: Full name of the administrative area
NAME_LAB: Short name of the administrative area
NAME_EN: English name of the administrative area
The embeded map datasets are applying WGS84 coordinate system. You can define your own coordinate reference system when plotting a map. China's official recommendations:
maps::map
() or ggplot2::coord_map
:
set it with mapproj::mapproject()
smaller maps: projection="albers", parameters = c(24, 47)
larger maps: projection="azequalarea", orientation = c(30, 105, 0)
ggplot2::coord_sf
: set it using CRS
smaller maps: coord_sf(crs="+init=epsg:4490 +proj=aea
+ellps=krass +lon_0=105 +lat_1=25 +lat_2=47")
larger maps: coord_sf(crs="+init=epsg:4490 +proj=laea
+ellps=GRS80 +lon_0=105 +lat_0=30")
Refer to coordcn
to use the parameters directly.
check the vignettes: vignette("drawChinaMap", package="asesgeo")
other useful functions: ms_simplify
,
ms_dissolve
, SpatialPolygonsDataFrame
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | ## Not run:
# to yield the 3-level China map as shown on the top
library(maps)
op <- par(mar=c(0, 0, 0, 0))
map(cnmap(3), col="gray90", lwd=0.2, projection="albers",
parameters = c(24, 47)) # cnmap(3) is equal to cnmap3()
map(cnmap(2), col="gray75", lwd=0.5, add=TRUE, projection="albers",
parameters = c(24, 47))
map(cnmap(1), col="gray30", lwd=0.8, add=TRUE, projection="albers",
parameters = c(24, 47))
map(cnmap(0), col="black", lwd=1, add=TRUE, projection="albers",
parameters = c(24, 47))
par(op)
# to draw the 2-level Beijing map as shown on the top
library(ggplot2)
library(sf)
library(extrafont)
bjmap2 <- st_as_sf(cnmap(2, "^110", simplify_level=0.5))
bjmap3 <- st_as_sf(cnmap(3, "^110", simplify_level=0.5))
ggplot() +
geom_sf(data=bjmap3, color="gray50", size=0.5) +
geom_sf(data=bjmap2, fill="transparent", color="gray5", size=0.8) +
geom_sf_text(aes(label=NAME_LAB), data=bjmap3, family="Microsoft YaHei") +
coord_sf(crs=coordcn$large$crs) + theme_minimal()
## End(Not run)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.