The code examples on this page use the pre-aggregated event-level dataset available from the download page. Our goal is to create a map of protest locations in Venezuela for the year 2010.
We first load the data (adjust the file name to match the version you are using), and convert the event date to a proper R date.
events <- read.csv("events.csv") events$event_date <- as.Date(events$event_date)
We now extract events in Venezuela (COW code 101) in 2010.
events.ven <- subset(events, cowcode==101 & format(event_date, "%Y")==2010)
We need the sp package to handle spatial data, and the cshapes package for the map background.
library(sp) library(cshapes)
Using functions from sp, we convert the events to a data frame with spatial coordinates attached.
coordinates(events.ven) <- ~longitude + latitude
For the map background, we obtain a world map for the year 2010 from cshapes, and extract the polygon for Venezuela.
worldmap2010 <- cshp(date=as.Date("2010-06-30"), useGW=F) border.ven <- worldmap2010[worldmap2010$COWCODE==101,]
Finally, we can plot (i) the background and (ii) the events to create the final map shown below. Note that in this simple example, events in the same location are plotted on top of each other and therefore appear as a single dot.
plot(border.ven, col="grey", main="Protest locations in Venezuela (2010)") plot(events.ven, add=T, pch=21)