6 Create interactive map with leaflet package

To learn about leaflet functions: (https://rstudio.github.io/leaflet/)

6.1 Why interactive maps?:

  • Static maps are useful for creating figures for reports and presentation. Sometimes, however, you want to interact with your data. You can use the leaflet package for R to overlay your data on top of interactive maps.
  • Leaflet supports various elements for the composition of maps such as Map tiles, Markers, Polygons, Lines, Popups, and GeoJSON.
  • Create a collaborative work, and share the results of your study, in an attractive way.

6.2 Add layers (markers, tiles, polygons)

6.3 Add the Snowy owl data

  • addCircleMakers function to add the data with x (longitude) and y (latitude) axis. Similar than geom_point from ggplot.

6.4 Customize Leaflet Maps

You can customize your leaflet map too. Let’s do the following:

6.5 Add Scale bar

  • To add a scale bar, need function addScaleBar

6.6 Add Popups

  • To add popups, you need to use popup in addCircleMarkers and set the colum you want to show in your popup (here the localisation of the birds observed)

6.7 Customize your popup

  • To customize your own popup, you need to use html
  • Hello b is bold tex Hello, in bold text

  • br adds a line break
  • Then you can specify replace popup = ~locality with the name of your popup created (here mypopup)
  • If you want to save and share your collaborative map, you can use the function saveWidget from the package htmlWidgets.