Data preparation

We are using datafrom National Consortium for the Study of Terrorism and Responses to Terrorism (START). (2016).Global Terrorism Database [Data file]. Retrieved from http://www.start.umd.edu/gtd

According to General Terms and Conditions of Use we cannot share whole data. Here is just a small portion. Find much more important data here: http://apps.start.umd.edu/gtd/

library("knitr")
opts_chunk$set(comment=NA, fig.width=6, fig.height=6, warning=FALSE, message=FALSE, cache=FALSE)

library("openxlsx")
data <- read.xlsx("globalterrorismdb_0616dist.xlsx", 1)
small_data <- data[,c("iyear", "country_txt", "nkill","nwound","weaptype1_txt")]
small_data <- small_data[small_data$iyear %in% c("2015","2014"),]

Store

Here the story with archivist begins.

library(dplyr)
library(ggplot2)
library(ggrepel)
library(ggthemes)

library(archivist)
setLocalRepo("~/GitHub/SmarterPoland_blog/arepo")

addHooksToPrint(class="ggplot",
                 repo = "SmarterPoland_blog", user = "pbiecek", subdir = "arepo")

sel <- small_data %a%
  dplyr::filter(iyear == "2015") %a%
  group_by(country_txt) %a%
  dplyr::summarise(sum_kills = sum(nkill, na.rm=TRUE),
            sum_wounds = sum(nwound, na.rm=TRUE),
            n = n()) %a%
  dplyr::filter(sum_kills > 2, sum_wounds>2)

And the plot

ggplot(sel, aes(sum_kills, sum_wounds)) +
  geom_point(aes(size=n)) + geom_text_repel(size=3,aes(label=country_txt)) +
  scale_x_log10() + scale_y_log10() + theme_classic() +
  theme(legend.position="none") + xlab("Total Number of Fatalities") + ylab("Total Number of Injured")+
  ggtitle("Victims of terrorism")
Load: [`archivist::aread('pbiecek/SmarterPoland_blog/arepo/e44de65f1e56ea42d2df2598c083d1ce')`](https://raw.githubusercontent.com/pbiecek/SmarterPoland_blog/master/arepo/gallery/e44de65f1e56ea42d2df2598c083d1ce.rda)

Restore

And here you can enjoy the magic

pl <- archivist::aread('pbiecek/SmarterPoland_blog/arepo/e44de65f1e56ea42d2df2598c083d1ce')
head(pl$data)
# A tibble: 6 x 4
         country_txt sum_kills sum_wounds     n
               <chr>     <dbl>      <dbl> <int>
1        Afghanistan      6208       6958  1926
2            Algeria        21         19    16
3            Bahrain         5         22    18
4         Bangladesh        76        695   465
5 Bosnia-Herzegovina         4          6     6
6       Burkina Faso         6          9     5
getTagsRemote("e44de65f1e56ea42d2df2598c083d1ce", "SmarterPoland_blog", "pbiecek", subdir = "arepo", tag = "")
 [1] "format:rda"                                   
 [2] "name:x"                                       
 [3] "class:gg"                                     
 [4] "class:ggplot"                                 
 [5] "labelx:Total Number of Fatalities"            
 [6] "labely:Total Number of Injured"               
 [7] "date:2016-07-27 17:22:08"                     
 [8] "session_info:241b933ea391e685940ca65c31533f7b"
 [9] "format:png"                                   
[10] "date:2016-07-27 20:10:03"                     
[11] "session_info:a8cd2da3bba1cc01c5e84212ff479d20"
[12] "date:2016-07-27 20:15:17"                     
digest::digest(pl$data)
[1] "ceed21e997efd00940cdbcba497559c7"
dat <- archivist::aread('pbiecek/SmarterPoland_blog/arepo/ceed21e997efd00940cdbcba497559c7')
head(dat)
# A tibble: 6 x 4
         country_txt sum_kills sum_wounds     n
               <chr>     <dbl>      <dbl> <int>
1        Afghanistan      6208       6958  1926
2            Algeria        21         19    16
3            Bahrain         5         22    18
4         Bangladesh        76        695   465
5 Bosnia-Herzegovina         4          6     6
6       Burkina Faso         6          9     5
ahistory(md5hash = 'pbiecek/SmarterPoland_blog/arepo/ceed21e997efd00940cdbcba497559c7')
   small_data                                                                                                   [d2ad05ac3e93aeaca02f57aa4f9f58bf]
-> dplyr::filter(iyear == "2015")                                                                               [01205474e0515ad29d3bae33ad4ba821]
-> group_by(country_txt)                                                                                        [e0d9c060107803889fbc7ffdea7a23f7]
-> dplyr::summarise(sum_kills = sum(nkill, na.rm = TRUE), sum_wounds = sum(nwound,     na.rm = TRUE), n = n())  [a78cf8a8e9cf10bdb1158af38422723d]
-> dplyr::filter(sum_kills > 2, sum_wounds > 2)                                                                 [ceed21e997efd00940cdbcba497559c7]
pl + ggtitle("Victims of terrorism in 2015\nCountries with > 2 Fatalities") + theme_bw()
Load: [`archivist::aread('pbiecek/SmarterPoland_blog/arepo/2e19d8d658b105fd90f550e1b37d720a')`](https://raw.githubusercontent.com/pbiecek/SmarterPoland_blog/master/arepo/gallery/2e19d8d658b105fd90f550e1b37d720a.rda)