-
Notifications
You must be signed in to change notification settings - Fork 0
/
old_IE-6600_-Sec-03_-Ashish_Group2.Rmd
1257 lines (798 loc) · 48 KB
/
old_IE-6600_-Sec-03_-Ashish_Group2.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
---
title: "Hackathon Group 2"
author: "Ashish Mhatre, Harshad Jadhav, Balaji Sampath"
date: "19/02/2022"
output:
html_document: default
pdf_document: default
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
```{r lib, include=FALSE, warning=FALSE}
#Import Dependencies and set working directory
setwd('C:/Users/Ashish Mhatre/Desktop/CVA/Project_Group 2/Hackathon_IE-6600_-Sec-03_-Ashish_Group2')
library(tidyr)
library(dplyr)
library(lubridate)
library(stringr)
library(imputeTS)
library(ggplot2)
library(magrittr)
library(stringr)
library(extrafont)
library(gridExtra)
library(corrplot)
library(lubridate)
library(ggalluvial)
library(gganimate)
library(ggplot2)
library(dplyr)
library(gapminder)
library(ggthemes)
library(gifski)
library(networkD3)
library(alluvial)
library(ggalluvial)
library(ggridges)
library(viridis)
library(hrbrthemes)
library(wordcloud2)
library(ggwordcloud)
library(tidyr)
library(dplyr)
library(lubridate)
library(stringr)
library(forcats)
library(ggplot2)
library(ggrepel)
library(readxl)
library(tweenr)
library(ggthemes)
library(countrycode)
library(devtools)
library(plotly)
library(corrplot)
library(RColorBrewer)
library(treemapify)
library(wordcloud)
library(wordcloud2)
library(tm)
library(fmsb)
library(igraph)
```
```{r data, include=FALSE,warning=FALSE}
# Import Global terrorism Dataset
gtd_df <- read.csv('Cleaned_Terror_DF.csv')
gtd_df <- gtd_df[-1]
```
# Introduction
The Global Terrorist database contains a detailed information about the terrorism, from 1970 to 2017. There are 181691 records and 135 columns including date, country, target details, attack type, and also if there was a motive behind a attack, the outcome of attack, and weapon details. The database is maintained by researchers at the National Consortium for the Study of Terrorism and Responses to Terrorism (START), headquartered at the University of Maryland.
For Hackathon we have droped columns having more than 80% NULL data and would be using the remainder of 60 attributes to present our analysis. we here by state that we have used this data materials solely for non-commercial analysis and Visualization purpose.
# Problem Statement
The objective of the report is to understand the terrorist events around the world. by making use of interactive charts and animations we have tried to make the exploration easy and more informative.
The report is divided into 4 sections, First section we try to have a Birdseye view on global events and observe the trend of attacks across the globe. In section two we concentrate our attention to terror activities related to India, similarly in section three we focus on United States are try to discover trends and relations regarding attacks, This section concludes with a brief comparison of terrorism and gun violence. Lastly in section four we make use of happiness index data, Global GDP data and Income by country data to perform a cross tab analysis and find correlation between the various factors and indicators of a country with terror attacks. links to all external data sets are mentioned in references section.
# Section 1
## 1.1 What was the overall trend in the number of terrorist attacks worldwide ?
```{r section1.1, echo=FALSE, warning=FALSE, fig.height = 8, fig.width = 10}
attacks <- gtd_df %>%
dplyr::select(eventid, iyear,country_txt) %>%
group_by(iyear, country_txt) %>%
summarise(Total_Attacks = n(), .groups = 'drop_last')
worldmap <- plot_geo(attacks,
locationmode = "country names",
frame = ~iyear) %>%
add_trace(locations = ~country_txt,
z = ~Total_Attacks,
zmin = 0,
zmax = max(attacks$Total_Attacks),
color = ~Total_Attacks,
colors = "OrRd") %>%
layout(title = list(text = "<b> Number of attacks on Countries over 50 Decades </b>", y = 0.98), paper_bgcolor='#fdbb84',
plot_bgcolor='#fdbb84') %>%
config(displayModeBar = FALSE)
worldmap
```
## Conclusion
In 1970 the countries in the Northern, Central and Southern America were affected the most and few countries in the middle east witnessed terrorist activities. During this year United States of America was the worst affected nation. Around 1976 1977 and 1978, terrorists activities were seen in countries belonging to European, Asian and Sub Sahara African regions and also in the Soviet Union and this can be considered as the time when terrorism started spreading in the world. Through 1984, most number of terrorist events occurred in Peru and Chile and continued to do so until 1988 where India also was affected along with them. In 1992, it can be observed that almost every country in the world had faced terrorism. The year 1998 saw decrease in the terrorist events but that didnt last for long as from the year 2005 there was constant increase in the number of attacks all over the world and 2014 was the year which has recorded most number of terrorist attacks. In 2014, countries like Iraq and Pakistan suffered the most with 3933 and 2151 attacks respectively.
## 1.2 How number of terrorist activities have varied across a period of 50 years ?
```{r section 1.2, echo=FALSE, warning=FALSE, fig.height = 8, fig.width = 15}
countries <- gtd_df %>%
dplyr::select(1,7) %>%
group_by(country_txt ) %>%
summarise(count = n()) %>%
arrange(desc(count)) %>%
slice(1:20) %>%
pull(country_txt)
countries_attack <- gtd_df %>%
dplyr::select(1,7,25) %>%
filter(country_txt %in% countries) %>%
group_by(country_txt,attacktype1_txt) %>%
summarise(count = n(), .groups = 'drop_last')
top_twenty <- ggplot(countries_attack, aes(x= reorder(country_txt, count), y= count, fill = attacktype1_txt))
top_twenty + geom_bar(stat = "identity") +
guides(fill = guide_legend(reverse = T)) +
coord_flip() +
labs(fill = "Attack Type",
title = "Top 20 countries attacked",
y = "Number of attacks",
x= "Countries") +
scale_fill_brewer(palette = 'OrRd')+
theme_wsj()+
theme(plot.title = element_text(size = 14,
face = "bold",
colour = "black",
lineheight = 1.2,
hjust = 0.5),
axis.title.x = element_text(size = 14),
axis.title.y = element_text(size = 14),
axis.text.x = element_text(size = 10),
axis.text.y = element_text(size = 10))
```
## Conclusion
The stacked barplot represents twenty countries that are most affected by terrorism. Iraq continues to be the country most impacted by terrorism. ISIL is responsible for all the terrorists attacks in Iraq Most of the attacks include bombing and explosion. After the withdrawal of US troops from Iraq, civil war broke, which led to the formation of ISIL and increased attacks on Iraq
## 1.3 Which are the top twenty countries that were targeted by the terrorist groups ?
```{r section 1.3, echo=FALSE, warning=FALSE, fig.height = 10, fig.width = 15}
events_per_year <- gtd_df %>%
select(eventid,iyear) %>%
group_by(iyear) %>%
summarise(count = n(), .groups = 'drop_last')
events <- ggplot( events_per_year, aes(x = iyear, y = count))+
geom_line() +
geom_point() +
geom_label_repel(aes(label = count),size = 3,alpha = 0.9) +
scale_x_continuous(limits = c(1970,2017), breaks = 1970:2017)+
theme_wsj()+
labs(title = "Trend in terrorism from 1970 to 2017",y = "Number of events",x= "Years") +
theme(plot.title = element_text(size = 14,face = "bold",colour = "black",lineheight = 1.2,hjust =
0.5),axis.title.x = element_text(size = 12),
axis.title.y = element_text(size = 12),
axis.text.x = element_text(size = 10, angle = 45),
axis.text.y = element_text(size = 10),
)
plot(events)
```
## Conclusion
The above linegraph represents the number of attacks all over the world from 1970 to 2017. As can be observed from the graph that on an average terrorism around the world has always increased until 2014. There were few years like from 1997 to 1998 where there was a sharp decrease in terrorits activities. The world in 2014 witnessed most terrorist attacks, this is due to the allegiance of two terrorist groups Boko Haram and ISIL, They were were jointly responsible for 51% of all claimed global fatalities in 2014. 78% of all deaths and 57% of all attacks occurred in just five countries: Afghanistan, Iraq, Nigeria, Pakistan and Syria.
# Section 2
## 2.1 Which were the cities that were mostly affected by various types of terrorist attacks?
```{r section 2.1, echo=FALSE, warning=FALSE, fig.height = 10, fig.width = 15}
A <- gtd_df%>%
filter(country==92)
A_1 <- A[c('city','attacktype1', 'attacktype1_txt')]
A_2 <- A_1%>%
group_by(attacktype1_txt,city)%>%
summarise(Total_attacks = sum(attacktype1),.groups = 'drop_last')%>%
arrange(desc(Total_attacks)) %>%
filter(city != "Unknown", attacktype1_txt != "Unknown")%>%
slice(1:15)
ggplot(A_2, aes(area = Total_attacks, fill = attacktype1_txt ,
label = city, subgroup = attacktype1_txt, )) +labs(fill = "AttackType")+labs(title ="Attack Type Distribution By Cities")+
theme_wsj()+
geom_treemap() +
geom_treemap_subgroup_border(colour = "white", size = 5) +
geom_treemap_subgroup_text(place = "centre", grow = TRUE,
alpha = 0.8, colour = "grey",
fontface = "italic") +
geom_treemap_text(colour = "black", place = "centre",
size = 4, grow =TRUE)+scale_fill_brewer(palette="OrRd")
```
## Conclusion
The treemap gives us the information about distribution of the various attack types across the Indian cities. Compared to other cities, the city of Srinagar was attacked by almost all the methods and it can be inferred from the chart that it was bombed many number of times. Imphal is the second most attacked city.
## 2.2 Do terrorists groups plan their attacks based on regions ?
```{r section 2.2, echo=FALSE, warning=FALSE, fig.height = 8, fig.width = 10}
terror.india <- gtd_df %>% filter(country_txt == "India")
terror.india$provstate[terror.india$provstate == "Orissa"] <-
"Odisha"
terror.india$provstate[terror.india$provstate == "Andhra pradesh"]<-"Andhra Pradesh"
terror.ind.recent <-
terror.india %>% filter(iyear >= "2000") %>% select(
one_of(
"iyear",
"imonth",
"iday",
"region_txt",
"provstate",
"city",
"latitude",
"longitude",
"attacktype1_txt",
"success",
"targtype1_txt",
"gname"
)
) %>%mutate(region = ifelse(
provstate %in% c("Rajasthan", "Maharashtra", "Gujarat", "Goa", "Daman and Diu"),
"Western",
ifelse(
provstate %in% c(
"Karnataka",
"Andhra Pradesh",
"Tamil Nadu",
"Telangana",
"Kerala",
"Puducherry"
),
"Southern",
ifelse(
provstate %in% c(
"Uttar Pradesh",
"Jammu and Kashmir",
"Himachal Pradesh",
"Uttarakhand",
"Punjab",
"Haryana",
"Delhi",
"Chandigarh",
"Uttaranchal"
),
"Northern",
ifelse(
provstate %in% c(
"Arunachal Pradesh",
"Assam",
"Meghalaya",
"Sikkim",
"Odisha",
"Bihar",
"West Bengal",
"Jharkhand",
"Manipur",
"Mizoram",
"Nagaland",
"Tripura"
),
"Eastern",
ifelse(
provstate %in% c("Madhya Pradesh", "Chhattisgarh"),
"Central",
NA
)
)
)
)
))%>%mutate(terror.abbr = ifelse(
gname == "People's War Group (PWG)",
"PWG",
ifelse(
gname == "Vishwa Hindu Parishad (VHP)",
"VHP",
ifelse(
gname == "Maoist Communist Center (MCC)",
"MCC",
ifelse(
gname == "Communist Party of India - Maoist (CPI-Maoist)",
"CPI-Maoist",
ifelse(
gname == "Naxalites",
"Naxalites",
ifelse(
gname == "Maoists",
"Maoists",
ifelse(
gname == "People's Liberation Army (India)",
"PLA",
ifelse(gname == "Jharkhand Janmukti Parishad (JJP)", "JJP", ifelse(gname=="Lashkar-e-Taiba (LeT)","LeT",ifelse(gname=="United Liberation Front of Assam (ULFA)","ULFA",ifelse(gname=="National Democratic Front of Bodoland (NDFB)","NBFB",ifelse(gname=="Garo National Liberation Army","GNLA",gname))))
)
)
)
)
)
))))%>%na.omit()
network_df <- terror.ind.recent %>%
select(region, terror.abbr) %>%
filter( terror.abbr != 'Unknown') %>%
group_by(region, terror.abbr) %>%
summarise(count = n(), .groups = 'drop_last') %>%
arrange(desc(count)) %>%
slice(1:5)
nodes <- data.frame(
name=c(as.character(network_df$region),
as.character(network_df$terror.abbr)) %>% unique()
)
network <- graph.data.frame(d=network_df, directed=F)
cnetwork<- cluster_edge_betweenness(network)
V(network)["Central"]$color<-"red"
V(network)["Northern"]$color<-"purple"
V(network)["Eastern"]$color<-"green"
V(network)["Southern"]$color<-"yellow"
V(network)["Western"]$color<-"brown"
plot(cnetwork,network,edge.color="orange", edge.curved=.1, vertex.label.cex = 0.8)
title(main = "Terrorist Groups And Their Active Regions")
```
## Conclusion
The network chart tells us whether the terrorists groups organise their attack based on the regions in India. Some groups attack only one region like LeT in North and ULFA in the eastern part of the country. There are also groups which attack more than one region like the PWG attacks both central and southern regions. Maoists and CPI- Maoists are the only two groups which attacks all the regions except the north.
## 2.3 In India, what was the mostly used attack method by the terrorists organisations?
```{r section 2.3, echo=FALSE, warning=FALSE, fig.height = 8, fig.width = 10}
C<- gtd_df%>%
filter(country==92)
C<- C[c("attacktype1","attacktype1_txt")]
C_1 <-C%>%
group_by(attacktype1_txt)%>%
summarise(Total_attacks = n())%>%
arrange(desc(Total_attacks))%>%
filter(attacktype1_txt != "Unknown")
C_2<- C_1%>%
pivot_wider(
names_from = attacktype1_txt,
values_from = Total_attacks
)
C_3 <- rbind(rep(12000,9),rep(0,9),C_2)
C_4<- radarchart(C_3,axistype = 1,axislabcol = "black",
cglty = 1, cglcol = "gray",
pcol = "red", plwd = 2,
pfcol = rgb(0,0,0, 0.25),title= "Most Preferred Attack Methods")
```
## Conclusion
The spider chart represents the most used attack methods by the terrorist groups in India over the years. It can be observed that bombing accounts for almost 50% of the attacks. The second method that was preferred was armed assault which constitutes 25%. Hostage taking and Unarmed assault were the least preferred methods among the terrorists groups.
## 2.4 Which are the most notorious terrorist groups active in India ?
```{r section 2.4, echo=FALSE, warning=FALSE, fig.height = 8, fig.width = 10}
ind_df <- gtd_df %>%
filter(country_txt == 'India' & gname != 'Unknown' ) %>%
select(group = gname, state = provstate) %>%
group_by(state, group) %>%
summarise(Count = n(), .groups = 'drop_last') %>%
arrange(desc(Count)) %>%
slice(1:5)
set.seed(43)
ggplot(ind_df, aes(label = group, size = Count, color = Count)) +
theme_wsj()+
scale_color_gradient(low = "darkred", high = "red") +
geom_text_wordcloud_area(aes(angle = 45 * sample(-2:2, nrow(ind_df),
replace = TRUE,
prob = c(1, 1, 4, 1, 1)
)),mask = png::readPNG("C:/Users/Ashish Mhatre/Desktop/CVA/Project_Group 2/Hackathon_IE-6600_-Sec-03_-Ashish_Group2/India_WordCloud.png"), rm_outside = TRUE) +
scale_size_area(max_size = 35) +
theme_minimal()
```
## Conclusion
Naxalite–Maoist group name looks the most prominent as the most dangerous terrorist group in india with more than 1400 attacks followed by another naxalite group operating in andhra pradesh region by People's War Group (PWG). These groups target Government in general by staging attacks against military, police and goverment. Other equally responsible groups for terrorism are Muslim Militants, Bodo Militants and Sikh Extremists.
# Section 3
## 3.1 How many attacks for a particular attack type happened in each year? and How many total number of each attack type affected the cities ?
```{r section 3.1, echo=FALSE, warning=FALSE, fig.height = 8, fig.width = 10}
us_df <- gtd_df %>%
filter(., country_txt == 'United States')
top_year <- us_df %>%
select(iyear) %>%
group_by(iyear) %>%
summarise(count = n()) %>%
arrange(iyear)
year <- bind_rows(top_year %>% head(10), top_year %>% tail(10))
task1 <- us_df %>%
select(Source = iyear, Target = attacktype1_txt) %>%
filter( Source %in% year$iyear & Target != 'Unknown') %>%
group_by(Source,Target) %>%
summarise(count = n(),.groups = 'drop_last') %>%
arrange(desc(count)) %>%
drop_na() %>%
slice(1:5)
task2 <- us_df %>%
filter( iyear %in% year$iyear & attacktype1_txt != 'Unknown') %>%
select(Source = attacktype1_txt, Target = provstate) %>%
group_by(Source,Target) %>%
summarise(count = n(), .groups = 'drop_last') %>%
arrange(desc(count)) %>%
drop_na() %>%
slice(1:5)
task1$Source <- as.character(task1$Source)
sankey <- bind_rows(task1,task2)
nodes <- data.frame(
name=c(as.character(sankey$Source),
as.character(sankey$Target)) %>% unique())
sankey$IDsource <- match(sankey$Source, nodes$name)-1
sankey$IDtarget <- match(sankey$Target, nodes$name)-1
# Make the Network
plot_sankey <- sankeyNetwork(Links = sankey, Nodes = nodes,
Source = "IDsource", Target = "IDtarget",
Value = "count", NodeID = "name",
sinksRight=FALSE)
plot_sankey
```
## Conclusion
Terror Attacks on United States are in decline since the highest spike in 1970s. Bombing/Explosion has been the most used attack type over the years with a high of 278 explosions in 1970 and the lowest being 2 incidents in 2008,2009 and 2012. The above sankey plot helps us to understand the exact flow of attack incidents by year and attack type by interatively showing us the number of attacks per year for a given type while also showing us the distribution of attack types by cities. Where we can see that California, New York and Puerto Rico are the 3 cities who have recieved a cumalative attacks of more than 100 over all the years from 1970 to 2017.
## 3.2 How was the Distribution of Attack frequency by Target over the Years ?
```{r section 3.2, echo=FALSE, warning=FALSE, fig.height = 8, fig.width = 10}
ridges <- us_df %>%
select(Year = iyear, Target = targtype1_txt) %>%
arrange(Year) %>%
drop_na()
ggplot(ridges, aes(y=Target, x=Year, fill=Year)) +
theme_wsj()+
scale_fill_brewer(palette = 'OrRd') +
geom_density_ridges(alpha=0.5, stat="binline", bins=20) +
theme_ridges() +
theme(
legend.position="none",
panel.spacing = unit(2, "lines"),
strip.text.x = element_text(size = 8)
) +
labs(title = 'Distribution of Attack frequency by Target over the Years')+
xlab("Years") +
ylab("Target Categories")
```
## Conclusion
The majority of attacks in United States are taken place in year 1970 which we can see targetted everthing with few target categories like Military, Police, Telecommunication, Other and NGO's being targetted the most. The years after 2000 witness a medium to high frequency of attacks with attacks targetting Religious Figures/Institution, Police and Transport. The overall level of terrorist-related acts in the United States declined in the early 1990s, when compared to figures for the 1970s and 1980s, but has increased steadily during the early 2000's years.
## 3.3 How was the Activity of top Terrorist group over the decades ?
```{r section 3.3, echo=FALSE, warning=FALSE, fig.height = 8, fig.width = 15}
us_df_mod <- us_df %>%
mutate(decade =
ifelse(iyear<1980, '70s',
ifelse(iyear < 1990, '80s',
ifelse(iyear < 2000, '90s',
ifelse( iyear < 2010, '2000s', '2010s')))))
us_df_mod$decade <- factor(us_df_mod$decade, levels=c("70s", "80s", "90s", "2000s", "2010s"))
top10_groups <- us_df_mod %>%
filter(gname != "Unknown") %>%
group_by(gname) %>%
summarise(nr_of_attacks = n()) %>%
arrange(desc(nr_of_attacks)) %>%
head(n=10)
top10_groups_activity <- us_df_mod %>%
filter(us_df_mod$gname %in% top10_groups$gname )%>%
select(decade, group_name = gname)%>%
group_by(decade, group_name) %>%
summarise(nr_of_attacks = n(), .groups = 'drop_last')%>%
arrange(desc(nr_of_attacks))%>%
top_n(n=10, wt=nr_of_attacks)
ggplot(data=top10_groups_activity, aes(x=decade, y=nr_of_attacks, col=group_name, group= group_name)) +
geom_line(size=1.5, alpha=1) +
theme(legend.position="right")+
labs(title='Terrorist Group activity over decades', x= 'Decades', y ='Number of Attacks') +
scale_color_brewer(name = "Terrorist Groups", palette = 'RdGy') + theme_wsj()
```
## Conclusion
FALN separatist organization in Puerto Rico which used violence in its campaign for Puerto Rican independence from the United States contributes to the highest attacks in 70s and then after rapidly declines reducing to 0 attacks after the 90s. also Between 1973, when the Supreme Court decided abortion should be legal throughout the United States, The US have been the target of anti abortion extremists attacks facing more than 300 acts of extreme violence. The third group attacking the United States for more than four decades is the Animal Libration Front (ALF).
## 3.4 What were the weapons of choice over the decades ?
```{r section 3.4, echo=FALSE, warning=FALSE, fig.height = 8, fig.width = 15}
top15_weapons <- us_df_mod %>%
select(year = iyear, weapon_type = weaptype1_txt, decade) %>%
filter(weapon_type != "Unknown") %>%
group_by(decade, weapon_type) %>%
summarise(nr_of_attacks = n(), .groups = 'drop_last') %>%
top_n(n=5, wt=nr_of_attacks) %>%
mutate(percent = nr_of_attacks/sum(nr_of_attacks)*100) %>%
arrange(decade, desc(nr_of_attacks))
ggplot(data=top15_weapons, aes(x=decade, y=percent, col=weapon_type, group= weapon_type)) +
geom_line(size=1.5, alpha=0.9) +
labs(title='Weapon choice of terrorists over time', x= 'Decades', y='Percentage of Use') +
scale_color_brewer(name = "Weapon Types", palette = 'YlOrRd') + theme_wsj()
```
## Conclusion
We can observe that the use of explosives has been in a decline since the 70s but in contrast the use of incendiary saw an increase from the 70s to 2000s and then decline there after. but we should be more concerned as the use of biological and chemical weapons have been in raise from early 80s and 70s respectively which would prove more lethal than explosives or incendiary weapons.
## 3.5 Which locations were targeted in united states ?
```{r section 3.5, echo=FALSE, warning=FALSE, fig.height = 8, fig.width = 10}
library(leaflet)
map_us <- us_df_mod %>%
filter(nkill > 0)
leaflet(data = map_us) %>%
addTiles() %>%
addMarkers(lat=map_us$latitude, lng=map_us$longitude, clusterOptions = markerClusterOptions(),
popup= paste(
"<br><strong>Killed: </strong>", map_us$nkill
))
```
## Conclusion
USA doesn't witness many terror attacks as compared to India.There are very few attacks that have claimed a very large number of lives. Also the number of casualities on an average is less as compared to that of India.
It has however witnessed one of the worst terrorist attacks in 2001 in New-York, which killed more than 1500 people.
## 3.6 What should have our concerns Gun violence or Terror attacks ?
```{r section 3.6, echo=FALSE, warning=FALSE, fig.height = 8, fig.width = 15}
gun_df <- read.csv("gun-violence-data_01-2013_03-2018.csv")
gun_df_cleaned <- gun_df %>%
select(date, state,n_killed,n_injured)
gun_df_cleaned$date <- ymd(gun_df_cleaned$date)
gun_df_cleaned$date <- year(gun_df_cleaned$date)
gun_df_cleaned <- gun_df_cleaned %>%
group_by(date,state) %>%
summarise(sum_kill = sum(n_killed), sum_injured = sum(n_injured), .groups = 'drop_last' ) %>%
drop_na()
us_terror_grouped <- us_df_mod %>%
select(date = iyear, state = provstate, nkill, nwound ) %>%
group_by(date, state) %>%
summarise(sum_terror_kill = sum(nkill), sum_terror_injured = sum(nwound), .groups = 'drop_last') %>%
drop_na()
df_terror_gun <- inner_join(gun_df_cleaned,us_terror_grouped, by=c('date','state'))
df_terror_gun %>%
select(-state) %>%
group_by(date) %>%
summarise(Gun_Killed = sum(sum_kill), Gun_injured = sum(sum_injured), Attack_kill = sum(sum_terror_kill), Attack_injured = sum(sum_terror_injured)) %>%
drop_na() %>%
pivot_longer(., cols = 2:5, names_to ="violence_type",
values_to = "Count") %>%
ggplot(., aes(fill=violence_type, y=Count, x=date)) +
geom_bar(position="dodge", stat="identity", alpha = 0.7)+
scale_fill_brewer(palette="OrRd",
name="Violence\nType and Result",
breaks=c("Attack_injured", "Attack_kill", "Gun_injured","Gun_Killed"),
labels=c("Terror Attack Injured", "Terror Attack Killed", "Gun Violence Injured","Gun Violence Killed")) +
xlab('Years') + ylab('Number of affected people') + labs(title = 'Comparison of Violence type from Year 2013-2017') + theme_wsj()
```
## Conclusion
Gun violence in the US results in tens of thousands of deaths and injuries annually. In 2013, there were 73,505 nonfatal firearm injuries which included 11,208 homicides, 21,175 suicides, 505 deaths due to accidental or negligent discharge of a firearm, and 281 deaths due to firearms use with "undetermined intent".
From the above graph, we can observe that the number of gun violence incidents are increasing every year. In the year 2014, there were about 51 thousand incidents reported, The number increased to 53 thousand in the next year, 2016 saw a bigger jump with close to 58 thousand incidents reported, in 2017, the number of gun violence incidents further increased to 61 thousand. A big increase of 10,000 incidents have been observed from 2014 to 2017, And this number is expected to further grow.
In the purview of the statistics shown by the grouped bar charts it is vividly clear that gun violence is the biggest issue in United States in comparison to terrorism.
## 3.7 What should have our concerns Gun violence or Terror attacks ?
```{r section 3.7, echo=FALSE, warning=FALSE, fig.height = 8, fig.width = 15}
df_terror_gun %>%
select(-date) %>%
group_by(state) %>%
summarise(Gun_Killed = sum(sum_kill), Gun_injured = sum(sum_injured), Attack_kill = sum(sum_terror_kill), Attack_injured = sum(sum_terror_injured)) %>%
drop_na() %>%
arrange(desc(Attack_kill)) %>%
slice(1:10) %>%
pivot_longer(., cols = 2:5, names_to ="violence_type",
values_to = "Count") %>%
ggplot(.,aes(x=state,y=Count,fill=violence_type))+
geom_bar(stat="identity", alpha = 0.7)+
coord_polar()+
scale_fill_brewer(palette="OrRd",
name="Violence\nType and Result",
breaks=c("Attack_injured", "Attack_kill", "Gun_injured","Gun_Killed"),
labels=c("Terror Attack Injured", "Terror Attack Killed", "Gun Violence Injured","Gun Violence Killed"))+
xlab("")+
ylab("") + labs(title = 'Comparison of cities with respective to violence type') + theme_wsj()
```
## Conclusion
The following rose chart displays the comparison of violence type and its affects distributed among different cities of United States where California tops with approx 16000 incidents reported, Florida with 15,000 incidents and Texas with 13,000 and it narates the same story that gun violence is the greater evil than overall terrorism in United States.
# Section 4
#### In this section we will make use of happiness index dataset and income by country dataset for the year 2015, 2016 and 2017 to draw out correlations relating to various factors and number of terrorist attacks
## 4.1 Does GDP of a nation gets affected by the terrorist activities ?
```{r section 4.1, echo=FALSE, warning=FALSE, fig.height = 8, fig.width = 15}
r_year <- 1970:2017
gdp <- read.csv("gdp_1960_2020.csv", na.strings = "") %>%
filter(year %in% r_year ) %>%
mutate(country_txt = str_replace(country, "the United States", "United States")) %>%
dplyr::select(year, country_txt, gdp)
terror_sub <- gtd_df %>%
dplyr::select(iyear,country_txt, eventid, success) %>%
group_by (iyear, country_txt) %>%
summarise(Total_Attacks = n(), .groups = 'drop_last')
names(gdp)[names(gdp) == "year"] <- 'iyear'
terror_gdp <- inner_join(terror_sub, gdp, by = c("iyear", "country_txt"))
terror_gdp_1 <- terror_gdp %>%
dplyr::select(iyear, country_txt, Total_Attacks, gdp) %>%
filter(country_txt %in% c("United States","Japan","China"," Germany"," France",
"United Kingdom","Italy","Brazil","Canada","India",
"Australia","Spain","Netherlands","Sweden"," Mexico"
))
##feature scaling
terror_gdp_1[,3:4] <- scale(terror_gdp_1[,3:4])
## scatter plot
scale_units <- function(n) {
labs <- ifelse(n < 1000, n, # less than thousands
ifelse(n < 1e6, paste0(round(n/1e3), 'k'), # in thousands
ifelse(n < 1e9, paste0(round(n/1e6), 'M'), # in millions
ifelse(n < 1e12, paste0(round(n/1e9), 'B'), # in billions
ifelse(n < 1e15, paste0(round(n/1e12), 'T'), # in trillions
'too big!'
)))))
return(labs)
}
terror_gdp_sc <- ggplot(terror_gdp_1, aes(x=gdp, y=Total_Attacks))+
geom_point(aes(col= country_txt))+
geom_smooth(formula = y~x, method = "lm", col = "firebrick", se= FALSE)+
scale_x_continuous(labels = scale_units)+
labs(col = "Countries",
title = "GDP vs Total Attacks",
y = "Total Attacks",
x = "GDP in Trillions")+
theme_base()+
#theme(panel.background = element_rect(fill = "#fd9984",
# colour = "#fd9984"))+
theme(plot.title = element_text(size = 14,
face = "bold",
colour = "black",
lineheight = 1.2,
hjust = 0.5),
axis.title.x = element_text(size = 12),
axis.title.y = element_text(size = 12),
axis.text.x = element_text(size = 12),
axis.text.y = element_text(size = 12),
legend.title = element_text(size = 12,
face = "bold",
colour = "black")) + theme_wsj()
plot(terror_gdp_sc)
```
## Conclusion
In the above scatter plot, we tried to get a generally idea on how GDP of a country gets affected by terrorist attacks. For this purpose, we chose few developed and developing countries for our analysis. As it is clearly visible from the graph that there exists a negative correlation between total attacks and GDP of a country. As number of attacks increase, the GDP decreases. There could be several other factors for the fall in GDP, number of terrorist attacks is one of them.
## 4.2 Does the mean income index, happiness score, health life expectancy, etc., of a nation have any relation with the number of terrorists attacks ?
```{r section 4.2, echo=FALSE, warning=FALSE, fig.height = 8, fig.width = 10}
h_2015 <- read.csv("2015.csv", na.strings = "") %>%
dplyr::select(Country, Happiness.Rank, Happiness.Score,
Economy..GDP.per.Capita., Family,
Health..Life.Expectancy., Freedom,
Trust..Government.Corruption.,
Generosity,
Dystopia.Residual)
h_2016 <- read.csv("2016.csv", na.strings = "") %>%
dplyr::select(Country, Happiness.Rank, Happiness.Score,
Economy..GDP.per.Capita., Family,
Health..Life.Expectancy., Freedom,
Trust..Government.Corruption.,
Generosity,
Dystopia.Residual)
h_2017 <- read.csv("2017.csv", na.strings = "") %>%
dplyr::select(Country, Happiness.Rank, Happiness.Score,
Economy..GDP.per.Capita., Family,
Health..Life.Expectancy., Freedom,
Trust..Government.Corruption.,
Generosity,
Dystopia.Residual)
master_happy <- rbind(h_2015, h_2016, h_2017)
means_all <- master_happy %>%
group_by(Country) %>%
summarise(Happiness_Rank = mean(Happiness.Rank),
Happiness_Score = mean(Happiness.Score),
Economy_GDP = mean(Economy..GDP.per.Capita.),
Family = mean(Family),
Health_Life_Exp = mean(Health..Life.Expectancy.),
Freedom = mean(Freedom),
Trust_Government_Corruption = mean(Trust..Government.Corruption.),
Generosity = mean(Generosity),
Dystopia_Residual = mean(Dystopia.Residual))
names(means_all)[names(means_all) == "Country"] <- "country_txt"
terror_subset <- gtd_df %>%
dplyr::select(eventid, country_txt) %>%
group_by(country_txt) %>%
summarise(Total_Attacks = n())
terror_happy <- inner_join(means_all, terror_subset, by = "country_txt")
terror_happy[,2:11] <- scale(terror_happy[,2:11])
income <- read_excel("Income by Country.xlsx", sheet = "Income Index") %>%
dplyr::select(1,27:29) %>%
mutate(Country = str_replace(Country, "Russian Federation", "Russia")) %>%
pivot_longer(cols = 2:4, names_to ="iyear",
values_to = "income_index") %>%
drop_na() %>%
group_by(Country) %>%
summarise(Mean_IncomeIndex = mean(income_index, na.rm =T))
names(income)[names(income) == "Country"] <- "country_txt"
income_subset <- inner_join(income, terror_happy, by = "country_txt" )
income_subset[,2:12] <- scale(income_subset[,2:12])
##Corrplot
cormat_2 <- cor(income_subset[,-1])
cor_inc_attacks <- corrplot(cormat_2, method = "color", COL1(sequential= c('OrRd')),
type = 'lower', order = 'original', addCoef.col = 'black', tl.col = 'black')