China Map

Authors

[Editor] Hu Zheng;

[Contributors]

Note

Hiplot website

This page is the tutorial for source code version of the Hiplot China Map plugin. You can also use the Hiplot website to achieve no code ploting. For more information please see the following link:

https://hiplot.cn/basic/map-china?lang=en

Setup

  • System Requirements: Cross-platform (Linux/MacOS/Windows)

  • Programming language: R

  • Dependent packages: ggplot2; RColorBrewer

# Install packages
if (!requireNamespace("ggplot2", quietly = TRUE)) {
  install.packages("ggplot2")
}
if (!requireNamespace("RColorBrewer", quietly = TRUE)) {
  install.packages("RColorBrewer")
}

# Load packages
library(ggplot2)
library(RColorBrewer)

Data Preparation

# Load data
data <- read.delim("files/Hiplot/100-map-china-data.txt", header = T)
dt_map <- readRDS("files/Hiplot/china.rds")

# Convert data structure
dt_map$Value <- data$value[match(dt_map$FCNAME, data$name)]

# View data
head(data)
    name value
1 ๅฎ‰ๅพฝ็œ  6118
2 ็ฆๅปบ็œ  3581
3 ็”˜่‚ƒ็œ  2617
4 ๅนฟไธœ็œ  9449
5 ่ดตๅทž็œ  3762
6 ๆตทๅ—็œ   845

Visualization

# China Map
p <- ggplot(dt_map, aes(x = long, y = lat, group = group, fill = Value)) +
  labs(fill = "Value") +
  geom_polygon() +
  geom_path() +
  scale_fill_gradientn(
    colours = colorRampPalette(rev(brewer.pal(11,"RdYlBu")))(500),
    na.value = "grey10",
    limits = c(0, max(dt_map$Value) * 1.2)) +
    ggtitle("China Map Plot") +
  theme_minimal()

p
Figureย 1: China Map