class: center, middle, inverse, title-slide # Data Visualization ## Making sliding maps ### Andrew Irwin,
a.irwin@dal.ca
### Math & Stats, Dalhousie University ### 2021-03-17 (updated: 2021-03-06) --- class: middle # Plan * Kinds of maps * Basic maps * Adding points * Shading areas * Tile service providers --- class: middle ### Map libraries * Dynamic: `leaflet` for drawing raster or tiled maps (leafletjs.com) * Static: `ggmap` (part of tidyverse, has stamen map functions) --- ### A basic map ```r m <- leaflet() %>% addTiles() %>% # Add default OpenStreetMap map tiles addMarkers(lng=-63.5932, lat=44.63697, popup="Math & Stats, Dalhousie U") ``` --- ### A basic map
--- ### Adding points ```r cities <- read_csv("../static/selected_cities.csv") m2 <- leaflet(data = cities) %>% addTiles() %>% addCircleMarkers(~ lng, ~lat, label = ~city) ``` --- ### Adding points
--- ### Colour regions ```r library(geojsonio) pal <- colorNumeric("viridis", NULL) # make a viridis palette canada <- geojson_read("https://gist.githubusercontent.com/mikelotis/2156d7c170d10d2c77cb79424fe2137d/raw/7a13748ed7ea5ba64876c77c53b6cb64dd5c3ab0/canada-province.geojson", what="sp") my_values = runif(13, 0, 10) # random numbers between 0 and 10 m3 <- canada %>% leaflet() %>% addTiles() %>% addPolygons(fillColor = ~ pal(my_values), weight = 1, color = "black") %>% addLegend(pal = pal, values = my_values, opacity = 1.0) ``` --- ### Colour regions
--- ### Other tiled map services ```r mymap_terrain <- get_stamenmap(bbox = c(left = -130, bottom = 41, right = -50, top = 66), zoom=5, maptype = "terrain") m4 <- ggmap(mymap_terrain) ``` --- ### Other tiled map services <img src="28-sliding-maps_files/figure-html/unnamed-chunk-7-1.png" width="90%" style="display: block; margin: auto;" /> --- ### Add text and points ```r my_points <- tibble(lat = c(43+57/60, 49+53/60), lon = c(-59-55/60, -97-9/60), label = c("Sable Is.", "Winnipeg") ) m5 <- ggmap(mymap_terrain) + geom_point(data = my_points, color="brown") + geom_label(data = my_points, aes(label=label), fill = "#FFFFFF90", color = "black", nudge_y = 1.5) ``` --- #### Add text and points <img src="28-sliding-maps_files/figure-html/unnamed-chunk-9-1.png" width="90%" style="display: block; margin: auto;" /> --- class: middle ### Summary * Make a basic map * Add points and labels * Fill regions with colour (requires polygons) * There are several tile services --- class: middle # Further reading * Course notes --- class: middle, inverse ## Task * Task 15. Make some maps as described in repository