This repository has been archived by the owner on Apr 25, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathproof_of_concept.R
98 lines (72 loc) · 3.85 KB
/
proof_of_concept.R
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
library(tidyverse)
library(leaflet)
library(leaflet.extras)
library(htmlwidgets)
library(igraph)
library(scales)
# data manipulation & prep ------------------------------------------------
# load organizations csv
geo_data <- read_csv("geo_all.csv")
# network definition ------------------------------------------------------
# map definition ---------------------------------------------------------
map <- leaflet(data = geo_data, options = leafletOptions(minZoom = 11, maxZoom = 18, preferCanvas = TRUE)) %>%
addProviderTiles(providers$OpenStreetMap.BlackAndWhite, group = 'Grayscale') %>%
addTiles(group = 'Color') %>%
# restrict boundaries to around Baltimore (doesn't seem to work as expected)
fitBounds(lng1 = min(geo_data$lon) - 0.11,
lat1 = min(geo_data$lat) - 0.11,
lng2 = max(geo_data$lon) + 0.11,
lat2 = max(geo_data$lat) + 0.11) %>%
# set default view to downtown Baltimore
setView(lng = -76.62, lat = 39.29, zoom = 12) %>%
# addCircleMarkers(data = geo_data, ~lon, ~lat, stroke = FALSE, radius = ~log(ASSET_AMT + 100),
# fillOpacity = .5, popup = ~ paste( NAME, "<br/>",
# "Address:", STREET, "<br/>",
# "Assets:", ASSET_AMT, "<br/>",
# "Income:", INCOME_AMT, "<br/>",
# "Revenue:", REVENUE_AMT, "<br/>",
# "Category:", codes),
#
# group="circles") %>%
#
addMarkers(clusterOptions = markerClusterOptions(),
data = geo_data,
~lon,
~lat,
popup = ~ paste(NAME, '<br/>',
'<strong>Address:</strong>', STREET, '<br/>',
'<strong>Assets:</strong>', scales::comma(ASSET_AMT), '<br/>',
'<strong>Income:</strong>', scales::comma(INCOME_AMT), '<br/>',
'<strong>Revenue:</strong>', scales::comma(REVENUE_AMT), '<br/>',
'<strong>Category:</strong>', codes),
group="circles") %>%
addResetMapButton() %>%
# search doesn't work with clustered points, use regular markers 1px by 1px for search
addMarkers(data = geo_data, ~lon, ~lat, label = geo_data$NAME, group = 'blanks',
icon = makeIcon(
iconUrl = "http://leafletjs.com/examples/custom-icons/leaf-green.png",
iconWidth = 1, iconHeight = 1)) %>%
addSearchFeatures(targetGroups = 'blanks',
options = searchFeaturesOptions(zoom=17,
openPopup = TRUE,
firstTipSubmit = TRUE,
autoCollapse = TRUE,
hideMarkerOnCollapse = FALSE)) %>%
# Add user controls to toggle map tiles displayed
addLayersControl(
baseGroups = c('Grayscale', 'Color'),
options = layersControlOptions(collapsed = TRUE)
) %>%
addControl('<P>
<strong>
Hint!
</strong>
<br>
Search for your organization with the magnifying glass button.
</P>',
position='bottomright')
map
# map export --------------------------------------------------------------
# save map as html document
sav.file <- '/Users/jbjrV/OneDrive/syncthecity.github.io/index.html'
saveWidget(map, file=sav.file, selfcontained = F)