-
Notifications
You must be signed in to change notification settings - Fork 438
Expand file tree
/
Copy pathbuildMap.R
More file actions
35 lines (30 loc) · 952 Bytes
/
buildMap.R
File metadata and controls
35 lines (30 loc) · 952 Bytes
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
# BuildMap file: function that returns a plotly map
library(plotly)
library(stringr)
# BuildMap function: fill this in with a function that returns a map:
# Derived from: https://plot.ly/r/choropleth-maps/
BuildMap <- function(data, map.var) {
# give state boundaries a white border
l <- list(color = toRGB("white"), width = 2)
# specify some map projection/options
g <- list(
scope = 'usa',
projection = list(type = 'albers usa'),
showlakes = TRUE,
lakecolor = toRGB('white')
)
# Make equation for map color / text
var.equation <- paste0('~', map.var)
# Plot
p <- plot_geo(data, locationmode = 'USA-states') %>%
add_trace(
z = eval(parse(text = var.equation)), text = ~state, locations = ~code,
color = eval(parse(text = var.equation)), colors = 'Purples'
) %>%
colorbar(title = "Color Title") %>%
layout(
title = str_to_title(map.var),
geo = g
)
return(p)
}