The Health Facilities Map of Haryana

Using Open Street Maps database to map out the health facilities in Haryana State

Maps
Public Health
India
Haryana
Author

Aditya Dahiya

Published

September 6, 2024

Figure 1: Map of Haryana showing locations of the health facilities - pharmacies, doctors’ and dentists’ clinics, and hospitals.

How I made this graphic?

Loading libraries & data

Code
# Data Import and Wrangling Tools
library(tidyverse)            # All things tidy
library(here)                 # File locations and paths

# Final plot tools
library(scales)               # Nice Scales for ggplot2
library(fontawesome)          # Icons display in ggplot2
library(ggtext)               # Markdown text support for ggplot2
library(showtext)             # Display fonts in ggplot2
library(colorspace)           # Lighten and Darken colours
library(patchwork)            # Combining plots

# Mapping tools
library(sf)                   # All spatial objects in R
library(osmdata)              # Getting Open Street Maps data

hy_bbox <- osmdata::getbb("Haryana")

# hy_health_docs <- opq(bbox = hy_bbox) |> 
#   add_osm_feature(
#     key = "amenity",
#     value = c("clinic", "dentist", "doctors")
#   ) |> 
#   osmdata_sf()
# 
# hy_health_hospitals <- opq(bbox = hy_bbox) |> 
#   add_osm_feature(
#     key = "amenity",
#     value = c("hospital", "nursing_home")
#   ) |> 
#   osmdata_sf()
# 
# hy_health_pharmacy <- opq(bbox = hy_bbox) |> 
#   add_osm_feature(
#     key = "amenity",
#     value = c("pharmacy")
#   ) |> 
#   osmdata_sf()
# Getting Haryana Roads and streets data
hy_roads <- opq(bbox = hy_bbox) |> 
  add_osm_feature(
    key = "highway", 
    value = c("trunk")
  ) |> 
  osmdata_sf()

hy_roads1 <- opq(bbox = hy_bbox) |> 
  add_osm_feature(
    key = "highway", 
    value = c("motorway")
  ) |> 
  osmdata_sf()

hy_roads2 <- opq(bbox = hy_bbox) |> 
  add_osm_feature(
    key = "highway", 
    value = c("primary")
  ) |> 
  osmdata_sf()

hy_roads3 <- opq(bbox = hy_bbox) |> 
  add_osm_feature(
    key = "highway", 
    value = c("secondary")
  ) |> 
  osmdata_sf()

# Save the large list objects to disk
# saveRDS(hy_health_docs, here("data", "hy_health_docs.rds"))
# saveRDS(hy_health_hospitals, here("data", "hy_health_hospitals.rds"))
# saveRDS(hy_health_pharmacy, here("data", "hy_health_pharmacy.rds"))

# Reload the downloaded data:
hy_health_docs <- readRDS(here("data", "hy_health_docs.rds"))
hy_health_hospitals <- readRDS(here("data", "hy_health_hospitals.rds"))
hy_health_pharmacy <- readRDS(here("data", "hy_health_pharmacy.rds"))

hy_map <- read_sf(here("data", "haryana_map", "HARYANA_DISTRICT_BDY.shp")) |> 
  st_transform(crs = 4326) |> 
  # as_tibble() |> 
  janitor::clean_names() |> 
  mutate(
    district = str_to_sentence(district),
    district = str_replace_all(district, ">", "a"),
    district = str_replace_all(district, "\\|", "i")
  )

Visualization Parameters

Code
# Font for titles
font_add_google("Quattrocento",
  family = "title_font"
) 

# Font for the caption
font_add_google("Stint Ultra Condensed",
  family = "caption_font"
) 

# Font for plot text
font_add_google("Saira Extra Condensed",
  family = "body_font"
) 

showtext_auto()

bg_col <- "white"

text_col <- "grey5"
text_hil <- "grey10"

mypal <- paletteer::paletteer_d("NineteenEightyR::sunset2")[1:3]
mypal

bts <- 80

# Caption stuff for the plot
sysfonts::font_add(
  family = "Font Awesome 6 Brands",
  regular = here::here("docs", "Font Awesome 6 Brands-Regular-400.otf")
)
github <- "&#xf09b"
github_username <- "aditya-dahiya"
xtwitter <- "&#xe61b"
xtwitter_username <- "@adityadahiyaias"
social_caption_1 <- glue::glue("<span style='font-family:\"Font Awesome 6 Brands\";'>{github};</span> <span style='color:{text_hil}'>{github_username}  </span>")
social_caption_2 <- glue::glue("<span style='font-family:\"Font Awesome 6 Brands\";'>{xtwitter};</span> <span style='color:{text_hil}'>{xtwitter_username}</span>")

plot_title <- "Health Map of Haryana"

plot_subtitle <- plot_subtitle <- glue::glue("Locations of <b style='color:{mypal[3]}'>Hospitals</b>, <b style='color:{mypal[2]}'>doctors' Clinics</b> and <b style='color:{mypal[1]}'>Pharmacies</b>.")

plot_caption <- paste0(
  "**Data:** Open Street Maps", 
  " |  **Code:** ", 
  social_caption_1, 
  " |  **Graphics:** ", 
  social_caption_2
  )

rm(github, github_username, xtwitter, 
   xtwitter_username, social_caption_1, 
   social_caption_2)

The static plot

Code
g <- ggplot() +
  
  # Outline Map of Haryana and districts
  geom_sf(
    data = hy_map,
    colour = "grey15",
    fill = "grey98",
    linewidth = 0.4,
    linejoin = "round"
  ) +
  
  # Main Roads of Haryana - Motorways, Trunk, Primary & Secondary Roads
  geom_sf(
    data = hy_roads1$osm_lines |> 
            st_transform(crs = 4326) |> 
            st_intersection(hy_map),
    colour = "grey30",
    alpha = 0.5,
    linewidth = 0.4,
    linetype = 1
  ) +
  geom_sf(
    data = hy_roads$osm_lines |> 
            st_transform(crs = 4326) |> 
            st_intersection(hy_map),
    colour = "grey30",
    alpha = 0.4,
    linewidth = 0.2,
    linetype = 1
  ) +
  geom_sf(
    data = hy_roads2$osm_lines |> 
            st_transform(crs = 4326) |> 
            st_intersection(hy_map),
    colour = "grey30",
    alpha = 0.4,
    linewidth = 0.1,
    linetype = 1
  ) +
   geom_sf(
    data = hy_roads3$osm_lines |> 
            st_transform(crs = 4326) |> 
            st_intersection(hy_map),
    colour = "grey30",
    alpha = 0.3,
    linewidth = 0.1,
    linetype = 1
  ) +
  
  # Labels of the districts names
  geom_sf_text(
    data = hy_map,
    colour = text_col,
    mapping = aes(
      label = district
    ),
    size = bts/3,
    family = "body_font",
    alpha = 0.5
  ) +
  
  # Pharmacies
  geom_sf(
    data = hy_health_pharmacy$osm_points |> 
      st_transform(crs = 4326) |> 
      st_intersection(hy_map),
    colour = mypal[1],
    size = 3,
    pch = 1,
    linewidth = 0.2
  ) +
  
  # Hospitals
  geom_sf(
    data = hy_health_hospitals$osm_points |> 
      st_transform(crs = 4326) |> 
      st_intersection(hy_map),
    colour = mypal[3],
    size = 3,
    pch = 1,
    linewidth = 0.2
  ) +
  # geom_sf(
  #   data = hy_health_hospitals$osm_polygons |> 
  #     st_transform(crs = 4326) |> 
  #     st_intersection(hy_map),
  #   colour = mypal[3],
  #   linewidth = 0.5
  # ) +
  # geom_sf(
  #   data = hy_health_hospitals$osm_multipolygons |> 
  #     st_transform(crs = 4326) |> 
  #     st_intersection(hy_map),
  #   colour = mypal[3],
  #   linewidth = 0.5
  # ) +
  
  # Doctors, Dentists etc.
  geom_sf(
    data = hy_health_docs$osm_points |> 
      st_transform(crs = 4326) |> 
      st_intersection(hy_map),
    colour = mypal[2],
    size = 3,
    pch = 1,
    linewidth = 0.2
  ) +
  
  # geom_sf(
  #   data = hy_health_docs$osm_polygons |> 
  #     st_transform(crs = 4326) |> 
  #     st_intersection(hy_map),
  #   colour = mypal[2],
  #   linewidth = 0.5
  # ) +
  
  # Themes and Labels
  labs(
    title = plot_title,
    subtitle = plot_subtitle,
    caption = plot_caption
  ) +
  ggthemes::theme_map(
    base_size = bts,
    base_family = "body_font"
  ) + 
  theme(
    text = element_text(
      colour = text_hil
    ),
    plot.title = element_text(
      size = bts * 3.5,
      hjust = 0.5,
      face = "bold",
      margin = margin(5,0,5,0, "mm"),
      colour = text_hil
    ),
    plot.caption = element_textbox(
      colour = text_hil,
      hjust = 0.5,
      family = "caption_font",
      margin = margin(0,0,0,0, "mm"),
      size = bts / 3
    ),
    plot.subtitle = element_textbox(
      colour = text_hil,
      hjust = 0.5,
      face = "bold",
      margin = margin(5,0,0,0, "mm"),
      size = 2 * bts
    ),
    plot.title.position = "plot",
    plot.margin = margin(10, -20, 10, -20, "mm")
  )

ggsave(
  filename = here::here("data_vizs", "poster_health_map_hy.png"),
  plot = g,
  width = 24,   
  height = 36,   
  units = "in",
  bg = "white"
)

Savings the graphics

Code
library(magick)
# Saving a thumbnail for the webpage
image_read(here::here("data_vizs", "poster_health_map_hy.png")) |> 
  image_resize(geometry = "400") |> 
  image_write(here::here("data_vizs", 
                         "thumbnails", 
                         "health_map_hy.png"))