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)
#> Package 'geokz' version 1.0.0

**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. This vignette provides multiple real-world examples of their usage.

Package installation

geokz can be installed from CRAN using

# install from CRAN
install.packages("geokz")

# Install development version from GitHub
remotes::install_github("arodionoff/geokz")

Administrative units level 1 keys

Kazakhstan is divided into 14 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)
#> 
#> Присоединяю пакет: 'dplyr'
#> Следующие объекты скрыты от 'package:stats':
#> 
#>     filter, lag
#> Следующие объекты скрыты от 'package:base':
#> 
#>     intersect, setdiff, setequal, union
library(sf)
#> Linking to GEOS 3.12.1, GDAL 3.8.4, PROJ 9.3.1; sf_use_s2() is TRUE

IQR <- data(package = "geokz")
dplyr::as_tibble(IQR$results) %>% 
  dplyr::select(Item, Title) %>% 
    dplyr::filter(grepl("kaz_adm1_sf", Item))
#> # A tibble: 1 x 2
#>   Item        Title                                                             
#>   <chr>       <chr>                                                             
#> 1 kaz_adm1_sf Map of All Administrative units level 1 (the principal units of a~

Looking at the names of kaz_adm2_sf there is 16 different variables from each rayons

names(geokz::kaz_adm1_sf)
#>  [1] "KATO"       "ADM0_EN"    "ADM0_KK"    "ADM0_RU"    "ADM0_PCODE"
#>  [6] "ADM1_EN"    "ADM1_KK"    "ADM1_RU"    "ADM1_PCODE" "ISO_3166_2"
#> [11] "Year"       "geometry"

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)
#>    ADM1_PCODE          ADM1_EN                                  ADM1_KK
#> 1        KZ10             Abay                                     Абай
#> 2        KZ11           Akmola                            А<U+049B>мола
#> 3        KZ15           Aktobe                     А<U+049B>т<U+04E9>бе
#> 4        KZ19           Almaty                                   Алматы
#> 5        KZ23           Atyrau                                   Атырау
#> 6        KZ27  West Kazakhstan            Батыс <U+049A>аза<U+049B>стан
#> 7        KZ31          Zhambyl                                   Жамбыл
#> 8        KZ33          Zhetysu                                   Жетісу
#> 9        KZ35        Karagandy                  <U+049A>ара<U+0493>анды
#> 10       KZ39         Kostanay                          <U+049A>останай
#> 11       KZ43        Kyzylorda                         <U+049A>ызылорда
#> 12       KZ47        Mangystau                  Ма<U+04A3><U+0493>ыстау
#> 13       KZ55         Pavlodar                                 Павлодар
#> 14       KZ59 North Kazakhstan Солт<U+04AF>стiк <U+049A>аза<U+049B>стан
#> 15       KZ61        Turkestan                         Т<U+04AF>ркістан
#> 16       KZ62           Ulytau                            <U+04B0>лытау
#> 17       KZ63  East Kazakhstan     Шы<U+0493>ыс <U+049A>аза<U+049B>стан
#> 18       KZ71    Astana (city)                     Астана (<U+049B>ала)
#> 19       KZ75    Almaty (city)                     Алматы (<U+049B>ала)
#> 20       KZ79  Shymkent (city)                    Шымкент (<U+049B>ала)
#>                   ADM1_RU ISO_3166_2 n
#> 1                Абайская     KZ-ABY 1
#> 2             Акмолинская     KZ-AKM 1
#> 3             Актюбинская     KZ-AKT 1
#> 4             Алматинская     KZ-ALM 1
#> 5              Атырауская     KZ-ATY 1
#> 6   Западно-Казахстанская     KZ-ZAP 1
#> 7              Жамбылская     KZ-ZHA 1
#> 8              Жетысуская     KZ-ZHT 1
#> 9          Карагандинская     KZ-KAR 1
#> 10           Костанайская     KZ-KUS 1
#> 11         Кызылординская     KZ-KZY 1
#> 12          Мангистауская     KZ-MAN 1
#> 13           Павлодарская     KZ-PAV 1
#> 14   Северо-Казахстанская     KZ-SEV 1
#> 15          Туркестанская     KZ-YUZ 1
#> 16             Улытауская     KZ-ULT 1
#> 17 Восточно-Казахстанская     KZ-VOS 1
#> 18                 Астана     KZ-AST 1
#> 19                 Алматы     KZ-ALA 1
#> 20                Чимкент     KZ-SHY 1

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.

Administrative units level 2 keys

Official administrative regions in Kazakhstan are based on rayons (the district units of principal units) or Administrative units level 2. From 2018 there are 216 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(2018 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))
#> # A tibble: 1 x 2
#>   Item        Title                                                             
#>   <chr>       <chr>                                                             
#> 1 kaz_adm2_sf Map of All Administrative units level 2 (the district units of pr~

Looking at the names of kaz_adm2_sf there is 16 different variables from each rayons

names(geokz::kaz_adm2_sf)
#>  [1] "KATO"       "ADM0_EN"    "ADM0_KK"    "ADM0_RU"    "ADM0_PCODE"
#>  [6] "ADM1_EN"    "ADM1_KK"    "ADM1_RU"    "ADM1_PCODE" "ADM2_EN"   
#> [11] "ADM2_KK"    "ADM2_RU"    "ADM2_PCODE" "ISO_3166_2" "Year"      
#> [16] "geometry"

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)
#>    ADM1_PCODE          ADM1_EN                                  ADM1_KK
#> 1        KZ10             Abay                                     Абай
#> 2        KZ11           Akmola                            А<U+049B>мола
#> 3        KZ15           Aktobe                     А<U+049B>т<U+04E9>бе
#> 4        KZ19           Almaty                                   Алматы
#> 5        KZ19          Zhetysu                                   Жетісу
#> 6        KZ23           Atyrau                                   Атырау
#> 7        KZ27  West Kazakhstan            Батыс <U+049A>аза<U+049B>стан
#> 8        KZ31          Zhambyl                                   Жамбыл
#> 9        KZ33          Zhetysu                                   Жетісу
#> 10       KZ35        Karagandy                  <U+049A>ара<U+0493>анды
#> 11       KZ39         Kostanay                          <U+049A>останай
#> 12       KZ43        Kyzylorda                         <U+049A>ызылорда
#> 13       KZ47        Mangystau                  Ма<U+04A3><U+0493>ыстау
#> 14       KZ55         Pavlodar                                 Павлодар
#> 15       KZ59 North Kazakhstan Солт<U+04AF>стiк <U+049A>аза<U+049B>стан
#> 16       KZ61        Turkestan                         Т<U+04AF>ркістан
#> 17       KZ62           Ulytau                            <U+04B0>лытау
#> 18       KZ63  East Kazakhstan     Шы<U+0493>ыс <U+049A>аза<U+049B>стан
#> 19       KZ71    Astana (city)                                   Астана
#> 20       KZ75    Almaty (city)                     Алматы (<U+049B>ала)
#> 21       KZ79  Shymkent (city)                                  Шымкент
#>                   ADM1_RU ISO_3166_2  n
#> 1                Абайская     KZ-ABY 12
#> 2             Акмолинская     KZ-AKM 20
#> 3             Актюбинская     KZ-AKT 13
#> 4             Алматинская     KZ-ALM 11
#> 5              Жетысуская     KZ-ALM  2
#> 6              Атырауская     KZ-ATY  8
#> 7   Западно-Казахстанская     KZ-ZAP 13
#> 8              Жамбылская     KZ-ZHA 11
#> 9              Жетысуская     KZ-ZHT 10
#> 10         Карагандинская     KZ-KAR 13
#> 11           Костанайская     KZ-KUS 20
#> 12         Кызылординская     KZ-KZY  9
#> 13          Мангистауская     KZ-MAN  7
#> 14           Павлодарская     KZ-PAV 13
#> 15   Северо-Казахстанская     KZ-SEV 14
#> 16          Туркестанская     KZ-YUZ 16
#> 17             Улытауская     KZ-ULT  5
#> 18 Восточно-Казахстанская     KZ-VOS 11
#> 19                 Астана     KZ-AST  5
#> 20                 Алматы     KZ-ALA  8
#> 21                Чимкент     KZ-SHY  5

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.

Administrative units level 3 keys

In the Administrative units 3 level there are 47 cities of regional significance, 4 urban districts (2 each in the cities of regional significance Karaganda and Aktobe), 26 village administrations (akimats), 2283 rural district akimats and 82 rural akimats.

Centers of Administrative units level 2

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 (2019 version).

Looking at the names of kaz_cnt1_sf there is 15 different variables from each centers.

names(geokz::kaz_cnt1_sf)
#>  [1] "KATO"       "ADM0_EN"    "ADM0_KK"    "ADM0_RU"    "ADM0_PCODE"
#>  [6] "ADM1_EN"    "ADM1_KK"    "ADM1_RU"    "ADM1_PCODE" "TYPE_CNT1" 
#> [11] "ISO_3166_2" "NAME_EN"    "NAME_KK"    "NAME_RU"    "geometry"

Spatial data

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:

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 borders

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 <- "\u041d\u04b1\u0440-\u0421\u04b1\u043b\u0442\u0430\u043d (\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>'\u041d\u04b1\u0440-\u0421\u04b1\u043b\u0442\u0430\u043d (\u049b\u0430\u043b\u0430)'</b>")
#> Warning in get_kaz_oblasts_map(ADM1_KK = x): The Conditions you defined
#> specified an empty dataset of geographic features
Administrative unit level 1 - The Capital (kaz. ‘Нұр-Сұлтан (қала)’
KATO ADM1_EN ADM1_KK ADM1_RU ADM1_PCODE ISO_3166_2

Rayon borders

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.

Centers of Administrative units 1 Level

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.

Use several packages for mapping ({tmap}, {ggplot2}, {leaflet})

Package {tmap}: Joining attribute data with geokz data

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.

Population Density of Kazakhstan (2021)


library(geokz)
library(dplyr)
library(knitr)

Population_Density_df <- 
  data.frame(
    ISO_3166_2 = c("KZ-AKM", "KZ-AKT", "KZ-ALM", "KZ-ATY", "KZ-VOS", "KZ-ZHA", "KZ-KAR", "KZ-KUS", "KZ-KZY", "KZ-MAN", "KZ-SEV", "KZ-PAV", "KZ-YUZ", "KZ-ZAP", "KZ-AST", "KZ-ALA", "KZ-SHY"), 
    Region = c("Akmola Region", "Aktobe Region", "Almaty Region", "Atyrau Region", "East Kazakhstan Region", "Jambyl Region", "Karaganda Region", "Kostanay Region", "Kyzylorda Region", "Mangystau Region", "North Kazakhstan Region", "Pavlodar Region", "Turkistan Region", "West Kazakhstan Region", "Nur-Sultan", "Almaty", "Shymkent"),
    Area = c(146219, 300629, 223924, 118631, 283226, 144264, 427982, 196001, 226019, 165642, 97993, 124800, 117249, 151339, 710, 319, 1170),
    Population = c(735481, 893669, 2077656, 657118, 661172, 1139151, 1375788, 864529, 814461, 719559, 751011, 543679, 2044551, 1363656, 1184469, 1977011, 1074167)
) %>% 
  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 = ' '))
Demographic statistics of Kazakhstan
ISO_3166_2 Region Area Population Population_Density
KZ-AKM Akmola Region 146 219 735 481 5.0
KZ-AKT Aktobe Region 300 629 893 669 3.0
KZ-ALM Almaty Region 223 924 2 077 656 9.3
KZ-ATY Atyrau Region 118 631 657 118 5.5
KZ-VOS East Kazakhstan Region 283 226 661 172 2.3
KZ-ZHA Jambyl Region 144 264 1 139 151 7.9
KZ-KAR Karaganda Region 427 982 1 375 788 3.2
KZ-KUS Kostanay Region 196 001 864 529 4.4
KZ-KZY Kyzylorda Region 226 019 814 461 3.6
KZ-MAN Mangystau Region 165 642 719 559 4.3
KZ-SEV North Kazakhstan Region 97 993 751 011 7.7
KZ-PAV Pavlodar Region 124 800 543 679 4.4
KZ-YUZ Turkistan Region 117 249 2 044 551 17.4
KZ-ZAP West Kazakhstan Region 151 339 1 363 656 9.0
KZ-AST Nur-Sultan 710 1 184 469 1 668.3
KZ-ALA Almaty 319 1 977 011 6 197.5
KZ-SHY Shymkent 1 170 1 074 167 918.1

dplyr::inner_join( x = get_kaz_oblasts_map( Year = 2021L ),
                   y = Population_Density_df[, c("ISO_3166_2", "Population_Density")],
                   by = c("ISO_3166_2" = "ISO_3166_2") ) %>% 
  tmap::qtm(
    shp = ., 
    fill = "Population_Density", 
    fill.n = 6,
    fill.style = "quantile",
    fill.text  = "Population_Density",
    fill.title = "Плотность \nнаселения \n(чел. на кв. м)",
    text = "Population_Density",
    title = "Плотность населения Казахстана (2021)",
    format = "World"
    )

Toning of District maps


if (requireNamespace(c("colorspace"), quietly = TRUE)) {

  adm1 <- kaz_adm1_sf
  adm2 <- kaz_adm2_sf
  
  set.seed(3)
  # Создаем цветовую палитру для областей
  Palette <- sample(tmaptools::get_brewer_pal("Spectral", n = 30, plot = FALSE), length(unique(adm1$ADM1_EN)), replace = FALSE) %>% 
    setNames(adm1$ADM1_EN)
  
  # Добавляем столбец с цветами для областей
  adm1$color <- Palette
  
  # Добавляем столбец с цветами для районов, используя цвет области и добавляя оттенок серого
  adm2$color <- adm1$color[match(adm2$ADM1_EN, adm1$ADM1_EN)]
  adm2$brightness <- sample(seq(from = 0.1, to = 0.5, length.out = 20), size = length(unique(adm2$KATO)), replace = TRUE)
  
  adm2 <- 
    adm2 %>% 
      dplyr::mutate(color = colorspace::lighten(color, brightness))
  
  # Создаем карту областей с разными цветами
  adm_map <- 
  # Добавляем районы на карту, используя цвет области и добавляя оттенок серого
    tmap::tm_shape(adm1) +
      tmap::tm_polygons('ADM1_EN', legend.show = TRUE, title = "ADM1 Objects") +
    tmap::tm_shape(adm2) +
      tmap::tm_fill(col = "color", by = "ADM2_EN") +
      tmap::tm_borders() +
    tmap::tm_shape(adm1) +
      tmap::tm_borders(col = "grey20", lwd = 2) +
      tmap::tm_text('ADM1_EN', size = 1.5, shadow = TRUE) + 
    tmap::tm_format(format = 'World') +
    tmap::tm_layout(
      main.title = "Kazakhstan",
      main.title.size = 2,
      legend.outside = TRUE,
      legend.title.size = 2,
      legend.text.size = 1.3
    )
  
  # Выводим карту
  print(adm_map)
  
}

Zones are distinguished according to natural conditions

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 = ' '))
Administrative units level 2 by Zones according to natural conditions
ZONE_EN n
Steppe 40
Dry-steppe 52
Foothill-desert-steppe 57
Desert 29
South Siberian mountain and foothill 9
Semi-desert 29
TOTAL 216

dplyr::inner_join( x = get_kaz_rayons_map(Year = 2018L),
                   y = natural_zones[, c("ADM2_PCODE", "ZONE_RU")],
                   by = c("ADM2_PCODE" = "ADM2_PCODE") ) %>%
tmap::tm_shape(shp = .) +
  tmap::tm_polygons(
    col = "ZONE_RU",
    title = "Зоны согласно \nприродным \nусловиям"
  ) +
tmap::tm_shape(shp = get_kaz_oblasts_map()) +
  tmap::tm_borders(col = "red", lwd = 3) +
tmap::tm_format(format = 'World_wide') +  
tmap::tm_layout(main.title = "Зоны Казахстана, согласно природным условиям") +
tmap::tm_credits('Источник: Министерство сельского хозяйства РК', 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(file = ., 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(data = .) +
  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

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(Year = 2018L, 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(Year = 2018L, 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 = "Қазіргі \nаудандар",
    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 = "Торғай облысы (1970-1988, 1990-1997)",
    main.title.size = 0.9,
    legend.position = c("left", "top")
  )

Interactive map using {tmap} package in view mode

See use {tmap} & {leaflet} packages for draw of Interactive Maps as sf objects.

Package {ggplot2}: Flexibility in each of the layers and many aspects of visualisation

Kazakhstan: Administrative units level 1 (Oblasts & Cities of Republican Significance)

library(ggplot2)
library(dplyr)

get_kaz_oblasts_map() %>%
  dplyr::mutate(ADM1_EN = factor(ADM1_EN, levels = ADM1_EN)) %>%
  ggplot2::ggplot(data = .) +
    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
    )

Kazakhstan: Mangystau Oblast (Rayons & Cities of Oblast Significance)

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(data = .) +
    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
    )

Kazakhstan: Kyzylorda Oblast (Administrative Center, Rayons & City of Republican Significance)

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(data = .) +
    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
      )

Package {leaflet}: Interactive map widget using htmlwidgets

Interactive Map of Kazakhstan with the Capitals

See use {leaflet} package for draw of Interactive Maps as sf objects.

Interactive Map of Kazakhstan with Rayons

See use {leaflet} package for draw of Interactive Maps as sf objects.