-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplotly_demo.R
More file actions
80 lines (63 loc) · 2.49 KB
/
plotly_demo.R
File metadata and controls
80 lines (63 loc) · 2.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
require(maps)
require(tidyverse)
require(plotly)
# Set Plotly info
Sys.setenv("plotly_username"="amsilvr")
Sys.setenv("plotly_api_key"="kDoqXYPQYD2PqBVKpNA0")
# Create data frame
# Bring in data frame from CMAS Messages
if (!exists("alert_states")) source("CMAS_States.R")
# Join alert_tally to to return the matching county name
if (!exists("fips_lookup")) fips_lookup <- load_state_fips()
t <- select(fips_lookup, abb, name)
state_alert_df <- ungroup(alert_states) %>%
magrittr::set_colnames(value = tolower(colnames(.))) %>%
mutate(total = amber + flashflood + other + tornado + tsunami) %>%
group_by(abb) %>%
# select(StateAbbr, amber, flashflood, other, tornado, tsunami, total) %>%
summarize_all(sum) %>%
left_join(t)
# ##########
# # Create hover text
state_alert_df$hover <- with(state_alert_df
, paste('<b>',name, '<br />', 'Total:', total,'</b>'
, if_else(amber > 0
,true = paste('<br />','AMBER:', amber)
,false = '')
, if_else(flashflood > 0
,true = paste('<br />','Flash Flood:', flashflood)
,false = '')
, if_else(tornado > 0
,true = paste('<br />','Tornado:', tornado)
,false = '')
, if_else(tsunami > 0
,true = paste('<br />','Tsunami:', tsunami)
,false = '')
, if_else(other > 0
,true = paste('<br />','Others:', other)
,false = '')
)
)
# # Make state borders white
l <- list(color = toRGB("white"), width = 2)
# Set up some mapping options
g <- list(scope = 'usa'
, projection = list(type = 'albers usa')
, showlakes = TRUE
, lakecolor = toRGB("white")
)
p <- plot_geo(state_alert_df,locationmode = 'USA-states') %>%
add_trace(
z = ~total
, text = ~hover
, hoverinfo = "text"
, locations = ~abb
, color = ~total
, colors = 'Greens'
) %>%
colorbar(title = 'Total Alerts') %>%
layout(title = 'WARN Messages: <br />
May 2014 to March 2017'
, geo = g)
# chart_link = plotly_POST(p, filename = "warn_states")
# chart_link