library(RTaiwan) library(mapview) library(dplyr)
Please install and library
following packages first:
# install.packages("remotes") remotes::install_github("sheethub/RTaiwan") remotes::install_github("r-spatial/mapview") install.packages(c("dplyr")) library(RTaiwan) library(mapview) library(dplyr)
Loading the SpatialPolygonsDataFrame
objects from RTaiwan:
data(TaiwanTownArea, package = "RTaiwan")
mapview(TaiwanTownArea)
Download the populations from sheethub:
populations <- read.csv(url("https://sheethub.com/ronnywang/%E5%85%A8%E5%9C%8B%E4%BA%BA%E5%8F%A3%E7%B5%B1%E8%A8%88_%E9%84%89%E9%8E%AE%E5%B8%82%E5%8D%80_104%E5%B9%B46%E6%9C%88?format=csv"))
populations <- read.csv("populations.csv")
Join the data to the object TaiwanTownArea
populations[["鄉鎮市區代碼"]] <- as.character(populations[["鄉鎮市區代碼"]]) .data <- left_join(TaiwanTownArea@data, populations, by = c(TOWN_ID = "鄉鎮市區代碼")) TaiwanTownArea@data <- .data TaiwanTownArea <- TaiwanTownArea[!is.na(TaiwanTownArea@data[["人口數"]]),]
View the populations:
TaiwanTownArea@data[["人口級距"]] <- cut(TaiwanTownArea@data[["人口數"]], breaks = quantile(TaiwanTownArea@data[["人口數"]], seq(0, 1, by = 0.1)), include.lowest = TRUE) mapview(TaiwanTownArea, zcol = "人口級距", legend = TRUE)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.