
The course data and code are contained in the R Leaflet.zip file. You will need to download and unzip this file for the course.
Set up a leaflet map project in RStudio by downloading and unzipping data and code, creating a project and script, importing the data folder, and installing the leaflet package.
Load the leaflet package, create an html widget with leaflet(), add a base map with addTiles, and setView to Alaska to demonstrate a layered, pipe operator workflow.
See how the pipe operator from the Margaretha package chains map transformations in R Leaflet, forwarding the map through ad_tiles and set_view for clearer, minimal code.
Customize the base map in Leaflet by using addProviderTiles to switch tile sets, noting free options and API key needs, and explore provider themes before overlaying geographic data.
Overlay county shapefiles on a Leaflet map in R by loading with read Ohga, styling polygons, and adjusting smoothing for faster rendering, preparing for homicide data overlay.
Geocode Alaska homicide addresses using the GEMAP Geocode function, loop to fill missing coordinates, then left join coordinates to the data for overlay on a leaflet map.
Map unsolved crime cases of murder or manslaughter by filtering for crime solved as no, then overlay circle markers using coordinates and apply jitter to separate identical locations.
Enhance interactive maps by adding labels to circle markers in a leaflet map, convert the year to text, and build HTML labels using an html tools package.
Cluster map markers using the marker cluster options function to group markers and enable spidering at higher zooms. Tune show coverage on hover and other cluster options.
Add a checkbox control to toggle solved and unsolved markers on a Leaflet map, using overlay groups and layer controls to customize visibility and aesthetics.
Calculate state-level solve rates from FBI data by converting solved to 1/0, filter for murders, and align the results with a U.S. state shapefile for mapping.
Create a choropleth map of U.S. state solve rates by loading a shapefile, aligning data, defining color bins, and applying a color bin palette with legend and hover highlights.
Export maps with R Leaflet as static images or web pages, preserving dynamic features in html exports. Use mapshot with phantomjs for automated static exports, and saveWidget for html widgets.
Learn to embed leaflet maps in an R Markdown report, creating static Word outputs and dynamic HTML reports by using markdown basics, code chunks, and include/echo options to control display.
Embed a leaflet map into a shiny dashboard, build a reactive user interface with a date range slider and data table, and optimize performance with leaflet proxy.
Leaflet.js is one of the most popular libraries for creating beautiful looking maps. Companies like Facebook, Pinterest, and The Washington Post use Leaflet to create maps that draw-in and engage viewers in a unique way.
In this course, we'll be using the Leaflet package for R to analyze FBI homicide data in the United States.