1. Overview

This DataViz assignment is to work on the project dataset on ACLED (Armed Conflict Location & Event Data Project) for Southern Asia to look at the patterns with respect to the armed conflicts on the borders of the countries. The duration taken into account for this assignment would be February 2016 - February 2020.

Through interactivity and animation, typically we want to look at the various events across the borders and how they could be linked to the various events.

2. Core purpose and components of the data visualization

2.1. Core Purpose

Core purpose of this visualization is to showcase the different armed conflicts occuring in Southern Asia in the period of Feb 2016 - Feb 2020. With a focus on the events that have caused fatalities, we want to look at the cross border events across South Asia and look at the concentration and impact of the events at these borders. Alongside visualizing the static maps, with the help of interactivity and animation, the user is provided with the flexibility to interact with the dashboard in a user friendly manner. Animation is provided to look at the trend of the events over a period of time and how the events have evolved during this period.

2.2. Components of the visualization and linked significances

Title: The final visualization has a title to define the story being depicted through the visualization.

Legend: The legend helps with a marker that gives the definition of the points, colours used in the visualization.

Tooltips: In the interactive visualization, tooltips help with highlighting the features at a given point when navigated through it.

Trends: The trends in the data can be derived through facetting the original visualization and using interactivity and/or animation to highlight specific trends in the data.

Layered grammar of graphics: This includes various components embedded into tmaps through different layers for - data, aesthetics in form of a map layout, geometries as shape and symbol, facets to divide the visualization into various components, statistics to show the symbols scaled through the variable of focus and theme to make the overall visualization impactful and self-explanatory.

2.3. Rough sketch of the visualization

3. Ways of Interactivity

To adopt interactivity the tmaps are visualized in view mode wherein the tmap is automatically converted into a leaflet which has the tooltip describing the features of the point and the points are automatically plotted onto a natural map background. Apart from that for animation with a view of the time trend, through ImageMagick an animation is embedded which shows the events over the period of time.

4. Step by Step Data visualization process

This section describes the step by step process for creating the visualizations. It is divided into 3 sections - Intallation of R packages, Data Preparation followed by Creating Visualizations. Customizations and aesthetics in form of interactivity and animations have been described in the third section.

4.1. Installation of R packages

This code chunk installs the basic sf, tmap, tidyverse, magick and mapview packages on the user machine without having to load one by one. These packages are installed and loaded into Rstudio environment because they are needed to be loaded for the visualizations.

packages = c('sf', 'tmap', 'tidyverse','magick','maptools','spatstat')

for(p in packages){
  if(!require(p,character.only = T)){
    install.packages(p)
  }
  library(p,character.only = T)
}

4.2. Data Preparation

The data source for this dataviz is ACLED. The dataset used for this dataviz is the Armed Conflict Location & Event Data Project for Southern Asia wherein the events, impact of events can be analyzed in detail. The data set was downloaded from the link provided and included in the data sub-folder of the DataViz Makeover 9 project folder in csv format.

raw_data <- read_csv("data/2016-02-01-2020-02-01-Southern_Asia.csv")
## Parsed with column specification:
## cols(
##   .default = col_character(),
##   data_id = col_double(),
##   iso = col_double(),
##   event_id_no_cnty = col_double(),
##   year = col_double(),
##   time_precision = col_double(),
##   inter1 = col_double(),
##   inter2 = col_double(),
##   interaction = col_double(),
##   latitude = col_double(),
##   longitude = col_double(),
##   geo_precision = col_double(),
##   fatalities = col_double(),
##   timestamp = col_double()
## )
## See spec(...) for full column specifications.
map <- st_read("data/custom.geo.json")
## Reading layer `custom.geo' from data source `C:\Visual Analytics and Applications\DataViz\DataViz 9\DataViz Makeover 9\data\custom.geo.json' using driver `GeoJSON'
## Simple feature collection with 5 features and 64 fields
## geometry type:  POLYGON
## dimension:      XY
## bbox:           xmin: 60.87425 ymin: 5.96837 xmax: 97.40256 ymax: 37.13303
## epsg (SRID):    4326
## proj4string:    +proj=longlat +datum=WGS84 +no_defs

Removing the records without any fatalities. All the events without any fatalities have been removed because these are not being analyzed. As a part of this analysis we are only looking at the cases wherein there have been fatalities.

clean_fatalities <- raw_data %>%
  filter(fatalities!="0")

India-Pakistan border data cleaning is performed here for filtering the events. Filtering the states in India and districts in Pakistan which are on the borders with the other to look at the events in that area.

india_at_pak_border <- clean_fatalities %>%
  filter(country==c("India")) %>%
  filter(admin1==c("Jammu and Kashmir"))
pak <- clean_fatalities %>%
  filter(country==c("Pakistan")) %>%
  filter(admin1==c("Azad Jammu and Kashmir","Gilgit-Baltistan","Punjab"))
india_pak_border <- rbind(india_at_pak_border,pak)

Simple feature object named raw_data_sf is created out of the dataframe clean_fatalities to create the spatial points out of which the map is created. The longitude and latitude are considered as part of the coords and the crs which defines the coordinate system.

raw_data_sf <- st_as_sf(clean_fatalities, 
                       coords = c("longitude", "latitude"),
                       crs=4326)

Simple feature object named fatalities_india_pak_sf is created out of the dataframe india_pak_border to create the spatial points out of which the map is created. The longitude and latitude are considered as part of the coords and the crs which defines the coordinate system.

fatalities_india_pak_sf <- st_as_sf(india_pak_border,
                       coords = c("longitude", "latitude"),
                       crs=4326)

4.3. Static Visualizations

tmap mode can be set to static plotting or interactive viewing. The global option tmap.mode determines the whether thematic maps are plot in the graphics device, or shown as an interactive leaflet map. In this case for exploring static visualizations, tmap_mode is set to plot.

tmap_mode("plot")
## tmap mode set to plotting

For creating the visualization here, first of all the events with fatalities are plotted all throughout South Asia. The shape type for this visualization is in form of bubbles. The map shape is plotted at the background as a polygon on which the bubbles are plotted with reference to grammar of graphics. The bubble points are coloured red with border being black. Through this we can see that the intensity of the events are more in Pakistan with number of fatalities being high as well. On the other hand in Bangladesh it can be observed that there have been many events but the fatality of the events are not that high.

tm_shape(map)+tm_polygons()+
tm_shape(raw_data_sf)+
  tm_bubbles(col = "red",
           size = "fatalities",
           border.col = "black",
           border.lwd = 1)

Now to deep dive into the event type of the events, the previous visualization is facetted, i.e wrapped based on the event_type and also coloured using the event_type.

tm_shape(map)+tm_polygons()+
tm_shape(raw_data_sf)+
  tm_bubbles(col = "event_type",
           size = "fatalities",
           border.col = "black",
           border.lwd = 1)+
  tm_facets(by="event_type",
            free.coords = TRUE)

India Pakistan Border Analysis

Because the objective of this analysis is to look at the cross border events, India-Pakistan border is being focused on here because the events have been known to be high here. To focus on India and Pakistan border particularly, the data filtered for these 2 countries will be visualized in the similar manner as before.

tm_shape(map)+tm_polygons()+
tm_shape(fatalities_india_pak_sf)+
  tm_bubbles(col = "red",
           size = "fatalities",
           border.col = "black",
           border.lwd = 1)

The previous code chunk is built upon here to split the visualization into the various event types and with some customization with the help of tm_layout. The title is set in this visualization with customization with respect to the title size and position. Compass and gridlines are added to make the plot presentable. This is done with the help of tm_compass(), tm_scale_bar() and tm_grid().

r <- tm_shape(map)+
  tm_polygons()+
  tm_shape(fatalities_india_pak_sf)+
  tm_bubbles(col = "red",
           size = "fatalities",
           border.col = "black",
           border.lwd = 1)+
  tm_facets(by="event_type",nrow = 3)+
  tm_layout(main.title = "Fatalities in India Pakistan Border",
            main.title.position = "left",
            main.title.size = 1.2,
            frame = TRUE)+
  tm_compass(type="arrow", size = 0.8,text.size = 0.6) +
  tm_scale_bar(width = 0.15) +
  tm_grid(lwd=0.5,alpha = 0.5) +
  tm_credits("Source: ACLED (Armed Conflict Location & Event Data Project", 
             position = c("left", "bottom"),size=1.2)+
  tmap_style("white")
## tmap style set to "white"
## other available styles are: "gray", "natural", "cobalt", "col_blind", "albatross", "beaver", "bw", "classic", "watercolor"
r

4.4. Interactivity and Animation

The previous visualizations have been modified with animation to show the progression of the events over the passage of time (2016-2020) and interactivity using leaflet to get tooltips of the points and providing the user with the flexibility to intract with the visualization.

India Pakistan Border Analysis

In this case for interactive visualizations, tmap_mode is set to view.

tmap_mode("view")
## tmap mode set to interactive viewing

Animation is done with the help of tmap_animation() wherein the current visualization is converted to a gif using ImageMagick. A pre-requisite for this visualization is the installation of ImageMagick on the machine. With ImageMagick and the magick library on R, the gif is created based on the variable which has been facetted along with the help of tm_facets(). The arguements in tmap_animation are used to adjust the animation of the gif. This gif is saved in this project and later called as an image to be displayed in this markdown file.

t<-tm_shape(map)+tm_polygons()+tm_shape(fatalities_india_pak_sf)+
  tm_bubbles(col = "event_type",
           size = "fatalities",
           alpha=0.7,
           border.col = "black",
           border.lwd = 1)+
  tm_facets(along = "year", free.coords = FALSE)+
  tm_layout(main.title.size = 2)+
  tmap_style("white")
## tmap style set to "white"
## other available styles are: "gray", "natural", "cobalt", "col_blind", "albatross", "beaver", "bw", "classic", "watercolor"
tmap_animation(t, filename = "t.gif", delay = 200, restart.delay = 200, height=9,width=12,dpi=72)
## Animation saved to C:\Visual Analytics and Applications\DataViz\DataViz 9\DataViz Makeover 9\t.gif

To bring in interactivity into the visualization, tmap_mode(“view”) is used. The previous visualization already created under static visualizations is called here with the help of view mode in tmap_mode. Here the visualization is grouped based on the colours which show the different event types.

tm_shape(fatalities_india_pak_sf)+
  tm_bubbles(col = "event_type",
           size = "fatalities",
           alpha=0.7,
           border.col = "black",
           border.lwd = 1)
## Legend for symbol sizes not available in view mode.

To make the previous visualization more organized and easy to read, the visualization is facetted based on the event types. For the sake of highlighting the 4 most important event types (as derived from previous visualization), the dataframe is filtered for 4 event types. The visualization here is synced for all the 4 facetted visualizations for the navigation to be easy for the user and to look at the event types at the same location and at the same point of time.

fatalities_india_pak_sf<-fatalities_india_pak_sf %>%
  filter(event_type==c("Battles","Violence against civilians","Riots","Explosions/Remote violence"))
p<-tm_shape(fatalities_india_pak_sf)+
  tm_bubbles(col = "event_type",
           size = 1,
           alpha=0.7,
           border.col = "black",
           border.lwd = 1)+
  tm_facets(by="event_type",
            nrow=2,
            ncol=2,
            sync=TRUE)
p

5.0 Finalized Visualizations with takeaways

Static Visualization The static visualization here focuses on the type of event at the India-Pakistan border over the period of 2016-early 2020. The map is customized by changing theme so that it looks appealing to the user. It can be said that Battles are the events causing the most unrest followed by violence against civilians. But for deriving insights on fatalities, it can be said that explosions cause the maximimum fatalities.

tmap_mode("plot")
## tmap mode set to plotting
r

Interactive Visualization This is the interactive visualizations. Only the 4 most important and widespread event types are filtered over here. The reason to do that is for facetting it is hard to look at more than 4 visualizations synced at the same time. Hence, because of the same, only battles, violence against civilians, explosions and remote violence and riots are filtered for here. As a future scope, a filter can be added for the user to select the 2 variables that the user would like to compare. As the visualizations are synced, a point on one of the maps links to the other maps based on the geographical point on the map. The insights drawn from the visualization are similar to the static counterpart.

tmap_mode("view")
## tmap mode set to interactive viewing
p

Animated Visualization To add animation to the same visulization, an animation is created along the time period, year to look at the yearly progression of the events coloured by the event type. It can be seen that the intensity of the events have been the maximum in the year 2018 with maximum fatalities in 2016, 2018 and 2019. Some specific events are highlights in particular years. As for instance, an explosion event is the highlight in 2019 with maximum fatalities.

6.0 Benefits of Animation / Interactivity

  1. Tell a Story Animation and/or Interactivity helps with telling a story through the visualization. Users can glean important revelations about the data from a good interactive visualization with a focus on the objective. For instance, in this visualization it helps the user compare the cross border events with tooltips describing the event type and comparing the other event types at the same location through sync among the visualizations. It can be said that there have been more battles and riots at the border of India and Pakistan.

  2. Depiction of patterns Patterns make it easier for users to analyze the data and identify trends. It’s unlikely that users would be able to recognize patterns when presented with all the data points at the same time; hence visualizations make it easier to identify patterns at a glance. In this case through the animation, the spread of the events over the years can be seen at a glance and insights can be drawn according to it. The motion of the animation enhances with perception of changes and reduces changes blindness.

  3. Simplicity Users are presented with only the key elements that enable them to get both the big picture and the details in one visualization. Through interactivity the important components of the visualization are highlighted and separated so that the user doesn’t have to slice and dice the data on the visualization to derive insights. As in the case of the interactive visualization for the different event types, the user can navigate on one of the event type visualization to look at the impact on the other event types.