knitr::opts_chunk$set( collapse = FALSE, comment = "#>" )
packages <- c("devtools", "testthat", "dplyr", "ggplot2", "sf", "magrittr", "RColorBrewer", "leaflet", "tmap", "usethis") utils::install.packages(base::setdiff(packages, base::rownames(utils::installed.packages()))) # R ver. 3.6.2 library(geokz)
geokz
-package provides access to multiple dataset of different types and for different use. In this vignette we introduce the different datas and explain their use cases. Vignette Making maps using {geokz}-package provides multiple real-world examples of their usage.
geokz
can be installed from GitHUB using
# Install development version from GitHub devtools::install_github("arodionoff/geokz") # Install development version from GitHub with vignette devtools::install_github("arodionoff/geokz", build_vignettes = TRUE)
Kazakhstan is divided into 17 regions (Kazakh: облыстар/oblystar; singular: облыс/oblys; Russian: области/oblasti; singular: область/oblast' ), the Capital - Nur-Sultan (formerly Astana) and 3 Cities of Republican Significance (Almaty, Shymkent and also Baikonyr, near is the World's First spaceport).
library(geokz) library(dplyr) library(sf) IQR <- data(package = "geokz") dplyr::as_tibble(IQR$results) |> dplyr::select(Item, Title) |> dplyr::filter(grepl("kaz_adm1_sf", Item))
Looking at the names of kaz_adm1_sf
there is r prettyNum( ncol(geokz::kaz_adm1_sf) )
different variables from each Oblast.
names(geokz::kaz_adm1_sf)
With these Oblast keys you can easily filter Oblasts for plotting or you can list different regional (Multi-Oblast) breakdowns.
geokz::kaz_adm1_sf |> sf::st_drop_geometry() |> dplyr::count(ADM1_PCODE, ADM1_EN, ADM1_KK, ADM1_RU, ISO_3166_2)
kaz_adm1_sf
keys are joined with the oblast spatial data (geographic features) by default, meaning that data returned by get_kaz_oblasts_map()
can be aggregated as it is.
Official administrative regions in Kazakhstan are based on rayons (the district units of principal units) or Administrative units level 2. From 2024 there are 228 rayons (equivalent territories, for example, related to city administrations - City of Oblast Significance and Rayons of Cities of Republican Significance) and the number has been increasing since the reorganization of Kazakhstan in 1997 through the division of districts.
Each rayons belongs to a higher level regional classifications such as regions (Oblast) or Administrative units level 1. kaz_adm2_sf
- datasets are based on Kazakhstani administrative division Statistical classification(2024 version) with few modification and provided on yearly basis.
Note, the large cities with more than 400 thousand inhabitants (now, Aktobe and Karaganda) also have regional divisions, but such districts are not considered separate administrative units of the 3 level, but are referred to the 3 level, like rural districts with 5-10 settlements.
IQR <- data(package = "geokz") dplyr::as_tibble(IQR$results) |> dplyr::select(Item, Title) |> dplyr::filter(grepl("kaz_adm2_sf", Item))
Looking at the names of kaz_adm2_sf
there is r prettyNum( ncol(geokz::kaz_adm2_sf) )
different variables from each rayons
names(geokz::kaz_adm2_sf)
With these rayon keys you can easily aggregate rayons for plotting or you can list different regional (Oblast) breakdowns.
geokz::kaz_adm2_sf |> sf::st_drop_geometry() |> dplyr::count(ADM1_PCODE, ADM1_EN, ADM1_KK, ADM1_RU, ISO_3166_2)
kaz_adm2_sf
keys are joined with the rayon spatial data (geographic features) by default, meaning that data returned by get_kaz_rayons_map()
can be aggregated as it is.
There is a three-level administrative division in Kazakhstan. Akimats of villages, rural and settlement districts, cities of district (Aktobe & Karaganda) and regional significance belong to units of administrative-territorial division of the third level. There were 2169 administrative-territorial units 3 level in 2024 year and subordinate villages - 6256.
The coverage on Centers of Administrative units level 2 including the Capital Nur-Sultan (formerly Astana), 3 Cities of Republican Significance (Almaty, Shymkent and also Baikonur or Baykonyr, near is the World's First Spaceport) and all center of Oblasts (the principal units of a country) of Kazakhstan (2024 version).
Looking at the names of kaz_cnt1_sf there is r prettyNum( ncol(geokz::kaz_cnt1_sf) )
different variables from each centers.
names(geokz::kaz_cnt1_sf)
Spatial data is provided as administrative regions (polygons) and administrative district (polygons) and region centers (points).
You can use ESRI ArcGIS shapefiles (*.cpg, *.dbf, *.prj, *.shp, *.shx) load as shape
subdirectory directly or by coverages in 2018 Year:
You can use ESRI ArcGIS shapefiles (*.cpg, *.dbf, *.prj, *.shp, *.shx) load as shape
subdirectory directly or by coverages in 2024 Year:
The Default Projection in functions uses A Lambert Conformal Conic (LCC) with Krasovsky 1940 ellipsoid and First standard parallel - 45 N, Second standard parallel - 51 N, Longitude of projection center - 67 E, Latitude of projection center - 48 N.
Oblast and Cities of Republican Significance borders are provided yearly from 2018.
rayons <- get_kaz_oblasts_map() plot(rayons["ADM1_EN"], border = NA, main = "Maps of All Kazakhstani Administrative units level 1 - Oblasts")
Source: The Centre for Humanitarian Data is managed by the United Nations Office for the Coordination of Humanitarian Affairs (OCHA).
Use can use names of Regions in different languages (English, Russian or Kazakh) for filtering and binding geographic features. Non-latin characters you can convert into Unicode (not ASCII-printable) code points, for example, cat(stringi::stri_escape_unicode("Астана (қала)"))
.
x <- "\u0410\u0441\u0442\u0430\u043d\u0430 (\u049b\u0430\u043b\u0430)" get_kaz_oblasts_map(ADM1_KK = x) |> dplyr::select("KATO", "ADM1_EN", "ADM1_KK", "ADM1_RU", "ADM1_PCODE", "ISO_3166_2") |> sf::st_drop_geometry() |> knitr::kable(caption = "Administrative unit level 1 - \nThe Capital (kaz. <b>'\u0410\u0441\u0442\u0430\u043d\u0430 (\u049b\u0430\u043b\u0430)'</b>")
Rayon and Cities of Republican Significance borders are provided by 2018 version.
rayons <- get_kaz_rayons_map() plot(rayons["ADM2_EN"], border = NA, main = "Maps of All Kazakhstani Administrative units level 2 - Rayons")
Source: The Centre for Humanitarian Data is managed by the United Nations Office for the Coordination of Humanitarian Affairs (OCHA). The borders of districts were corrected by Alexander Rodionov in QGIS.
Oblast Centers and Cities of Republican Significance borders are provided yearly from 2019 after renaming Astana into Nur-Sultan.
# EPSG:4326 or WGS84 - see https://github.com/r-spatial/sf/issues/1419 sf::st_crs(x = kaz_cnt1_sf) <- 4326L kaz_cnt1_sf <- sf::st_transform(x = kaz_cnt1_sf, crs = "+proj=lcc +lon_0=67 +lat_1=45 +lat_2=51 +ellps=krass") kaz_cnt1_sf$punch <- (5 - kaz_cnt1_sf$TYPE_CNT1) # adding to a plot of an sf object only works when using reset=FALSE in the first plot plot(x = get_kaz_oblasts_map()["ADM1_EN"], reset = FALSE, cex.main = 1.0, main = "KAZ: The Capital, Cities of Republican Significance & Oblast Centers (ADM1)") plot(kaz_cnt1_sf["KATO"], col = "red", pch = "o", add = TRUE)
The cities mapped by Alexander Rodionov in QGIS.
This vignettes provides few examples on how to join attribute data from common sources of attribute data. Here we are using data from two different sources of The Bureau of National Statistics of the Agency for Strategic Planning and Reforms of the Republic of Kazakhstan: the Population of the Republic of Kazakhstan and the Area of Kazakhstani Regions. Third is Zones of Kazakhstan are distinguished according to natural conditions.
# library(geokz) library(dplyr) library(knitr) Population_Density_df <- data.frame( ISO_3166_2 = c("KZ-ABY", "KZ-AKM", "KZ-AKT", "KZ-ALM", "KZ-ATY", "KZ-ZAP", "KZ-ZHA", "KZ-ZHT", "KZ-KAR", "KZ-KUS", "KZ-KZY", "KZ-MAN", "KZ-PAV", "KZ-SEV", "KZ-YUZ", "KZ-ULT", "KZ-VOS", "KZ-AST", "KZ-ALA", "KZ-SHY"), Region = c("Abay Oblast", "Akmola Oblast", "Aktobe Oblast", "Almaty Oblast", "Atyrau Oblast", "West Kazakhstan Oblast", "Zhambyl Oblast", "Zhetysu Oblast", "Karagandy Oblast", "Kostanay Oblast", "Kyzylorda Oblast", "Mangystau Oblast", "Pavlodar Oblast", "North Kazakhstan Oblast", "Turkestan Oblast", "Ulytau Oblast", "East Kazakhstan Oblast", "Astana (city)", "Almaty (city)", "Shymkent (city)"), Area = c(185500, 146219, 300629, 105100, 118631, 151339, 144264, 118500, 239100, 196001, 226019, 165642, 124800, 97993, 116100, 188900, 97700, 797, 682, 1163), Population = c(610183, 786012, 924845, 1497025, 689674, 686655, 1215482, 698952, 1134146, 832445, 830901, 761401, 754829, 534966, 2110502, 221014, 730818, 1340782, 2147113, 1184113) ) |> dplyr::mutate(Population_Density = round( Population / Area, 1)) knitr::kable(Population_Density_df, caption = 'Demographic statistics of <b>Kazakhstan</b>', format.args = list(big.mark = ' ')) dplyr::inner_join( x = get_kaz_oblasts_map(), y = Population_Density_df[, c("ISO_3166_2", "Population_Density")], by = c("ISO_3166_2" = "ISO_3166_2") ) |> tmap::qtm( fill = "Population_Density", fill.n = 6, fill.style = "quantile", fill.text = "Population_Density", fill.title = "Population Density \n(people per sq.km)", text = "Population_Density", title = "Population Density of Kazakhstan (2024)", format = "World" )
The territory of Kazakhstan is located in four climatic zones - forest-steppe, steppe, semi-desert and desert. The presence of mountains in the south and east of the country leads to the emergence of the allocation of special mountainous regions, significantly different from the surrounding area. So on the territory of the Republic 6 zones are distinguished according to natural conditions: Steppe (1), Dry-steppe (2), Foothill-desert-steppe (3), Desert (4), South Siberian mountain and foothill (5), Semi-desert (6).
data(natural_zones) natural_zones |> dplyr::count(ZONE_EN) |> dplyr::bind_rows(data.frame( ZONE_EN = "TOTAL", n = nrow(natural_zones))) |> knitr::kable(caption = "Administrative units level 2 by Zones according to <b>natural conditions</b>", format.args = list(big.mark = ' ')) dplyr::inner_join( x = get_kaz_rayons_map(Year = 2018L), y = natural_zones[, c("ADM2_PCODE", "ZONE_EN")], by = c("ADM2_PCODE" = "ADM2_PCODE") ) |> tmap::tm_shape() + tmap::tm_polygons( col = "ZONE_EN", title = "Zones according \nto natural conditions" ) + tmap::tm_shape(shp = get_kaz_oblasts_map(Year = 2018L)) + tmap::tm_borders(col = "red", lwd = 3) + tmap::tm_format(format = 'World_wide') + tmap::tm_layout(main.title = "Zones are distinguished according to natural conditions") + tmap::tm_credits('Source: package {geokz}', position = c('right', 'BOTTOM'))
However even such a division adopted by the Ministry of Agriculture does not reflect the presence of desert and foothill-desert lands with a subtropical climate, which occupy up to 8% of the country's area.
Loading Raw data as Comma Separated Value file and join to Geographic coverage for mapping Zones according to natural conditions.
natural_zones_df <- system.file("extdata", "kaz_zones.csv", package = "geokz", mustWork = FALSE) if (natural_zones_df == "") { natural_zones_df <- utils::read.csv(paste0("inst/extdata/", "kaz_zones.csv"), encoding = "UTF-8") } else { natural_zones_df <- system.file("extdata", "kaz_zones.csv", package = "geokz", mustWork = TRUE) |> utils::read.csv(encoding = "UTF-8") } Zones_EN_labels <- c("Steppe", "Dry-steppe", "Foothill-desert-steppe", "Desert", "South Siberian mountain and foothill", "Semi-desert") Zones_pallete <- c("yellowgreen", "khaki", "darkolivegreen1", "peachpuff2", "olivedrab", "navajowhite") |> stats::setNames(Zones_EN_labels) dplyr::inner_join( x = get_kaz_rayons_map( Year = 2018L ), y = natural_zones_df[, c("ADM2_PCODE", "ZONE_EN")], by = c("ADM2_PCODE" = "ADM2_PCODE") ) |> dplyr::mutate(KATO = as.character(KATO), ZONE_EN = factor(ZONE_EN, levels = Zones_EN_labels)) |> ggplot2::ggplot() + ggplot2::geom_sf(mapping = ggplot2::aes(fill = ZONE_EN)) + # Rayons - Zones by natural conditions ggplot2::geom_sf( # Boundaries of Kazakhstani Oblasts data = sf::st_geometry(get_kaz_oblasts_map()), fill = NA, color = "red", size = 1.25, show.legend = FALSE ) + ggplot2::scale_fill_manual( values = Zones_pallete, name = "Zones according \nto natural conditions" ) + ggplot2::theme_light() + ggplot2::labs(title = "Zones are distinguished according to natural conditions", x = NULL, y = NULL )
Torgay Oblast is disbanded Region of the Kazakh Soviet Socialist Republic from 1970 to 1988 and of independent Kazakhstan and from 1990 to 1997.
Unfortunetely, simultaneous use of several types of geographic features codes or names in different languages is not allowed.
Fortunetely, Simultaneous use of several types of International & National codes or names in different languages is allowed with binding geographic features.
Torgay_Region <- get_kaz_rayons_map(ADM2_EN = c( "Esil", "Zhaksy", "Zharkain")) |> dplyr::filter(ADM1_EN == "Akmola") |> # There are three rayons named Esil by Esil (Ishim) river dplyr::bind_rows( get_kaz_rayons_map(ADM2_PCODE = c( "KZ391600", # Arkalyk city was a Center of Torgay Oblast "KZ393400", # Amangeldi rayon "KZ394200") # Zhangeldi rayons ) ) |> dplyr::mutate(ADM2_EN = factor(ADM2_EN, levels = ADM2_EN)) center_sf <- data.frame( NAME = c("Arkalyk"), BRANCH = c("The Center"), LINK = c("https://en.wikipedia.org/wiki/Arkalyk"), LAT = c(50.24861), LON = c(66.91139) ) |> sf::st_as_sf( coords = c("LON", "LAT"), # columns with geometry by x - "LON" and y - "LAT" crs = "+proj=longlat +datum=WGS84" ) to_bb <- Torgay_Region |> sf::st_bbox() |> sf::st_as_sfc() |> sf::st_buffer(dist = 50000) tmap::tm_shape(Torgay_Region) + tmap::tm_polygons( col = "ADM2_EN", border.col = "grey", title = "Administrative \nunits level 2", labels = Torgay_Region$ADM2_KK ) + tmap::tm_text("ADM2_KK", col = "gray10", size = 0.9, shadow = TRUE) + tmap::tm_shape( shp = get_kaz_oblasts_map(), bbox = to_bb ) + tmap::tm_borders( col = "red", lwd = 4 ) + tmap::tm_text("ADM1_KK", col = "gray10", size = 1.2, shadow = TRUE) + tmap::tm_shape(center_sf) + tmap::tm_dots(size = 1) + tmap::tm_graticules(lines = FALSE) + tmap::tm_format(format = 'World') + tmap::tm_layout( main.title = "Disbanded Torgay Oblast (1970-1988, 1990-1997)", main.title.size = 0.9, legend.position = c("left", "top") ) + tmap::tm_credits('Source: package {geokz}', position = c('right', 'bottom'), size = 1.2)
See use {tmap} & {leaflet} packages for draw of Interactive Maps as sf
objects.
library(ggplot2) library(dplyr) get_kaz_oblasts_map() |> dplyr::mutate(ADM1_EN = factor(ADM1_EN, levels = ADM1_EN)) |> ggplot2::ggplot() + ggplot2::geom_sf(mapping = ggplot2::aes(fill = ADM1_EN)) + # forcats::fct_inorder(ADM1_EN) ggplot2::geom_sf_text(mapping = ggplot2::aes(label = ADM1_EN)) + ggplot2::theme_bw() + ggplot2::guides(fill = ggplot2::guide_legend(title = "Administrative \nunits level 1")) + ggplot2::labs(title = "Kazakhstan: Administrative units level 1 (Oblasts & Cities of Republican Significance)", x = NULL, y = NULL )
library(dplyr) library(ggplot2) library(RColorBrewer) data(kaz_adm2_sf) # EPSG:4326 or WGS84 - see https://github.com/r-spatial/sf/issues/1419 sf::st_crs(x = kaz_adm2_sf) <- 4326L kaz_adm2_sf |> dplyr::filter(ADM1_EN =="Mangystau") |> dplyr::mutate(ADM2_EN = factor(ADM2_EN, levels = ADM2_EN)) |> ggplot2::ggplot() + ggplot2::geom_sf(mapping = ggplot2::aes(fill = ADM2_EN)) + # forcats::fct_inorder(ADM2_EN) ggplot2::geom_sf_text( mapping = ggplot2::aes(label = ADM2_EN), size = 3 ) + ggplot2::coord_sf(crs=2499) + # Pulkovo 1942 / Gauss-Kruger CM 51E. See <https://epsg.io/2499>. ggplot2::scale_fill_brewer(palette = "Pastel2") + # uses library(RColorBrewer) ggplot2::theme_light() + ggplot2::guides(fill = ggplot2::guide_legend(title = "Administrative \nunits level 2")) + ggplot2::labs(title = "Kazakhstan: Mangystau Oblast (Rayons & Cities of Oblast Significance)", x = NULL, y = NULL )
library(dplyr) library(sf) library(ggplot2) data(kaz_adm0_sf) data(kaz_adm1_sf) data(kaz_adm2_sf) data(kaz_cnt1_sf) # EPSG:4326 or WGS84 - see https://github.com/r-spatial/sf/issues/1419 sf::st_crs(x = kaz_adm0_sf) <- 4326L sf::st_crs(x = kaz_adm1_sf) <- 4326L sf::st_crs(x = kaz_adm2_sf) <- 4326L sf::st_crs(x = kaz_cnt1_sf) <- 4326L ko_bb <- dplyr::filter(kaz_adm1_sf, ADM1_EN == 'Kyzylorda') |> sf::st_transform(crs = 2501) |> # Pulkovo 1942 / Gauss-Kruger CM 63E. See <https://epsg.io/2501>. sf::st_bbox() |> sf::st_as_sfc() |> sf::st_buffer(dist = 30000) kaz_adm2_sf |> dplyr::filter(ADM1_EN =="Kyzylorda") |> dplyr::mutate(ADM2_EN = factor(ADM2_EN, levels = ADM2_EN)) |> ggplot2::ggplot() + ggplot2::geom_sf( # Boundaries of Kazakhstani Oblasts data = sf::st_geometry(kaz_adm1_sf), color = "red", size = 1 ) + ggplot2::geom_sf( # Rayons of Kyzylorda Oblasts mapping = ggplot2::aes(fill = ADM2_EN) ) + # forcats::fct_inorder(ADM2_EN) ggplot2::geom_sf_text( # Labels of Rayons data = dplyr::filter(kaz_adm2_sf, (ADM1_EN == 'Kyzylorda' & magrittr::and(ADM2_EN != "Kyzylorda", ADM2_EN != "Baykonyr"))), mapping = ggplot2::aes(label = ADM2_EN), size = 2.5 ) + ggplot2::scale_fill_brewer(palette = "Pastel1") + ggplot2::geom_sf( # Administrative Center & City of Republican Significance data = dplyr::filter(kaz_cnt1_sf, ADM1_EN == 'Kyzylorda'), size = 3, col = "red", shape = 19 ) + ggplot2::geom_sf_text( # Labels of Cities data = dplyr::filter(kaz_cnt1_sf, ADM1_EN == 'Kyzylorda'), mapping = ggplot2::aes(label = NAME_EN), nudge_x = 65000, nudge_y = -9000, size = 4 ) + ggplot2::geom_sf( # Boundaries of Kazakhstan data = sf::st_geometry(kaz_adm0_sf), alpha = 0, color = "brown", size = 2 ) + # Set new Coordinate System: Pulkovo 1942 / Gauss-Kruger CM 63E. See <https://epsg.io/2501>. ggplot2::coord_sf(xlim = c(sf::st_bbox(ko_bb)$xmin, sf::st_bbox(ko_bb)$xmax), ylim = c(sf::st_bbox(ko_bb)$ymin, sf::st_bbox(ko_bb)$ymax), crs = 2501, expand = FALSE) + ggplot2::theme_linedraw() + ggplot2::guides(fill = ggplot2::guide_legend(title = "Administrative \nunits level 2")) + ggplot2::labs(title = "Kazakhstan: Kyzylorda Oblast (Administrative Center, Rayons & City of Republican Significance)", x = NULL, y = NULL )
See use {leaflet} package for draw of Interactive Maps as sf
objects.
See use {leaflet} package for draw of Interactive Maps as sf
objects.
You can create Interactive Maps with hyperlinks to Wikipedia articles about Kazakhstani Regions. Basemap can be varied from a list of providers.
library(leaflet) library(magrittr) urls <- c("Abay_Region", "Aqmola_Region", "Aqtobe_Region", "Almaty_Region", "Atyrau_Region", "West_Kazakhstan_Region", "Jambyl_Region", "Jetisu_Region", "Karaganda_Region", "Kostanay_Region", "Kyzylorda_Region", "Mangystau_Region", "Pavlodar_Region", "North_Kazakhstan_Region", "Turkistan_Region", "Ulytau Region", "East_Kazakhstan_Region", "Astana", "Almaty", "Shymkent") leaflet::leaflet() |> leaflet::addProviderTiles(provider = "Esri.WorldPhysical") |> leaflet::addPolygons( data = sf::st_zm(kaz_adm1_sf, geometry), weight = 1, color = "darkred", fillColor = "coral", fillOpacity = 0.3, smoothFactor = 0.5, popup = ~paste0("Region: ", '<a href = "https://en.wikipedia.org/wiki/', urls, '"> ', ADM1_EN, "</a><br>", "KATO: ", KATO, "<br>", "ISO 3166-2: ", ISO_3166_2), label = ~paste(ADM1_EN, ":", ADM1_PCODE), labelOptions = labelOptions(direction = "auto") ) |> leaflet::addCircleMarkers( data = kaz_cnt1_sf, color = "brown", radius = 3, label = ~paste0("Center of ", ADM1_EN,": ", NAME_EN) )
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.