World map
# require packages: readxl, tidyverse, ggplot2, raster, rgdal, viridis, sp
world.map = map_data("world")
head(world.map)
## long lat group order region subregion
## 1 -69.89912 12.45200 1 1 Aruba <NA>
## 2 -69.89571 12.42300 1 2 Aruba <NA>
## 3 -69.94219 12.43853 1 3 Aruba <NA>
## 4 -70.00415 12.50049 1 4 Aruba <NA>
## 5 -70.06612 12.54697 1 5 Aruba <NA>
## 6 -70.05088 12.59707 1 6 Aruba <NA>
p = ggplot(data=world.map, aes(x=long, y=lat, group=group, fill=factor(group)))
p + geom_polygon(col="white") + theme(legend.position="none")

Get specific countries
countries = c("Vietnam", "Thailand", "Cambodia", "Malaysia", "Laos")
asean = map_data("world", region = countries)
ggplot(asean, aes(x=long, y=lat, group=group, fill=factor(group))) + geom_polygon(col="white") + theme(legend.position="none")

Map of Vietnam - provincial level
# Get the Vietnam data – provincial level
library(raster)
vnm = getData("GADM", country="Vietnam", level=1)
head(vnm)
## GID_0 NAME_0 GID_1 NAME_1 VARNAME_1 NL_NAME_1 TYPE_1 ENGTYPE_1 CC_1
## 1 VNM Vietnam VNM.1_1 An Giang An Giang <NA> Tỉnh Province <NA>
## 12 VNM Vietnam VNM.2_1 Bạc Liêu Bac Lieu <NA> Tỉnh Province <NA>
## 23 VNM Vietnam VNM.3_1 Bắc Giang Bac Giang <NA> Tỉnh Province <NA>
## 34 VNM Vietnam VNM.4_1 Bắc Kạn Bac Kan <NA> Tỉnh Province <NA>
## 45 VNM Vietnam VNM.5_1 Bắc Ninh Bac Ninh <NA> Tỉnh Province <NA>
## 56 VNM Vietnam VNM.6_1 Bến Tre Ben Tre <NA> Tỉnh Province <NA>
## HASC_1
## 1 VN.AG
## 12 VN.BL
## 23 VN.BG
## 34 VN.BK
## 45 VN.BN
## 56 VN.BR
# Clean up data
vn = fortify(vnm, regions="VARNAME_1")
## Regions defined for each Polygons
vn$id = as.numeric(as.factor(vn$id))
head(vn)
## long lat order hole piece id group
## 1 105.3745 10.24604 1 FALSE 1 1 1.1
## 2 105.3362 10.23442 2 FALSE 1 1 1.1
## 3 105.3154 10.26842 3 FALSE 1 1 1.1
## 4 105.3120 10.27393 4 FALSE 1 1 1.1
## 5 105.3065 10.26894 5 FALSE 1 1 1.1
## 6 105.3013 10.27698 6 FALSE 1 1 1.1
# Plotting
ggplot(data=vn, aes(x=long, y=lat, group=group)) + geom_polygon(aes(fill=id), col="grey30", show.legend=F)

# With data
pop = read_excel("~/Dropbox/Bai giang online/Map data/Province data.xlsx")
vnn = merge(vn, pop, by="id")
ggplot(data=vnn, aes(x=long, y=lat, group=group)) + geom_polygon(aes(fill=Covid19), show.legend = T) + scale_fill_gradientn(colours = c("yellow", "blue" , "blue", "red", "red")) + labs(x="Longitude", y="Latitude")

Map of Vietnam - district level
# Get the Vietnam data – provincial level
# Get the Vietnam data – district level
vnm = getData("GADM", country="Vietnam", level=2)
# Clean up data
vn = fortify(vnm, regions="VARNAME_2")
## Regions defined for each Polygons
head(vn)
## long lat order hole piece id group
## 1 105.1216 10.71159 1 FALSE 1 1 1.1
## 2 105.1147 10.71974 2 FALSE 1 1 1.1
## 3 105.1012 10.74415 3 FALSE 1 1 1.1
## 4 105.0979 10.76532 4 FALSE 1 1 1.1
## 5 105.0883 10.76043 5 FALSE 1 1 1.1
## 6 105.0882 10.76061 6 FALSE 1 1 1.1
ggplot(data=vn, aes(x=long, y=lat, group=group)) + geom_polygon(aes(fill=id), col="grey30", show.legend=F)
