A Shiny app that summarizes and displays data about US cocaine seizures during 2007
The app presents 3 maps, each showing the following information by US state for a particular month:
All the user has to do is to select a month (in numeric format) using a slider; the maps are automatically updated.
The app can be found here
Source code can be found here
Scroll up and down to see the 3 maps
The data is included in the ggvis package; it comes from DEA's STRIDE, System to Retrieve Information from Drug Evidence
The dataset consists of 3380 observations, each comprising
State abbreviations are converted to to full state names in lowercase
library(ggvis); data(cocaine)
convertName <- function(abb) {
tolower(state.name[grep(abb, state.abb)])
}
cocaine$state <- as.character(sapply(cocaine$state, convertName))
theMonth <- 6 # supplied by the user through the slider!
prepData1 <- function(theMonth) {
theDataTable <- data.table(subset(cocaine, month == theMonth))
avgPurityByState <- theDataTable[,list(meanPurity=mean(potency)),by=state]
}
avgPurityByState <- prepData1(theMonth)
print(head(avgPurityByState)) # let's take a look at the results....
## state meanPurity
## 1: indiana 60.26667
## 2: florida 61.42308
## 3: pennsylvania 45.30000
## 4: new jersey 44.50000
## 5: illinois 53.20000
## 6: california 64.75000