Introduction

The American Civil War began in 1861 and the last battle was fought in 1865. Majority of the battles occurred along the east coast with the Confederates and the Union. This interactive leaflet allows users to explore the east coast battles during the Civil War. It also depicts which side won which battle, or whether it was inconclusive.

# libraries necessary for this project
library(leaflet)
library(sf)
library(tidyverse)
library(USAboundaries)
library(mapview)

Data Management

Importing the necessary data file. The civilwar.csv contains every battle from the Civil War as well as additional variables to include spatial attributes.

civilwar <- read.csv("civilwar.csv")

Once imported, it is necessary to convert the file into a spatial format determined by specific coordinates from the csv file.

civilwar_spat <- st_as_sf(civilwar, coords = c("Longitutde", "Latitude"), crs = 4326)

A quick glance at the type of variables and observations we will be dealing with for this dataset.

summary(civilwar_spat)
##     OBJECTID         Battle          Other_Names         Location_1       
##  Min.   :  1.00   Length:374         Length:374         Length:374        
##  1st Qu.: 94.25   Class :character   Class :character   Class :character  
##  Median :187.50   Mode  :character   Mode  :character   Mode  :character  
##  Mean   :187.50                                                           
##  3rd Qu.:280.75                                                           
##  Max.   :374.00                                                           
##     State             Campaign         Principal_US_Commanders
##  Length:374         Length:374         Length:374             
##  Class :character   Class :character   Class :character       
##  Mode  :character   Mode  :character   Mode  :character       
##                                                               
##                                                               
##                                                               
##  Principal_CS_Commanders Forces_Engaged     Description       
##  Length:374              Length:374         Length:374        
##  Class :character        Class :character   Class :character  
##  Mode  :character        Mode  :character   Mode  :character  
##                                                               
##                                                               
##                                                               
##   Result_s_          CWSAC_Ref         Preservation_Priority National_Park_Unit
##  Length:374         Length:374         Length:374            Length:374        
##  Class :character   Class :character   Class :character      Class :character  
##  Mode  :character   Mode  :character   Mode  :character      Mode  :character  
##                                                                                
##                                                                                
##                                                                                
##   Start_Month       Start_Day       Start_Year     End_Month     
##  Min.   : 1.000   Min.   : 1.00   Min.   :1861   Min.   : 1.000  
##  1st Qu.: 4.000   1st Qu.: 8.00   1st Qu.:1862   1st Qu.: 5.000  
##  Median : 6.000   Median :16.00   Median :1863   Median : 7.000  
##  Mean   : 6.746   Mean   :15.99   Mean   :1863   Mean   : 6.794  
##  3rd Qu.: 9.000   3rd Qu.:24.00   3rd Qu.:1864   3rd Qu.: 9.000  
##  Max.   :12.000   Max.   :31.00   Max.   :1865   Max.   :12.000  
##     End_Day         End_Year     Start_Date          End_Date        
##  Min.   : 1.00   Min.   :1861   Length:374         Length:374        
##  1st Qu.: 8.00   1st Qu.:1862   Class :character   Class :character  
##  Median :16.00   Median :1863   Mode  :character   Mode  :character  
##  Mean   :15.72   Mean   :1863                                        
##  3rd Qu.:23.75   3rd Qu.:1864                                        
##  Max.   :31.00   Max.   :1865                                        
##  F__Days_Battle      NPS_Site         Battle_in_Multple_States_
##  Min.   :  1.000   Length:374         Length:374               
##  1st Qu.:  1.000   Class :character   Class :character         
##  Median :  1.000   Mode  :character   Mode  :character         
##  Mean   :  3.176                                               
##  3rd Qu.:  2.000                                               
##  Max.   :137.000                                               
##   Location_2         Location_3        Location_4     Total_Est__Casualties
##  Length:374         Length:374         Mode:logical   Length:374           
##  Class :character   Class :character   NA's:374       Class :character     
##  Mode  :character   Mode  :character                  Mode  :character     
##                                                                            
##                                                                            
##                                                                            
##  US_Est__Casualties CS_Est__Casualties Est_Casualties    
##  Length:374         Length:374         Length:374        
##  Class :character   Class :character   Class :character  
##  Mode  :character   Mode  :character   Mode  :character  
##                                                          
##                                                          
##                                                          
##  Casualties_in_Integers          geometry  
##  Min.   :    0.0        POINT        :374  
##  1st Qu.:  126.8        epsg:4326    :  0  
##  Median :  540.5        +proj=long...:  0  
##  Mean   : 2299.4                           
##  3rd Qu.: 1821.0                           
##  Max.   :51000.0

Analysis

The first step is to take a look at the data in a leaflet format to see what visual changes we want to make.

I think a circle marker would be best to display Civil War battles.

leaflet(data = civilwar_spat) %>% # calls the leaflet function using the data civilwar_spat
  addProviderTiles(providers$CartoDB) %>% # uses the basemap CartoDB
  addCircleMarkers() # displays the civilwar_spat data as circle markers

The results are a little overwhelming. Lets make some adjustments so that we are only looking at the east coast.

Filter the civilwar_spat by the east coast states that had battles.

civilwar_filtered <- civilwar_spat %>% 
  filter(State %in% c("VA", "NC", "SC", "FL", "GA", "MD", "PA")) # filter based on state abbreviations as theyre listed in the State variable

Display a leaflet based on the filtered results

leaflet(data = civilwar_filtered) %>% 
  addProviderTiles(providers$CartoDB) %>% 
  addCircleMarkers()

Still not quite there, the circle markers are still unclear and difficult to discern. Lets add a color filter.

Use colorfactor to create a pallette that assigns red, gray, and blue accordingly to the battle winners.

pal <- colorFactor(c("red", "gray", "blue"), domain = c("Confederate victory", "Union victory", "Inconclusive")) # use colorFactor to list colors and a domain that shares the observations highlighted in the variable for battle "Result_s_" (a variable in the dataset)

Add the pallette to the civilwar data and circle markers.

We also want to clean it up by adjusting the marker size, adding a legend, and even a mini map so our viewers don’t get lost when they navigate.

leaflet(data = civilwar_filtered) %>% 
  addProviderTiles(providers$CartoDB.Positron) %>% # change the basemap to something that has city names so viewers can have better situational awareness
  addCircleMarkers(color = ~pal(Result_s_), fillOpacity = .5, stroke = 1, # call to the pal and color scheme selected
                   radius = 3, # adjust the circle size
                   label = ~Battle, # add a lable to display the battle when users hover over the point
                   popup = ~Start_Date) %>%  # show battle startdate after selection
  
  
  addLegend(position = "bottomleft", # add a legend to the bottom left of the leaflet
            opacity = 1, 
            pal = pal, # call to the pal color scheme
            values = c("Confederate victory", "Union victory", "Inconclusive"), # list the matching values
            title = "Civil War Victories") %>% # add a title
  
  
  addMiniMap(tiles = providers$CartoDB.Positron, # add a mini map that allows users to navigate freely without losing any awareness
             width = 150, height = 150, # adjust the size
             toggleDisplay = TRUE)