This repository has been archived by the owner on Sep 2, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
map.R
36 lines (27 loc) · 1.42 KB
/
map.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
# map.R - Geographical Visualisation of dynamic microsimulation results
#' map
#'
#' Displays a map outlining the MSOAs within Tower Hamlets, filling with a colour derived from the supplied data
#' @param data a data.table (or data.frame) containing a column "MSOA" containing the MSOA code and
#' a column "Value" containing numeric data to be plotted
#' @param minColour colour for the lowest value of the data
#' @param maxColour colour for the lowest value of the data
#' @examples
#' p = microsynthesise()
#' d = diversity(p)
#' m = map(d)
#' @export
map = function(data, minColour = "#0080FF", maxColour= "#FF8000") {
# makes use of the following lazy-loaded package data: msoa
# Scale up growth to display as percentage
data$Value = data$Value * 100.0
map = leaflet() %>% addTiles(urlTemplate = "//a.basemaps.cartocdn.com/light_all/{z}/{x}/{y}.png")#, options=tileOptions(opacity=0.5))
# Use of these tiles requires an acknowledgement
cat("Map tiles by Carto, under CC BY 3.0. Data by OpenStreetMap, under ODbL\n")
pal=colorNumeric(c(minColour,maxColour),c(min(data$Value),max(data$Value)))
map = map %>% addPolygons(data = msoa[msoa$code==data$MSOA,], fillColor = pal(data$Value), fillOpacity=.2, weight=1, color = "black") %>%
addLegend("bottomleft", pal = pal, values = c(min(data$Value),max(data$Value)),
labFormat = labelFormat(suffix = "%"),
opacity = .5)
return(map)
}