Purpose of the workshop

This site is prepared for the GIS workshop at Universität Wien. The main purpose of the workshop is to encourage Japanologie researchers to understand GIS and public statistics regarding Japan.

In this workshop, how to use GIS in R will be lectured by hands-on. R could be available from the following URL https://cran.r-project.org/. R studio https://www.rstudio.com/ is also recommended to use because of its beautiful GUI.

Preparation and setup

When using GIS in R, it is necessary to use several packages. In order to use packages, we need to install them by using install.packages() function like this. ggplot2 package can be installed via github.

Once you install packages, usually you don’t need to install them next time. When some of them are upgraded, it is recommended to install the packages again.

install.packages(c("maptools","classInt","RColorBrewer", "readr",
                   "magrittr","dplyr","kokudosuuchi", "estatapi",
                   "sf","purrr", "needs", "DT"))
devtools::install_github("tidyverse/ggplot2")

Installed packages becomes active by using library() function.

library(maptools)
library(classInt)
library(RColorBrewer)
library(readr)
library(magrittr)
library(dplyr)
library(kokudosuuchi)
library(estatapi)
library(sf)
library(purrr)
library(needs)
library(ggplot2)
library(DT)

magrittr() of needs package should be prioritized so that pipes %>% are available.

needs::prioritize(magrittr) 

Create a new folder named as gisdata for the working space. In this case, gisdata folder will be made under the user folder.

setwd() is used to move directory and getwd() returns the current directory.

setwd("./")
dir.create("gisdata")
setwd("gisdata")
getwd()

Once you made a working directory, you don’t need to use the first and the second line of the above chunk.

Download and visualize GIS mesh map

First of all, we download a 1km mesh estiamted population data set from Kokudo Suuchi Joho (KSJ) from MLIT (Ministry of Lnad Infrastructure and Transportation) web site and then make a thematic map of estimated population of Kanagawa in 2020.

Kokudo Suuchi Joho Web site is as following; http://nlftp.mlit.go.jp/ksj/index.html

getKSJSummary() of kokudosuuchi package provides summary information of Kokudo Suuchi Joho via API

kokudosuuchi::getKSJSummary() %>% 
  filter(title=="1kmメッシュ別将来推計人口(H29国政局推計)(shape形式版)")
## # A tibble: 1 x 5
##   identifier title                                 field1  field2 areaType
##   <chr>      <chr>                                 <chr>   <chr>  <chr>   
## 1 m1000      1kmメッシュ別将来推計人口(H29国政局推計)(shape形式版)… 各種統計… " "    3

After getting URL of Kokudo Suuchi Joho by getKSJURL(), Kokudo Suuchi Joho data could be downloaded by curl_download of curl package.

url <- kokudosuuchi::getKSJURL("m1000", prefCode = 14) %>%
  dplyr::select(zipFileUrl) %>% 
  dplyr::pull(1)
tf <- tempfile(fileext = ".zip")
curl::curl_download(url, tf)
unzip(tf, exdir = getwd(), junkpaths = TRUE)
unlink(tf)
rm(tf)

st_read of sf package is used to read ArcGIS shape files.

d <- sf::st_read('Mesh3_POP_14.shp')

Plot a map of estimated population in 2020 of Kanagawa prefecture by using ggplot2 as followings.

ggplot2::ggplot(data = d, aes(fill=POP2020)) + 
  geom_sf() + 
  scale_fill_distiller(palette="RdYlGn") + 
  theme_bw() +
  labs(title = "Population of Kanagawa in 2020 (est.)")