Site icon R-bloggers

All Roads Lead to Rome

[This article was first published on R on datawookie, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

I was inspired by this visualisation, showing the optimal routes (by car) from the geographic centre of the USA to all counties.

The proverb “All Roads Lead to Rome” immediately came to mind and I set out to hack together something along that theme.

This is what was required:

  1. Find a list of major cities in Europe and Asia.
  2. Use OSRM to generate routes from each of these cities to Rome. This was slightly tricky. I used pmap() from {purrr} to loop over the cities. I had to be respectful of the load on the OSRM server and only make requests at a civilised cadence. I also had to handle exceptional conditions where the server returned an error. It took a iterations to get that right.
  3. Generate a plot using {ggplot2}.

Here’s the result. The step size in some areas is a little large, but I’m pretty happy with it as a first attempt.

The code can be found here. Please be cognisant of the fact that there are many people querying the OSRM server. Consider either spinning up your own local server (see this post) or lowering the cadence of the routing queries. Alternative, feel free to greb an RDS with the routing data here.

To leave a comment for the author, please follow the link and comment on their blog: R on datawookie.

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.