This interactive map shows all traffic stops from October 2017 to the present. Zoom and pan to see different areas of the map. Click on the markers to show greater detail. Click on individual stops to see the outcome. The greatest number of traffic stops are in the downtown area. The most frequent outcome of the traffic stops is “citation issued.” which is the outcome of 46% of stops. The second most frequent outcome is a verbal warning, which is the outcome for 43% of the stops.
This graph shows the count of traffic stops by day, from October 2017 to early 2018. The time covered by the series can be expanded or narrowed using the interactive tool below the graph.
---
title: "Asheville Traffic Stop Data"
output:
flexdashboard::flex_dashboard:
storyboard: true
social: menu
source: embed
---
```{r setup, include=FALSE}
# load data in 'global' chunk so it can be shared by all users of the dashboard
library(jsonlite)
stops<-read_json("https://services.arcgis.com/aJ16ENn1AaqdFlqx/arcgis/rest/services/APD_Traffic_Stops_after_Oct_1_2017/FeatureServer/0/query?where=1%3D1&outFields=*&outSR=4326&f=json", simplifyVector = TRUE, flatten=TRUE)
stops_df<-stops$features
names(stops_df) = gsub("attributes.", replacement = "", x = names(stops_df))
names(stops_df) = gsub("geometry.", replacement = "", x = names(stops_df))
#names(stops_df) = gsub(pattern = "attributes.", replacement = "", x = names(stops_df))
#location<-read_json("https://services.arcgis.com/aJ16ENn1AaqdFlqx/arcgis/rest/services/APDTrafficStops2020/FeatureServer/0/query?where=1%3D1&outFields=objectid&outSR=4326&f=json", simplifyVector = TRUE, flatten=TRUE)
#location_df<-location$features
#names(location_df) = gsub("attributes.", replacement = "", x = names(location_df))
#names(location_df) = gsub("geometry.", replacement = "", x = names(location_df))
#stopsdata<-merge(stops_df, location_df, by="objectid")
stopsdata<-stops_df
```
### TRAFFIC STOPS BY LOCATION AND OUTCOME. This interactive map shows all traffic stops from October 2017 to the present. Zoom and pan to see different areas of the map.
```{r}
library(leaflet)
leaflet(stopsdata) %>%
setView(lng=-82.5, lat=35.6, zoom=11) %>%
addProviderTiles(provider = "CartoDB.Positron") %>%
addCircleMarkers(lng = stopsdata$x, lat = stopsdata$y,
clusterOptions = markerClusterOptions(),
color = ~ifelse(stopsdata$enf_code_sbi == "CITATION ISSUED", "#e9a3c9", "#a1d76a"), stroke = FALSE,
fillOpacity = 0.5, label = stopsdata$enf_code_sbi)
```
***
This interactive map shows all traffic stops from October 2017 to the present. Zoom and pan to see different areas of the map. Click on the markers to show greater detail. Click on individual stops to see the outcome. The greatest number of traffic stops are in the downtown area. The most frequent outcome of the traffic stops is "citation issued." which is the outcome of 46% of stops. The second most frequent outcome is a verbal warning, which is the outcome for 43% of the stops.
### TOTAL TRAFFIC STOPS BY DAY, MONTH AND YEAR. This graph shows the count of traffic stops by day, from October 2017 to the present.
```{r}
library(dygraphs)
library(lubridate)
library(xts)
library(dplyr)
stopsdata$date_of_stop<-(date(ymd_hms(as.numeric(stopsdata$date_occurred))))
totalstops<-stopsdata[c(1,15, 50)]
totalstops$COUNT <- 1
totalsbydate<-totalstops %>% group_by(date_of_stop) %>% summarize(totals = sum(COUNT))
stopsdy <- xts(x = totalsbydate$totals, order.by = totalsbydate$date_of_stop)
dygraph(stopsdy, main = "Total Traffic Stops by Date") %>%
dyRangeSelector(dateWindow = c("2017-10-01", "2018-1-31"))
```
***
This graph shows the count of traffic stops by day, from October 2017 to early 2018. The time covered by the series can be expanded or narrowed using the interactive tool below the graph.