knitr::opts_chunk$set( collapse = TRUE, comment = "#>", fig.path = "man/img/usage-", out.width = "100%" )
The purpose of this package is to provide geo-spatial data sets that are needed to draw regional maps of Turkey at four levels:
NUTS-Level 1: Broad geographical regions (there are 12)
NUTS-Level 2: Geographical sub-regions (there are 26)
NUTS-Level 3: Provinces (there are 81 as of 2021, these are also the largest administrative units)
District level: there are 973 districts as of 2021
The development version can be installed from GitHub using
# devtools is required # install.packages("devtools") devtools::install_github("htastan/TRmaps")
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))
ggplot(tr_nuts2) + geom_sf()
ggplot(tr_nuts3) + geom_sf()
ggplot(tr_ilce) + geom_sf()
# 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")
# 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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.