John Lekberg


Chicago, Distance to MMR vaccination sites

Created 2019-08-26.

A heatmap showing distance to nearest MMR vaccination sites in Chicago.

This graphic uses the City of Chicago's "Special Vaccine Locations - MMR" dataset, which has location data for sites that guarantee MMR vaccines will be in-stock and available.

Given the locations of these sites, I was interested in visualizing an answer to the question "how far away am I from a vaccine site?".

We can see that there are many vaccination sites in the Loop and the near north side, but less in the south side and the west side of the city.

I made a heuristic "distance" function:

distance <- function(longitude, latitude) {
  dx <- longitude - df$longitude
  dy <- latitude - df$latitude
  d1 <- sqrt(dx^2 + dy^2)
  d2 <- min(abs(dx) + abs(dy))
  return(min(.9*d1+.1*d2))
}

Where df is a dataframe of vaccination locations.

I think the graphic could be improved by using a better distance estimate, something that would take into account walking distance, or public transportation.

I think the graphic could also be improved by using boundary data for the city, because I compute a mesh for a bounding box:

expand.grid(
  seq(-87.85, -87.55, by=.0025),
  seq(41.65, 42.05, by=.0025)
)

I tried to handle this by filtering things within a "distance" of .05 (a value I empirically determined to cause the graphic to "look nice"), but I think a more meaningful bounding would be to use the city boundaries proper.


Code used to create "Chicago, Distance to MMR vaccination sites"


code.r - A fragment of the code used to produce the graphic.
# distance function
distance <- function(longitude, latitude) {
  dx <- longitude - df$longitude
  dy <- latitude - df$latitude
  d1 <- sqrt(dx^2 + dy^2)
  d2 <- min(abs(dx) + abs(dy))
  return(min(.9*d1+.1*d2))
}

# DATA
expand.grid(
  seq(-87.85, -87.55, by=.0025),
  seq(41.65, 42.05, by=.0025)
) %>%
  set_colnames(c("longitude", "latitude")) %>%
  data.frame %>%
  # TRANS
  mutate(closest = Vectorize(distance)(longitude, latitude)) %>%
  filter(closest <= .05) %>%
  #
  ggplot() +
    # SCALE
    scale_fill_viridis(
      option="magma", direction=-1,
      limits=c(0, 0.05), breaks=c(0, 0.05),
      labels = c("At vaccination site", "Further from\nvaccination site"),
      name = ""
    ) +
    # COORD
    coord_fixed(1) +
    # GUIDE
    ggtitle(
      "Chicago - Distance to MMR vaccination sites",
      subtitle = "\"MMR\" stands for \"Measles, Mumps, and Rubela\""
    ) +
    # ELEMENT
    geom_tile(aes(longitude, latitude, fill=closest)) +
    # THEME
    theme_bw()