Accidents occured on MD Transportation Authority (MDTA) facilities
This document is to show accidents that occured on MD Transportation Authority (MDTA) facilities, or were within a concurrent jurisdiction and were responded to by MDTA Police. MDTA facilities are the Francis Scott Key Bridge (I-695), John F. Kennedy Memorial Highway (I-95), Thomas J. Hatem Memorial Bridge (US 40), Fort McHenry Tunnel (I-95), Baltimore Harbor Tunnel (I-895), the Bay Bridge (US 50/301), Governor Harry W. Nice Memorial Bridge (US 301), and Intercounty Connector (ICC/MD200). MDTA Police are also responsible for accidents at BWI Airport and the Port of Baltimore The data set is from Maryland State governemt website https://data.maryland.gov/Public-Safety/MDTA_-Accidents-Map/wncz-8s6d
Load and Explore data
md <- read.csv("MDTA__Accidents_Map.csv")
str(md)
## 'data.frame': 3043 obs. of 5 variables:
## $ CC.Number : Factor w/ 2989 levels "12B021665","12B021675",..: 175 101 102 176 177 178 179 180 181 182 ...
## $ Date : Factor w/ 1155 levels "01/01/2013","01/01/2015",..: 530 534 534 534 534 534 534 534 537 544 ...
## $ Time : int 1630 1229 1229 445 802 832 905 847 634 2232 ...
## $ Accident.Type: Factor w/ 9 levels "02","F","Injury Crash",..: 6 6 6 8 6 6 8 6 6 8 ...
## $ Location.1 : Factor w/ 2920 levels "(38.3594980000, -77.0130140000)",..: 1977 216 217 1667 1306 2200 2506 1861 1301 2211 ...
head(md)
## CC.Number Date Time Accident.Type Location.1
## 1 12T008826 07/01/2012 1630 PD (39.26699, -76.560642)
## 2 12L005385 07/02/2012 1229 PD (39.000549, -76.399312)
## 3 12L005388 07/02/2012 1229 PD (39.00058, -76.399267)
## 4 12T008851 07/02/2012 445 PI (39.26367, -76.56648)
## 5 12T008858 07/02/2012 802 PD (39.240862, -76.599017)
## 6 12T008860 07/02/2012 832 PD (39.27022, -76.63926)
Clean the data
Get rid of the bracket and the comma from “Location.1” variable and split the into two columns “alt” and “lng”
mdac <- md %>%
extract(Location.1, into = c('alt', 'lng'), "\\(([0-9.]+),\\s+(-*[0-9.]+).")
mdac$alt <- as.numeric(mdac$alt)
mdac$lng <- as.numeric(mdac$lng)
head(mdac)
## CC.Number Date Time Accident.Type alt lng
## 1 12T008826 07/01/2012 1630 PD 39.26699 -76.56064
## 2 12L005385 07/02/2012 1229 PD 39.00055 -76.39931
## 3 12L005388 07/02/2012 1229 PD 39.00058 -76.39927
## 4 12T008851 07/02/2012 445 PI 39.26367 -76.56648
## 5 12T008858 07/02/2012 802 PD 39.24086 -76.59902
## 6 12T008860 07/02/2012 832 PD 39.27022 -76.63926
On the map
Put the data on the map: Set the center on Baltimore, MD city and set the zoom to 10 set the popups to show the accsidant type and date
m<- leaflet(data = mdac) %>% setView(lng = -76.6121893, lat = 39.2903848, zoom = 10)%>%
addTiles() %>% addMarkers(lng = mdac[,6], lat= mdac[,5], clusterOptions = markerClusterOptions(),
popup = paste(mdac$Accident.Type, mdac$Date, sep= " "))
m