Sodelovanje Slovenske vojske pri podpori Policije - fotoreportaža Rigonce, Dobova, Brežice 11

After Hungary announced that it would close its border with Croatia to migrants on 16 October 2015, thousands of migrants daily were diverted to Slovenia instead. - Wikipedia, European Migrant Crisis

IOM confirmed yesterday (21/12) that over a million irregular migrants and refugees arrived in Europe in 2015 […] With arrivals of 4,141 migrants or refugees landing in Greece on Monday, IOM reports total arrivals to Europe at roughly 1,005,504. The total is the highest migration flow since World War II. - www.IOM.int, 22 December 2015

As many as 377.547 migrants entered Slovenia from 16 October 2015 to 31 December 2015 (12am) - Policija.si

Original data from: http://www.policija.si:

Notes from original data:

In the graph above the number of exiting migrants for 16-19 October is estimated based on the reported number of persons in reception and accommodation centers.

Date Inflow Outflow Comment Cumulative CumulativeInflow
2015-10-16 0 0 Outflow estimated 0 0
2015-10-17 3000 0 Outflow estimated 3000 3000
2015-10-18 2700 3000 Outflow estimated 2700 5700
2015-10-19 7677 7235 Outflow estimated 3142 13377
2015-10-20 7478 4036 6584 20855
2015-10-21 12616 6847 12353 33471
2015-10-22 9339 10367 11325 42810
2015-10-23 9500 9667 11158 52310
2015-10-24 9925 6238 14845 62235
2015-10-25 9818 7984 16679 72053
2015-10-26 8625 10042 15262 80678
2015-10-27 6877 8534 13605 87555
2015-10-28 9848 9848 13605 97403
2015-10-29 5341 9400 9546 102744
2015-10-30 7539 9277 7808 110283
2015-10-31 6344 6741 7411 116627
2015-11-01 7611 6380 8642 124238
2015-11-02 8568 9442 7768 132806
2015-11-03 5591 6665 6694 138397
2015-11-04 7693 7818 6569 146090
2015-11-05 5426 6675 5320 151516
2015-11-06 6655 6943 5032 158171
2015-11-07 1716 4156 2592 159887
2015-11-08 4381 3239 3734 164268
2015-11-09 5341 5487 3588 169609
2015-11-10 7457 6566 4479 177066
2015-11-11 7554 7666 4367 184620
2015-11-12 9681 8825 5223 194301
2015-11-13 7397 6449 6171 201698
2015-11-14 7905 8847 5229 209603
2015-11-15 7300 7037 5492 216903
2015-11-16 5261 6262 4491 222164
2015-11-17 7704 5762 6433 229868
2015-11-18 5998 7141 5290 235866
2015-11-19 5119 5528 4881 240985
2015-11-20 5211 6381 3711 246196
2015-11-21 2952 5726 937 249148
2015-11-22 5260 5089 1108 254408
2015-11-23 4102 4774 436 258510
2015-11-24 6297 5312 1421 264807
2015-11-25 2070 3334 157 266877
2015-11-26 1742 1801 98 268619
2015-11-27 2065 1891 272 270684
2015-11-28 3139 3153 258 273823
2015-11-29 2843 2225 876 276666
2015-11-30 4274 3813 1337 280940
2015-12-01 1709 2520 526 282649
2015-12-02 3077 2562 1041 285726
2015-12-03 3237 2127 2151 288963
2015-12-04 1557 3145 563 290520
2015-12-05 715 986 292 291235
2015-12-06 4288 1536 3044 295523
2015-12-07 4240 4407 2877 299763
2015-12-08 5351 5271 2957 305114
2015-12-09 4103 4367 2693 309217
2015-12-10 2078 3291 1480 311295
2015-12-11 3149 1742 2887 314444
2015-12-12 4271 3746 3412 318715
2015-12-13 3016 4000 2428 321731
2015-12-14 4250 3520 3158 325981
2015-12-15 2098 4081 1175 328079
2015-12-16 3214 2489 1900 331293
2015-12-17 3135 2687 2348 334428
2015-12-18 3150 3263 2235 337578
2015-12-19 3222 2925 2532 340800
2015-12-20 3233 3099 2666 344033
2015-12-21 3278 3371 2573 347311
2015-12-22 2118 3240 1451 349429
2015-12-23 3030 1466 3015 352459
2015-12-24 2131 2665 2481 354590
2015-12-25 3257 3254 2484 357847
2015-12-26 4274 3455 3303 362121
2015-12-27 3253 3422 3134 365374
2015-12-28 4228 4199 3163 369602
2015-12-29 4239 4203 3199 373841
2015-12-30 3195 3916 2478 377036
2015-12-31 511 1620 Data by 12 am 1369 377547

R code to prepare data:

Constants

page_nov <- "http://www.policija.si/index.php/novinarsko-sredie/81905-podatki-o-tevilu-migrantov-ki-so-vstopili-v-slovenijo-do-2-decembra-do-12-ure-?tmpl=component&print=1&page="
page_dec <- "http://www.policija.si/index.php/component/content/article/35-sporocila-za-javnost/82353-podatki-o-tevilu-migrantov-ki-so-vstopili-v-slovenijo-do-31-decembra-do-12-ure-?tmpl=component&print=1&page="
estimate_comment <- "Outflow estimated"
last_entry_comment <- "Data by 12 am"

Get raw data:

get_raw_migration_data <- function(page_url) {
  
  library(rvest)
  html_page <-  read_html(page_url)
  
  page_data <-
    html_page %>% 
    html_nodes(xpath = "//table[not(contains(@class, 'contentpaneopen'))]") %>% 
    html_table(header = TRUE, fill = FALSE, dec = ",") 
  
  migration <- list(
    inflow = page_data[[1]],
    outflow = page_data[[4]]
  )
}

library(stringr)
library(dplyr)

prepare_migration_data <- function(migration) {
  migration <-
    lapply(migration, function(x) {
      names(x) <- c("Date", "Persons")
      
      x$Persons <- str_extract(x$Persons, "\\d[\\d|\\.]*")
      x$Persons <- gsub("\\.", "", x$Persons)
      x$Persons <- trimws(x$Persons)
      x$Persons <- as.numeric(x$Persons)
      
      x <- x[!grepl("Skupaj", x$Date), ]
      x <- x[!grepl("SKUPAJ", x$Date), ]
      
      x$Date <- as.POSIXct(x$Date, format = "%d. %m. %Y")
      #if(!is.na(x$Date)) x else NULL
      x[complete.cases(x), ]
    })
  
  migr_df <- 
    migration$inflow %>% 
    left_join(migration$outflow, by = "Date") %>% 
    rename(Inflow = Persons.x, Outflow = Persons.y)
    
  migr_df
}

get_migration_data <- function(page) {
  migration <- get_raw_migration_data(page)
  prepare_migration_data(migration)
}

data_nov <- get_migration_data(page_nov)
data_dec <- get_migration_data(page_dec)

Prepare data:

correct_outflow <- function(migration) {
#   The data on the number of migrants who exit the country has only been recorded
#   since 20 October; therefore the total number of exiting migrants in this table
#   cannot be compared to the total number of migrants who enter the country (for
#   this data has been recorded since 16 October).
  
  # Estimate for outflows are calculated based on current number of persons in 
  # reception and accommodation centers (552 + 110):
  #  see http://www.policija.si/index.php/novinarsko-sredie/81905-podatki-o-tevilu-migrantov-ki-so-vstopili-v-slovenijo-do-2-decembra-do-12-ure-?tmpl=component&print=1&page=

  migration$Outflow[1:4] <- c(
    0, 
    0, 
    3000, 
    7235
  )
  migration$Comment <- ""
  migration$Comment[1:4] <- estimate_comment
  migration$Comment[length(migration$Comment)] <- last_entry_comment
  migration
}

library(dplyr)
migration <- 
  data_nov %>% 
  filter(Date < "2015-12-01") %>% 
  bind_rows( data_dec ) %>% 
  correct_outflow %>% 
  mutate(
    Outflow = ifelse(is.na(Outflow), 0, Outflow),
    Cumulative = cumsum(Inflow - Outflow),
    CumulativeInflow = cumsum(Inflow)
  )

Plot data:

library(tidyr)
migr_df_long <- 
  head(migration, -1) %>% 
  select(Date, Inflow, Outflow, Cumulative) %>% 
  gather("Migration", "Value", - Cumulative, -Date)  

library(ggplot2)
library(ggthemes)

g1 <- 
  ggplot(migr_df_long, aes(x = Date, y = Value, fill = Migration)) +
  geom_bar(stat = "identity", alpha = 0.5, position = position_dodge()) +
  geom_step(aes(y = Cumulative, color = "Number of refugees in Slovenia") ) +
  #theme_minimal() +
  theme_fivethirtyeight() +
  labs(
    fill = "",
    color = "",
    y = "", 
    title = "Daily migration and number of refugees in Slovenia"
  ) +
  scale_colour_manual(values = "black") +
  scale_fill_fivethirtyeight()