# Install packages
if (!requireNamespace("ggplot2", quietly = TRUE)) {
install.packages("ggplot2")
}if (!requireNamespace("RColorBrewer", quietly = TRUE)) {
install.packages("RColorBrewer")
}
# Load packages
library(ggplot2)
library(RColorBrewer)
China Map
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:
Setup
System Requirements: Cross-platform (Linux/MacOS/Windows)
Programming language: R
Dependent packages:
ggplot2
;RColorBrewer
Data Preparation
# Load data
<- read.delim("files/Hiplot/100-map-china-data.txt", header = T)
data <- readRDS("files/Hiplot/china.rds")
dt_map
# Convert data structure
$Value <- data$value[match(dt_map$FCNAME, data$name)]
dt_map
# View data
head(data)
name value
1 ๅฎๅพฝ็ 6118
2 ็ฆๅปบ็ 3581
3 ็่็ 2617
4 ๅนฟไธ็ 9449
5 ่ดตๅท็ 3762
6 ๆตทๅ็ 845
Visualization
# China Map
<- ggplot(dt_map, aes(x = long, y = lat, group = group, fill = Value)) +
p 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
