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 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
| setwd("...") library(rgdal) library(dplyr) library(tmap) library(tmaptools) rm(list = ls())
country <- readOGR("bou1_4l.shp") province <- readOGR("province_polygon.shp") sort(province$ID)
visited <- c( "Beijing", "Chongqing", "Fujian", "Guangdong", "Guangxi", "Guizhou", "Hainan", "Hebei", "Heilongjiang", "Henan", "Hubei", "Hunan", "Jiangsu", "Jiangxi", "Jilin", "Liaoning", "NeiMongol", "Shanghai", "Sichuan", "Tianjin", "Xianggang", "Yunnan", "Zhejiang")
province$ID <- as.character(province$ID) province$ID2 <- ifelse(province$ID %in% visited, "Visited", "Not Visited") province$ID2 <- as.factor(province$ID2)
country <- set_projection(country, projection = 2343) province <- set_projection(province, projection = 2343)
tm_shape(country) + tm_lines(col="dodgerblue3") + tm_shape(province) + tm_fill("ID2", title ="Provinces I have been to:", palette="Pastel2") + tm_borders("grey40", lwd = 1) + tm_scale_bar(position=c("left", "bottom")) + tm_compass(type = "4star", position=c("left", "top")) + tm_layout(inner.margins=c(0.12,0.03,0.08,0.03))
dev.off()
|