Contents

Is there a good way to list the dependencies (packages) upfront?

This gist produces a visualization of the location of the bombs that were dropped on London in the night of September, 7th, 1940 based on data provided by the Guardian Data Store & London Fire Brigade Records referenced by the website of the British National Archives http://bombsight.org.

This is an alternative method to arrive at something like Figure 5.2 of the book Modern Statistics for Modern Biology by Susan Holmes and Wolfgang Huber.

Instead of running Steps 1 and 2, you can also use the precomputed dataframe coordinates and charge ahead to Step 3 directly.

1 Download the street addresses

library("googlesheets")

addresses_url <- "https://docs.google.com/spreadsheets/d/1rL68hnF9bHHg3p72ti_reSvwK12VEdABN5Q7YADXm3I"
addresses <- gs_read(gs_url(addresses_url))

2 Query Google Maps to convert addresses into (latitude, longitude) coordinates

In order to query Google Maps, you need to set up the API key first, see ?googleway::set_key. As an alternative, if you don’t want to do this, you can use the dataframe coordinates that we provide along with this gist, see next step.

coordinates <- lapply(addresses$Location, function(loc) {
  x <- googleway::google_geocode(loc)
  x$results$geometry$location
}) %>% dpylr::bind_rows

save(coordinates, file = "Blitz-19400907-latlng.RData")

3 Alternatively, load a precomputed dataframe

This step is alternative to Steps 1 and 2.

load("Blitz-19400907-latlng.RData")

4 Display the locations on an online map and make a screenshot

We use the PhantomJS browser in order to do this. If it is not yet installed on your system, run the following chunk to do so:

## can we automaticallh check whether this needs to be run?
webshot::install_phantomjs()

Now we are ready to go:

library("leaflet")

bombsmap <- leaflet(coordinates) %>%
  addProviderTiles(providers$OpenStreetMap) %>%
  addCircleMarkers(color = "red",
                   radius = 5,
                   stroke = FALSE,
                   fillOpacity = 0.3) %>%
  setView(-0.1278, 51.5074, 12)

mapview::mapshot(bombsmap, file = "Blitz-19400907-latlng.png")

And here is the image:

Blitz-19400907-latlng.png

Blitz-19400907-latlng.png