The Greek Secretariat General of Information and Communication released data on the refugee population recorded in the country. This includes all the sites where refugees are recorded, along with current capacity levels per site. This is a snapshot (06/03/16) of the situation, when the borders first closed and more than 33.000 people were recorded. The data represents recorded refugees, from the Greek Islands to Athens, and then their journey north, where they concentrate at the F.Y.R.O.M. borders.
Here we provide a simple example with the above data in an interactive map using R and leaflet integration. The code below creates an interactive map of the occupancy levels of these sites across the region, but first, let’s take a closer look at the data.
# Controls the maximum number of columns on a line used in printing vectors
options(width = 90)
# Read the data into R
refugee_060316 <- read.csv("refugee_060316.csv")
# Calculate hot-spot occupancy levels as capacity ratio.
refugee_060316$Occupancy <- with(refugee_060316, ifelse(Capacity == 0, NA, Pop/Capacity))
# Table View
head(refugee_060316)
## ID Longitude Latitude Name Full_Name Pop Capacity Occupancy
## 1 1 26.50915 39.13270 Lesbos Lesbos, All Sites 3550 3500 1.0142857
## 2 2 26.99074 37.74141 Samos Samos 489 850 0.5752941
## 3 3 26.12182 38.37891 Chios Chios 1422 1100 1.2927273
## 4 4 29.58873 36.14868 Kastelorizo Megisti, Kastelorizo 316 0 NA
## 5 5 27.28055 36.89026 Kos Kos 124 1000 0.1240000
## 6 6 26.85247 37.13553 Leros Leros 310 1000 0.3100000
Since we have Longitude and Latitude corrdinates, we can easily create an interactive map to plot the points using the leaflet library, available on CRAN.
library(leaflet)
library(RColorBrewer)
We don’t want to use a simple shape to represent the camp points, so we will use a custom one. You can either select to supply leaflet with a local image file to use as an icon image, or use a URL to the image file directly. We also use the RColorBrewer library to create a custom palette for the visualization.
# Select Camp Icons
camp_icons <- icons(
iconUrl = 'Camping_gear_1-64.png',
iconWidth = 24, iconHeight = 24,
)
# Select a colour palette with 8 colours from the red-yellow-green palette.
colpal <- rev(brewer.pal(8,"RdYlGn"))
Next, we create a map “widget’ object using leaflet(). There is a variety of graphics that can be passed to the map. For instance, a tile layer can be passed with addTiles() or addProviderTiles() to change the backdrop. This can be effectively done with %>% to pipe objects down and add elements to the map. Otherwise you can just add elements to the basic map the conventional way, i.e. by overwriting the original map object. In this case we use the latter.
# Create Map
rfg_map <- leaflet(refugee_060316, width = 690, height = 460) %>% addTiles()
# Create the markers and labels
rfg_map <- addMarkers(rfg_map, lng = ~Longitude, lat = ~Latitude, icon = camp_icons,
popup = ~paste(Name, "(", Pop, " / ", Capacity, ")"))
# Add circles depending on the refugee population (radius) and occupancy (fillColor)
rfg_map <- addCircles(rfg_map, lng = ~Longitude, lat = ~Latitude, weight = 0,
radius = ~sqrt(Pop) * 700, fillOpacity = 0.5,
fillColor = ~colorBin(colpal, bins = 8, Occupancy,
na.color = "#8b0000", alpha = F)(Occupancy))
# Add legend
rfg_map <- addLegend(rfg_map, "bottomright",
pal = colorBin(colpal, bins = 8, na.color = "#8b0000",
domain = refugee_060316$Occupancy),
values = refugee_060316$Occupancy,
# We can make changes in the way the labels are represented,
# including transforming values passed with transform()
labFormat = labelFormat(suffix="%", transform = function(x) 100*x),
na.label = "Unofficial Rec. Centres",
title = "Site Capacity",
opacity = 0.9)
# Shows the map
rfg_map
In the above example site circle symbols are dependent on the population of the site. We use radius passed as an argument in the addCircles function. We use a colour pallete colpal to map occupancy levels in each site. Red indicates sites with over-capacity while green indicates under-capacity. Since some sites are not official reception centres and technically do not have any capacity, we pass on na.color argument to both the addCircles and addLegend functions.
Note that leaflet has a built-in feature to allow user interaction by clicking the features on the map. This ability is passed on by the popup argument of the addMarkers function. In this instance, clicking the sites gives more detailed information about their name and occupancy levels.