Skip to content

Instantly share code, notes, and snippets.

@daroczig
Last active September 23, 2015 14:22
Show Gist options
  • Save daroczig/3e598153aac1931a1e0a to your computer and use it in GitHub Desktop.
Save daroczig/3e598153aac1931a1e0a to your computer and use it in GitHub Desktop.
Download and parse public data on the number of "catched" refugees in Hungary 2015
## R script to download and parse public data found at
## http://www.police.hu/hirek-es-informaciok/hatarinfo/elfogott-migransok-szama-lekerdezes
## on the number of "captured" refugees by the Hungarian police in 2015
## download and parse data
library(XML)
library(jsonlite)
library(data.table)
res <- rbindlist(lapply(2015, function(year) {
rbindlist(lapply(1:9, function(month) {
page <- htmlParse(paste0('http://www.police.hu/hirek-es-informaciok/hatarinfo/elfogott-migransok-szama-lekerdezes?honap%5Bvalue%5D%5Byear%5D=', year, '&honap%5Bvalue%5D%5Bmonth%5D=', month))
list <- unlist(xpathApply(page, "//div[@class='charts-highchart chart']", xmlGetAttr, 'data-chart'))
data.frame(
date = paste0('2015.', fromJSON(list)$xAxis$categories[[1]]),
data = fromJSON(list)$series$data[[1]])
}))
}))
## parse date
res[, date := as.Date(date, format = '%Y.%m.%d')]
## plot data
library(ggplot2)
ggplot(res, aes(x = date, y = data)) +
geom_line(stat = 'identity') +
theme_bw() + ylab('') + xlab('') +
ggtitle(expression(
atop('"Captured refugees" in Hungary (2015)',
atop(italic('Source: police.hu'))))) + geom_smooth()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment