Listening to ABC Radio National a couple of weeks ago, I learned about Sydney's Red Rooster line. It's a straight line that can be drawn across Sydney marking the socio-economic divide that exists between the northern and eastern suburbs of Sydney and the western and soutwestern ones. Out of curiosity, I set out to explore this using data available on the open web, in particular OpenStreetMap.

Map of Sydney with Red Rooster line

The above map was drawn in R using OpenStreetMap data for all its components.

In R, obtaining data from OpenStreetMap is most easily done using the osmdata library, which provides functions to create and send an Overpass query. For instance, the snippet below obtains all locations that have been tagged as a fast food amenity within a geographical bounding box. In the same way, all roads, waterways and suburb boundaries can be obtained.

fastfood <- lapply(bb, function(x) {
    opq(x, timeout = 50) |>
    add_osm_feature("amenity", "fast_food") |>
    osmdata_sf()})

One of the quirks of the returned data is that any geometrical shape that has an element of it within the bounding box of the query is returned in whole. When rendered on a map surface, this results in the map exceeding the boundaries of the bounding box. Using the st_intersection() function this can be corrected relatively easily.

More difficult is rendering the ocean in a particular color, as there is no polygon returned for the partial ocean within the query geometry. This contrary to waterways and lakes. I solved this creating an outline for the overall land area within the bounding box, and subtracting that area from its bounding box area.

outlines <- st_union(osm_multipolygons)

ocean <- function() {
    a <- st_difference(boundingBoxSfc, outlines)
    a <- st_transform(a, crs = st_crs(outlines))
    return(a)}

In the full code, available on my git server, I also plot Perth to see whether the same socio-economic dividing line can be found over here in Western Australia's capital. It's certainly possible to see the affluent western suburbs are not as well served by Red Rooster as the eastern and southern ones:

Map of Perth with Red Rooster locations