library(dplyr)
library(knitr)
library(tidyr)
library(ggmap)
library(ggvis)
library(lubridate)
library(tools)
library(rgdal)
library(leaflet)
library(pander)

Death Rate Report for United States by State Brain & ONS, 2009 - 2013

Incidence Rate Report by State Brain & ONS, 2009-2013

#Geocode
BrCACenters <- geocode(Hosp2$Address)
## Information from URL : http://maps.googleapis.com/maps/api/geocode/json?address=101%20The%20City%20Drive%20South%20Orange,%20CA%2092868&sensor=false
## Information from URL : http://maps.googleapis.com/maps/api/geocode/json?address=1500%20East%20Duarte%20Road%20Duarte,%20CA%2091010&sensor=false
## Information from URL : http://maps.googleapis.com/maps/api/geocode/json?address=2000%206th%20Avenue%20South%20Birmingham,%20AL%2035233&sensor=false
## Information from URL : http://maps.googleapis.com/maps/api/geocode/json?address=400%20Parnassus%20Ave%20San%20Francisco,%20CA%2094143&sensor=false
## Information from URL : http://maps.googleapis.com/maps/api/geocode/json?address=710%20Westwood%20Plaza%20Los%20Angeles,%20CA%2090095&sensor=false
## Information from URL : http://maps.googleapis.com/maps/api/geocode/json?address=3800%20Reservoir%20Rd.%20Washington,%20DC%2020057&sensor=false
## Information from URL : http://maps.googleapis.com/maps/api/geocode/json?address=3855%20Health%20Sciences%20Drive,%20MC%200819%20La%20Jolla,%20CA%2092093&sensor=false
## Information from URL : http://maps.googleapis.com/maps/api/geocode/json?address=1441%20Eastlake%20Ave%20Los%20Angeles,%20CA%2090033&sensor=false
## Information from URL : http://maps.googleapis.com/maps/api/geocode/json?address=20%20York%20Street%20New%20Haven,%20CT%206510&sensor=false
## Information from URL : http://maps.googleapis.com/maps/api/geocode/json?address=3400%20Spruce%20Street%20Philadelphia,%20PA%2019104&sensor=false
## .
## Information from URL : http://maps.googleapis.com/maps/api/geocode/json?address=600%20Highland%20Ave%20Madison,%20WI%2053792&sensor=false
## Warning: geocode failed with status OVER_QUERY_LIMIT, location = "600
## Highland Ave Madison, WI 53792"
## .
## Information from URL : http://maps.googleapis.com/maps/api/geocode/json?address=450%20Brookline%20Avenue%20Boston,%20MA%202215&sensor=false
## .
## Information from URL : http://maps.googleapis.com/maps/api/geocode/json?address=2301%20Erwin%20Road%20Durham,%20NC%2027710&sensor=false
## .
## Information from URL : http://maps.googleapis.com/maps/api/geocode/json?address=333%20Cottman%20Avenue%20Philadephia,%20PA%2019111&sensor=false
## .
## Information from URL : http://maps.googleapis.com/maps/api/geocode/json?address=1354%20Aloha%20St%20Seattle,%20WA%2098109&sensor=false
## .
## Information from URL : http://maps.googleapis.com/maps/api/geocode/json?address=710%20West%20168th%20Street%20New%20York,%20NY%2010032&sensor=false
## .
## Information from URL : http://maps.googleapis.com/maps/api/geocode/json?address=200%20Hawkins%20Drive%20Iowa%20City,%20IA%2052242&sensor=false
## .
## Information from URL : http://maps.googleapis.com/maps/api/geocode/json?address=450%20West%20Drive%20Chapel%20Hill,%20NC%2027514&sensor=false
## .
## Information from URL : http://maps.googleapis.com/maps/api/geocode/json?address=55%20Fruit%20Street%20Boston,%20MA%202114&sensor=false
## .
## Information from URL : http://maps.googleapis.com/maps/api/geocode/json?address=200%20First%20Street%20SW%20Rochester,%20MN%2055905&sensor=false
## .
## Information from URL : http://maps.googleapis.com/maps/api/geocode/json?address=1515%20Holcombe%20Blvd%20Houston,%20TX%2077030&sensor=false
## .
## Information from URL : http://maps.googleapis.com/maps/api/geocode/json?address=1275%20York%20Avenue%20New%20York,%20NY%2010065&sensor=false
## .
## Information from URL : http://maps.googleapis.com/maps/api/geocode/json?address=12902%20Magnolia%20Drive%20Tampa,%20FL%2033612&sensor=false
## .
## Information from URL : http://maps.googleapis.com/maps/api/geocode/json?address=One%20Medical%20Center%20Drive%20Lebanon,%20NH%203756&sensor=false
## .
## Information from URL : http://maps.googleapis.com/maps/api/geocode/json?address=675%20N.%20St.%20Clair%20Chicago,%20IL%20606111&sensor=false
## .
## Information from URL : http://maps.googleapis.com/maps/api/geocode/json?address=1800%20Orleans%20Street%20Baltimore,%20MD%2021287&sensor=false
## .
## Information from URL : http://maps.googleapis.com/maps/api/geocode/json?address=4100%20John%20R%20Detroit,%20MI%2048201&sensor=false
## .
## Information from URL : http://maps.googleapis.com/maps/api/geocode/json?address=195%20Little%20Albany%20Street%20New%20Brunswick,%20NJ%208903&sensor=false
## .
## Information from URL : http://maps.googleapis.com/maps/api/geocode/json?address=Medical%20Center%20Boulevard%20Winston-Salem,%20NC%2027157&sensor=false
## .
## Information from URL : http://maps.googleapis.com/maps/api/geocode/json?address=300%20West%2010th%20Avenue%20Columbus,%20OH%2043210&sensor=false
## .
## Information from URL : http://maps.googleapis.com/maps/api/geocode/json?address=5841%20S.%20Maryland%20Avenue%20Chicago,%20IL%2060637&sensor=false
## .
## Information from URL : http://maps.googleapis.com/maps/api/geocode/json?address=1500%20E.%20Medical%20Center%20Drive%20Ann%20Arbor,%20MI%2048109&sensor=false
## .
## Information from URL : http://maps.googleapis.com/maps/api/geocode/json?address=5115%20Centre%20Ave.%20Pittsburgh,%20PA%2015232&sensor=false
## .
## Information from URL : http://maps.googleapis.com/maps/api/geocode/json?address=2220%20Pierce%20Ave%20Nashville,%20TN%2037232&sensor=false
#Rename columns
BrCACenters <- BrCACenters %>% rename(Lat = lat, Lon = lon)
BrCACenters <- bind_cols(Hosp2, BrCACenters)
#Format labels
Label <- paste("<strong>Hospital: </strong>", BrCACenters$Hospital, "<br><strong>Address:  </strong>", BrCACenters$Address, "<br><strong>Phone Number: </strong>", BrCACenters$Phone)
#Create leaflet file with treatment centers
m <-leaflet() %>% addTiles() %>% addMarkers(lng = BrCACenters$Lon, lat=BrCACenters$Lat, popup = Label)%>% fitBounds(-120, 47, -72, 29)
m

```

#Load shapefile
States <- readOGR("./States", "States")
## OGR data source with driver: ESRI Shapefile 
## Source: "./States", layer: "States"
## with 52 features
## It has 9 fields
States <- spTransform(States, CRS("+proj=longlat +datum=WGS84"))

leaflet() %>% addProviderTiles("Esri.WorldShadedRelief") %>% addPolygons(data = States, popup = ~NAME, color = "#D46A6A")%>% fitBounds(-120, 47, -72, 29)
MM <- read.csv("MandM.csv", header = TRUE, stringsAsFactors = FALSE)
head(MM,1)
##           State Incid_per_100000 Other Aver_Annual_Incid_Count
## 1 United States              6.6                         21761
##   Recent_Trend   Trend Death_per_100000 Aver_Deaths_per_Yr
## 1            0 falling              4.3              14690
##   Recent_Death_Trend
## 1             stable
#Trim data frame and rename columns
MM <- MM %>% rename(Incidence = Incid_per_100000, Diagnosed = Aver_Annual_Incid_Count, DeathPer100K = Death_per_100000, Death = Aver_Deaths_per_Yr, TrendInIncidence = Trend, TrendInDeath = Recent_Death_Trend) %>% select(State, Incidence, Diagnosed, TrendInIncidence, DeathPer100K, Death, TrendInDeath)
#Merging the shape and the incidence files.
CAByState <- merge(States, MM, by.x="NAME", by.y= "State")

#Design popup label for the Diagnosed density map.
State_Popup <- paste("<strong>State: </strong>", CAByState$NAME, "<strong>Average number of eople diagnosed annually: </strong>",CAByState$Diagnosed)

#Create color scheme for map. 
pal <- colorQuantile("PuRd", NULL, n = 4)
#Build Diagnosed density map
CancerbyState <- leaflet() %>% addProviderTiles("CartoDB.PositronNoLabels") %>% addPolygons(data = CAByState, fillColor = ~pal(CAByState$Diagnosed), color = "##D46A6A", weight = 1, popup = ~State_Popup) %>% fitBounds(-120, 47, -72, 29)
CancerbyState
#Design popup label for the Deaths density map
State_Popup1 <- paste("<strong>State: </strong>", CAByState$NAME, "<strong>The average mortality annually is: </strong>",CAByState$Death)

#Create color scheme for map. 
pal <- colorQuantile("PuRd", NULL, n = 4)
#Build density map for deaths
CancerbyState1 <- leaflet() %>% addProviderTiles("CartoDB.PositronNoLabels") %>% addPolygons(data = CAByState, fillColor = ~pal(CAByState$Death), color = "##D46A6A", weight = 1, popup = ~State_Popup1) %>% fitBounds(-120, 47, -72, 29)
CancerbyState1
CancerbyState2 <- leaflet() %>% addProviderTiles("CartoDB.PositronNoLabels") %>% addPolygons(data = CAByState, fillColor = ~pal(Diagnosed), color = "##D46A6A", weight = 1, popup = ~State_Popup) %>% addMarkers(BrCACenters, lng = BrCACenters$Lon, lat = BrCACenters$Lat, popup = Label) %>% fitBounds(-120, 47, -72, 29)

CancerbyState2

CancerbyState1 <- leaflet() %>% addProviderTiles(“CartoDB.Positron”) %>% addPolygons(data = BrainCAByCounty, fillColor = ~pal(Rate_per_100000), color = “##D46A6A”, weight = 1, popup = ~State_Popup) %>% addMarkers(BrCACenters, lng = BrCACenters\(Lon, lat = BrCACenters\)Lat, popup = Label) %>% fitBounds(-120, 47, -72, 29)

CancerbyState1

Map choices found here