townsendr interactive map

August 20, 2016

(This article was first published on rstats –, and kindly contributed to R-bloggers)

This week I updated my Townsend Material Deprivation Score project. The update makes townsendr an interactive online map of deprivation that users can simply view in their browser, rather than having to download and run the R code or view only static maps. I think the result is much more intuitive and useful. Making the map interactive is achieved by using Shiny, a technology for R to make interactive charts and plots. As well as this, the maps are now rendered by leaflet rather than ggplot2. ggplot2 is an awesome technology for making beautiful charts in R, but leaflet is a javascript library designed specifically for plotting interactive maps so rendering the map is now so effortless it felt like cheating.

The data is based on the relevant census tables obtained from Nomis. The shapefiles are obtained from the UK Data Service, but are greatly simplified (even the generalised versions were about 5MB, much too big for interactive use). Both are available under open licenses. For more information see the townsendr web page or the GitHub repository. Pull requests are very welcome.

I’m really happy with the result, which is my first attempt using Shiny and leaflet, but there’s more work to do (when I have time!). Specifically I think the following need addressing:

  • London probably needs removing from the analyses because car ownership and home ownership are low in London even among households that aren’t deprived.
  • The colour scale needs more contrast between high and low deprivation (although this might be corrected by removing London!). I might even create bands that show quantiles of deprivation.
  • The legend needs improving, specifically it should be clearer that darker blue = more deprivation. The z-scores probably aren’t that useful to someone who doesn’t know what they signify.

If you notice anything else, fix it and submit a pull request or file an issue for me to address!

To leave a comment for the author, please follow the link and comment on their blog: rstats – offers daily e-mail updates about R news and tutorials on topics such as: Data science, Big Data, R jobs, visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...

If you got this far, why not subscribe for updates from the site? Choose your flavor: e-mail, twitter, RSS, or facebook...

Comments are closed.

Search R-bloggers


Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)