2/2/2020

January 24 to January 30, 2020

Double-Click on any type of call from the legend to isolate just that type.

How this was Generated

library(httr)
library(dplyr)
library(plotly)
# get the data from Fairfax PD (run on January 30, 2020)
url<-'https://www.fairfaxcounty.gov/apps/'
url<-paste0(url,
            'pfsu/api/file/crimereportsfromsp')
a<-GET(url)
df<-content(a)
colnames(df)<-c('repnum','code','popup','date',
                'time','street_address','city',
                'state','zip')

How this was Generated pt.2

# remove some NA values in the time field
df<-df[which(!is.na(df$time)),] 

# take the hour only and convert to an integer
df$hour<-substr(df$time, 1,2) %>% as.integer 
df$weekDay<-weekdays(df$date)
df$rootCode<-lapply(df$code,
                    function(x){strsplit(x,'-')[[1]][1]}) %>% unlist
df2 <-df %>% select(c('date','hour','rootCode'))
colorspace<-rainbow(30)

df2 %>% group_by(hour) %>% 
  add_count(rootCode) %>%
  plot_ly(x=~date,y=~hour, z=~n, type='scatter3d',mode='markers',
          color=~rootCode, colors=colorspace, name = ~rootCode)

Thanks!