2/2/2020
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')
# 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)