Peer-Graded Assignment: R Markdown Presentation & Plotly

Innuganti

September 24, 2018

Set up mapping options

(echo = TRUE)
## [1] TRUE
head(assaults)
##   State Victim_Officers Total_Officers_Employed Rate Rate2
## 1    AK             717                   1,229 0.58    58
## 2    AL             920                   4,554 0.20    20
## 3    AR             343                   5,685 0.06     6
## 4    AZ           2,452                  12,336 0.20    20
## 5    CA          10,776                  78,094 0.14    14
## 6    CO           1,325                  12,164 0.11    11
##                                                                             hover
## 1     AK <br> Rate 58 <br> Victim_Officers 717 <br> Total_Officers_Employed 1,229
## 2     AL <br> Rate 20 <br> Victim_Officers 920 <br> Total_Officers_Employed 4,554
## 3      AR <br> Rate 6 <br> Victim_Officers 343 <br> Total_Officers_Employed 5,685
## 4  AZ <br> Rate 20 <br> Victim_Officers 2,452 <br> Total_Officers_Employed 12,336
## 5 CA <br> Rate 14 <br> Victim_Officers 10,776 <br> Total_Officers_Employed 78,094
## 6  CO <br> Rate 11 <br> Victim_Officers 1,325 <br> Total_Officers_Employed 12,164
# Make state borders white

borders <- list(color = toRGB("red"))

# Set up some mapping options

map_options <- list(

        scope = 'usa',

        projection = list(type = 'albers usa'),

        showlakes = TRUE,

        lakecolor = toRGB('blue'))

Interactive choropleth Map

When your mouse hovers the map it display intercatively
plot_ly(assaults, z = ~assaults$Rate2, text = ~assaults$hover, locations = ~assaults$State, type = 'choropleth', locationmode = 'USA-states',

        color = assaults$Rate2, colors = 'Oranges', marker = list(line =borders)) %>%

        layout(title = 'Police Officers Assaulted Nationwide in 2017', geo =map_options)