knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  fig.path = "man/img/usage-",
  out.width = "100%"
)

TRmaps

The purpose of this package is to provide geo-spatial data sets that are needed to draw regional maps of Turkey at four levels:

Installation

The development version can be installed from GitHub using

# devtools is required
# install.packages("devtools")
devtools::install_github("htastan/TRmaps")

Basic Usage

NUTS-1

library(TRmaps)
library(tidyverse)
library(sf)
data("tr_nuts1")
tr_nuts1

To draw a simple map, run the following code chunk:

ggplot(tr_nuts1) + 
  geom_sf()
ggplot(tr_nuts1) + 
  geom_sf(mapping = aes(fill = NUTS1_name))

NUTS-2

ggplot(tr_nuts2) + 
  geom_sf()

NUTS-3

ggplot(tr_nuts3) + 
  geom_sf()

District level

ggplot(tr_ilce) + 
  geom_sf()

Merging with your data set

NUTS-3 example

# load example data set 
data("trdata2015")
# select happiness level and province key
tr_happiness <- trdata2015 %>% 
  select(province, happiness_level)
# merge with geo-spatial data 
tr_happiness2 <- left_join(tr_nuts3, tr_happiness, by = c("name_tr" = "province"))
ggplot(tr_happiness2) + 
  geom_sf(aes(fill = happiness_level)) +
  theme_void()
# fixed and interactive maps using {tmap} package
library(tmap)
tmap_mode("plot")
tm_shape(tr_happiness2) +
  tm_polygons("happiness_level") +
  tm_layout(legend.outside = TRUE)
# uncomment for interactive map
# tmap_mode("view")
# tm_shape(tr_happiness2) +
#  tm_polygons("happiness_level")

District-level example

# load population data 
data("trpopdata_ilce")
# map of 2019 district population
ilce_pop_2019 <- trpopdata_ilce %>% 
  filter(year==2019) %>% 
  select(no, pop) 

ilce_pop_2019_comb <- left_join(tr_ilce, ilce_pop_2019, by = c("tuik_no" = "no"))
# compute population density
ilce_pop_2019_comb <- ilce_pop_2019_comb %>% 
  mutate(area = st_area(ilce_pop_2019_comb)) %>% 
  mutate(density = pop/(Shape_Area*10000), 
         logdensity = log(density))
# istanbul 
ilce_pop_2019_comb %>% filter(adm1 == "TUR034") %>%
  ggplot() +
  geom_sf(aes(fill = density)) + 
  scale_fill_viridis_c(trans = "log10", 
                       breaks=c(0,100,1000,10000)) +
  labs(fill = "Nüfus Yoğunluğu") + 
  theme_void()
# use tmap package 
# tmap_mode("view")
tm_shape(ilce_pop_2019_comb) +
tm_polygons(c("density"), style = "log10_pretty",
title = "Nüfus yoğunluğu (log)") +
  tm_layout(legend.outside = TRUE)


htastan/TRmaps documentation built on Jan. 6, 2022, 5:51 a.m.