12.7 Application: Terrorist Attacks in France
Political scientists study a wide range of questions related to terrorism, including how targets end up being selected, how to predict and defend against attacks, what types of incidents the public considers to be terrorism, how attacks influence public attitudes, and responses to terrorism from government and other actors.
- Why might mapping visualizations and spatial data be useful to political scientists for these questions?
12.7.1 Adding points to a map
For a video explainer of the code for the applications with maps and points, as well as animating these points in the subsequent section, see below. (Via youtube, you can speed up the playback to 1.5 or 2x speed.)
In this application, we use the Global Terrorism Database to visualize where terrorist attacks (including failed attacks) have occurred in recent years in France.
- We will make a map of France using
map_data
to get the polygon information
library(maps)
library(ggplot2)
## get france data (not available for all countries)
<- map_data("france")
france
## Plot France
ggplot()+
geom_polygon(data=france, aes(x=long, y=lat, group=group), fill="white", colour="gray")+
ggtitle("Terrorist Attacks in France 2000-2019")+
coord_quickmap()+
theme_void()
- We load separate data that includes the latitude and longitude of attacks
load("gtb.RData")
## Let's look at only recent attacks
<- subset(gtb, iyear > 2000 & country_txt=="France") gtbfrance
- We use
geom_point
to add a layer of points from this dataset- We can colour or size the points by additional variables in the data
ggplot()+
geom_polygon(data=france, aes(x=long, y=lat, group=group), fill="white", colour="gray")+
## add points with size in proportion to fatalities
geom_point(data=gtbfrance, aes(x=longitude, y=latitude, size=nkill),
alpha=.4, colour="red")+ # alpha makes points transparent
## range specifies how big or small you want points to be
scale_size(name="Number of Fatalities", range=c(2, 10))+
ggtitle("Terrorist Attacks in France 2000-2019")+
coord_quickmap()+
theme_void()
- We can also add labels to the plot with
geom_text_repel
from theggrepel
package- Note that we can use labels from yet another object so long as we have the right lat and long
install.packages("ggrepel")
library(ggrepel)
## Let's add labels for the biggest attacks only
<- subset(gtbfrance, nkill > 75)
gtbmajorfrance
ggplot()+
geom_polygon(data=france, aes(x=long, y=lat, group=group), fill="white", colour="gray")+
## add points with size in proportion to fatalities
geom_point(data=gtbfrance, aes(x=longitude, y=latitude, size=nkill),
alpha=.4, colour="red")+
scale_size(name="Number of Fatalities", range=c(2, 10))+
## add labels from gtbmajorfrance
geom_text_repel(data=gtbmajorfrance, aes(x=longitude, y=latitude,
label=city), size=4,
max.overlaps = 30)+
ggtitle("Terrorist Attacks in France 2000-2019")+
coord_quickmap()+
theme_void()