Interactive maps

This uses the same data from the mapping practical - airbnbs and hotels (OSM) in London. Run all of that code before starting this!

## Reading layer `gis_osm_pois_free_1' from data source 
##   `C:\Users\Andy\OneDrive - University College London\Teaching\CASA0005\CASA0005repo\prac5_data\greater-london-latest-free.shp\gis_osm_pois_free_1.shp' 
##   using driver `ESRI Shapefile'
## Simple feature collection with 57306 features and 4 fields
## Geometry type: POINT
## Dimension:     XY
## Bounding box:  xmin: -0.5090921 ymin: 51.29201 xmax: 0.2957296 ymax: 51.68432
## Geodetic CRS:  WGS 84
## Reading layer `London_Borough_Excluding_MHW' from data source 
##   `C:\Users\Andy\OneDrive - University College London\Teaching\CASA0005\CASA0005repo\prac1_data\statistical-gis-boundaries-london\ESRI\London_Borough_Excluding_MHW.shp' 
##   using driver `ESRI Shapefile'
## Simple feature collection with 33 features and 8 fields
## Geometry type: MULTIPOLYGON
## Dimension:     XY
## Bounding box:  xmin: 503568.2 ymin: 155850.8 xmax: 561957.5 ymax: 200933.9
## Projected CRS: OSGB36 / British National Grid

To make our map interactive we change tmap_mode() from plot to view..

tmap_mode("view")

tm_shape(Accomodation_contained) + 
  tm_polygons("hotels_n") 

8.33 Advanced interactive map

But let’s take it a bit further so we can select our layers on an interactive map..Let’s set a few more things up:

  • Our CRS needs to be in WGS84
Accomodation_containedWGS84<- Accomodation_contained %>%
  st_transform(., 4326)

Similar to our static maps we must:

  • First define the shape object
  • Then load the map layer (e.g. polygons)

Here, we also set a group which links the polygon both the legend and button selection options.

tmap_mode("view")

# Build the map

  # Airbnb layer
map <-  tm_shape(Accomodation_containedWGS84) +
        tm_polygons(fill="airbnbs_n",
                    fill.scale = list(tm_scale_intervals(values = "brewer.blues", breaks=breaks$brks)),
                    fill_alpha=0.5,
                    col="white",
                    lwd=2,
                    lty="dashed",
                    # select columns for popup
                    popup.vars=c("airbnbs_n", "NAME"),
                    group="Airbnb") + 
        
  # hotel layer  
        tm_polygons(fill="hotels_n",
                    fill.scale = list(tm_scale_intervals(values = "brewer.blues", breaks=breaks$brks)),
                    fill_alpha=0.5,
                    col="white",
                    lwd=2,
                    lty="dashed",
                    popup.vars=c("hotels_n", "NAME"),
                    group="Hotels")+
    # basemap
          tm_basemap(server = c("OpenStreetMap", "Thunderforest.Landscape"))
        

map

To see other basemap options (there are loads!) have a look here at leaflet extras

Cosh, Georgie. 2020. GLA Housing and Land Short-term and holiday letting in London.”
Donoho, David. 2017. 50 Years of Data Science.” Journal of Computational and Graphical Statistics 26 (4): 745–66. https://doi.org/10.1080/10618600.2017.1384734.
Glassdoor. 2020. 50 Best Jobs in America for 2019.” https://www.glassdoor.co.uk/List/Best-Jobs-in-America-LST_KQ0,20.htm.
Grolemund, Garrett., and Hadley. Wickham. 2017. R for Data Science. O’Reilly.
Guha, Subhanil, Himanshu Govil, Anindita Dey, and Neetu Gill. 2018. Analytical study of land surface temperature with NDVI and NDBI using Landsat 8 OLI and TIRS data in Florence and Naples city, Italy.” European Journal of Remote Sensing 51 (1): 667–78. https://doi.org/10.1080/22797254.2018.1474494.
Li, Songnian, Suzana Dragicevic, Francesc Antón Castro, Monika Sester, Stephan Winter, Arzu Coltekin, Christopher Pettit, et al. 2016. Geospatial big data handling theory and methods: A review and research challenges.” ISPRS Journal of Photogrammetry and Remote Sensing 115: 119–33. https://doi.org/10.1016/j.isprsjprs.2015.10.012.
Lovelace, Robin., Jakub. Nowosad, and Jannes. Muenchow. 2019. Geocomputation with R. CRC Press. https://doi.org/10.1201/9780203730058.
Pattabiraman, Kumaresh. 2019. LinkedIn’s Most Promising Jobs of 2019.” https://blog.linkedin.com/2019/january/10/linkedins-most-promising-jobs-of-2019.
The Universities and Colleges Admissions Service. 2020. UCAS Postgraduate courses.” https://digital.ucas.com/coursedisplay/results/providers?studyYear=2019{\&}destination=Postgraduate{\&}postcodeDistanceSystem=imperial{\&}pageNumber=1{\&}sort=MostRelevant{\&}searchTerm=data science.