Search code examples
rggplot2choropleth

Finding regions in Choroplet map


I am trying to prepare Choropleth map for Kosovo. My intention is to map following districts/regions : Ferizaj, Gjakova,Gjilan,Mitrovica,Pecki,Pristina and Prizren.

I tried to do this with ggplot2 and below you can see my code:

library(ggplot2)
mapdata_df <- map_data("world") 

sub_set<-mapdata_df%>%
    dplyr::filter(region %in%  c("Kosovo"))

But inside in the ggplot2 although I found Kosovo I can't find names of the regions. So can anybody help me how to solve this problem and prepare choropleth map with regions ?


Solution

  • To illustrate my comment, here's how you can create a map of the different districts in Kosovo using osmdata and ggplot2:

    library(ggplot2)
    library(osmdata)
    #> Data (c) OpenStreetMap contributors, ODbL 1.0. https://www.openstreetmap.org/copyright
    
    q <- getbb("kosovo") |>
      opq() |>
      add_osm_feature(key = "admin_level", value = "4") |>
      osmdata_sf()
    
    kosovo_districts <- q |>
      purrr::pluck("osm_multipolygons") |>
      dplyr::filter(`is_in:country`=="Republic of Kosovo")
    
    ggplot(data = kosovo_districts) +
      geom_sf() +
      geom_sf_text(aes(label = `name:en`)) +
      theme_void()
    

    Which gives the output: Map of Kosovo districts

    The OpenStreetMap wiki shows which administrative level to request to return districts, and can also be modified to return national borders as well. Since the bounding box for Kosovo also returns a few district-equivalent boundaries from Serbia, I filter those out. Hope this helps you out!

    Created on 2024-03-22 with reprex v2.1.0