drawChinaMap | R Documentation |
Draw standard China map.
drawChinaMap( provdata = NULL, citydata = NULL, var.prov = "prov", var = NA, multiply = 1, log = FALSE, digits = 0, nsmall = digits, colors = "Blues", direc = 1, cityshape = 18, cityalpha = 0.9, addlabel = TRUE, labelprefix = "", labelseg = ": ", tag = "", title = var, subtitle = "", guidetitle = "", addguidelabel = TRUE, guidelimits = NULL, guidebreaks = NULL, guidelabels = NULL, bordersize = 0.2, bordercolor = "grey70", na.color = "grey90", font = NULL, filename = "ChinaMap.png", dpi = 500 )
provdata |
Province-level data.
You can use |
citydata |
City-level data with two variables (must be "geoE" and "geoN") specifying the longitude and latitude of cities, respectively. |
var.prov |
The variable of provinces, e.g., |
var |
The variable to show on the map. |
multiply |
A number useful when you want to expand the raw values by, e.g., 100 times. |
log |
|
digits, nsmall |
Number of decimal places of output. Defaults to |
colors |
Color palettes. The following palettes are available
(see Sequential:
Diverging:
Qualitative (not suggested):
|
direc |
|
cityshape |
The shape of city dots. 16 (round) or 18 (rhombus) would be fine.
Defaults to |
cityalpha |
The transparency of city dots. Defaults to |
addlabel |
|
labelprefix |
A character specifying a variable in your data for adding label prefix,
usually |
labelseg |
A character specifying the joint character
between label prefix and values (e.g., setting to |
tag |
Tag of the map (left-top corner).
Defaults to |
title |
Title of the map. Defaults to the variable name. |
subtitle |
Subtitle of the map. Defaults to |
guidetitle |
Title of the colorbar guide. |
addguidelabel |
|
guidelimits |
A number vector specifying the range of values to plot (relevant both to the main plot and to the colorbar guide). Defaults to the actual range of your variable. |
guidebreaks |
A number vector specifying the breaking points of colorbar,
e.g., |
guidelabels |
A vector re-setting the labels of the colorbar guide. |
bordersize |
Line size of map border. Defaults to |
bordercolor |
Line color of map border. Defaults to |
na.color |
A color for those provinces with missing values.
Defaults to |
font |
Text font. Only for Windows systems. |
filename |
File name to be saved, should be either ".png" or ".jpg". |
dpi |
Dots per inch (DPI). Defaults to |
Invisibly return a list of two maps (a main map and a sub-map for Nanhai islands).
## Template # View(provdata_temp) # a template province-level dataset drawChinaMap() # draw a template of China map (no variables) drawChinaMap(provdata_temp, var="geoE", digits=1, filename="ChinaMap1.png") drawChinaMap(provdata_temp, var="geoN", digits=1, colors="Reds", direc=-1, addlabel=FALSE, filename="ChinaMap2.png") ## How to use it with real data? # View(provdata_demo) # a demo dataset (per capita GDP for 31 mainland provinces) # Method 1: Use the 'var.prov' parameter drawChinaMap(provdata_demo, var.prov="Province", var="GDPpc", digits=0, filename="ChinaMap_GDPpc.png") # Method 2: Use dplyr::left_join() or dplyr::right_join() to merge datasets provdata = dplyr::right_join(provdata_temp, provdata_demo, by=c("prov"="Province")) drawChinaMap(provdata, var="GDPpc", digits=0, title="GDP per capita", filename="ChinaMap_GDPpc.png") # delete files for code check unlink(c("ChinaMap.png", "ChinaMap1.png", "ChinaMap2.png", "ChinaMap_GDPpc.png"))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.