R bloggers

Mapping data using R and leaflet

FavoriteLoadingAdd to favorites

The R language provides many different tools for creating maps and adding data to them. I’ve been using the leaflet package at work recently, so I thought I’d provide a short example here. Whilst searching for some data that might make a nice map, I came across this article at ABC News. It includes a table containing Australian members of parliament, their electorate and their voting intention regarding legalisation of same-sex marriage. Since I reside in New South Wales, let’s map the data for electorates in that state. Here’s the code at Github. The procedure is pretty straightforward: Obtain a shapefile of New South Wales electorates (from here) and read into R Read the data from the ABC News web page into a data frame (very easy using rvest) Match the electorate names from the two sources (they match perfectly,…
Original Post: Mapping data using R and leaflet