Day 4 of the #30DayMapChallenge - Hexagons

I made a hexagon tessellation of a region (e.g.Iberian Peninsula):

  1. Download country data from Eurostat.
  World_URL <- "https://ec.europa.eu/eurostat/cache/GISCO/distribution/v2/countries/download/ref-countries-2016-60m.shp.zip"
  dir.create("Rdata")
  download.file(World_URL, destfile = "Rdata/World.zip")
  unzip(zipfile = "Rdata/World.zip", exdir   = "Rdata/World")
  unzip(zipfile = "Rdata/World/CNTR_RG_60M_2016_4326.shp.zip",
        exdir   = "Rdata/World_SHP")
  World <- read_sf("Rdata/World_SHP/CNTR_RG_60M_2016_4326.shp")
  unlink("Rdata", recursive = TRUE)
  1. From the world map select Spain and Portugal (SP)
  SP <- World %>%
    filter(NAME_ENGL == "Spain" | NAME_ENGL == "Portugal") %>%
    st_cast("POLYGON") 
  1. Remove islands (e.g. Canary Islands) and small territories. I calculated the area of each polygon and then I selected the polygons which have more than 4,000 km2. Finally I merged the resulting polygons for obtaining the Iberian Peninsula (IB).
  IB <- SP %>%
    mutate(Area = units::set_units(st_area(SP), km^2)) %>%
    filter(Area > units::set_units(4000, km^2)) %>%
    st_union()
  1. Make hexagons
  Grids <- st_make_grid(IB, cellsize = .2, what = "polygons", square = FALSE) %>%
      st_sf()
  1. Plot the results
  ggplot() +
      geom_sf(data = Grids, col = "red") +
      geom_sf(data = IB, alpha = 1, colour = "black", fill = NA, size = 0.5) +
      labs(title = "Hexagon tessellation of the Iberian Peninsula") 

Javier Elío
Javier Elío
Associate Professor

My research interests include environmental sciences and data analysis.

Related