Mapping 459 coal mines across India, with dots sized by annual production (MT). The largest 35 mines, driving significant output, are labelled with names, production figures, districts, and states, revealing key hubs of India’s coal industry.
Figure 1: This map visualizes 459 coal mines in India, with dots sized by annual production (MT). The largest 35 mines are labelled with names, output, districts, and states, highlighting key coal hubs. Data from Sandeep Pai and Hisham Zerriffi’s “Indian coal mine dataset.” Created using R packages: ggplot2, sf, tidyterra, ggmap, and ggrepel.
How I made this graphic?
The code generates a detailed map of coal mine locations in India using data from the “Indian coal mine location and production - December 2020” dataset, retrieved via the dataverse package. The Excel data is imported with readxl (alternatively, usign {dataverse} for directly getting the data from HArvard Dateverse, and cleaned using janitor. Geospatial data is processed with sf for vector layers and terra for raster data, integrated into ggplot2 visualizations via tidyterra. A base map is sourced using ggmap, with spatial enhancements like scales and north arrows added by ggspatial. Aesthetic improvements are made with scales, fontawesome, ggtext, showtext, and colorspace. Key techniques include geom_spatraster_rgb() for rendering the raster base map, geom_sf() for overlaying coal mine locations sized by production, and ggrepel::geom_label_repel() for non-overlapping labels of significant mines. The final plot is crafted and saved using ggplot2’s layering system, enhanced by custom fonts and themes.
Loading required libraries, data import
Code
# Plot touch-up toolslibrary(scales) # Nice Scales for ggplot2library(fontawesome) # Icons display in ggplot2library(ggtext) # Markdown text support for ggplot2library(showtext) # Display fonts in ggplot2library(colorspace) # Lighten and Darken colours# Getting geographic data library(sf) # Simple Features in Rlibrary(terra) # Cropping / Masking rasterslibrary(tidyterra) # Rasters with ggplot2library(ggspatial) # Scales and Arrows on maps# Data Wrangling & ggplot2library(tidyverse) # All things tidylibrary(patchwork) # Composing plots# Accessing Harvard Dataverselibrary(dataverse) # Access Harvard Dataverseraw_data <- dataverse::get_dataframe_by_name(filename ="Indian Coal Mines Dataset_January 2021-1.tab",dataset ="doi:10.7910/DVN/TDEK8O",.f = readxl::read_excel,server ="dataverse.harvard.edu")raw_data <- readxl::read_excel(path ="Indian Coal Mines Dataset_January 2021-1.xlsx",sheet =2) |> janitor::clean_names()
Visualization Parameters
Code
# Font for titlesfont_add_google("Saira",family ="title_font") # Font for the captionfont_add_google("Saira Extra Condensed",family ="caption_font") # Font for plot textfont_add_google("Saira Condensed",family ="body_font") showtext_auto()mypal <-c("#C35BCAFF", "#FD7901FF", "#0E7175FF")# A base Colourbg_col <-"white"seecolor::print_color(bg_col)# Colour for highlighted texttext_hil <-"grey30"seecolor::print_color(text_hil)# Colour for the texttext_col <-"grey20"seecolor::print_color(text_col)# Define Base Text Sizebts <-90# Caption stuff for the plotsysfonts::font_add(family ="Font Awesome 6 Brands",regular = here::here("docs", "Font Awesome 6 Brands-Regular-400.otf"))github <-""github_username <-"aditya-dahiya"xtwitter <-""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_caption <-paste0("**Data:** Sandeep Pai (Harvard Dataverse)", " | **Code:** ", social_caption_1, " | **Graphics:** ", social_caption_2 )rm(github, github_username, xtwitter, xtwitter_username, social_caption_1, social_caption_2)# Alpha Values for dots and coloursalpha_value =0.6# Add text to plot-------------------------------------------------plot_title <-"Unearthing India's Coal: A Spatial Snapshot"plot_subtitle <-"Mapping 459 coal mines across India, with dots sized by annual production (MT). The largest 35 mines, driving significant output, are labelled with names, production figures, districts, and states, revealing key hubs of India's coal industry."data_annotation <-"**About the Data:** This map uses the **Indian coal mine location and production - December 2020** dataset from Harvard Dataverse, compiled by Sandeep Pai and Hisham Zerriffi via the *Right to Information Act, 2005*. Sourced from Coal India Limited, Singareni Collieries, NLC India Ltd., and others, it details *459 mines' locations* in India."|>str_wrap(30) |>str_replace_all("\\n", "<br>")
# Saving a thumbnaillibrary(magick)# Saving a thumbnail for the webpageimage_read(here::here("data_vizs", "viz_india_coalmines.png")) |>image_resize(geometry ="x400") |>image_write( here::here("data_vizs", "thumbnails", "viz_india_coalmines.png" ) )
Session Info
Code
# Plot touch-up toolslibrary(scales) # Nice Scales for ggplot2library(fontawesome) # Icons display in ggplot2library(ggtext) # Markdown text support for ggplot2library(showtext) # Display fonts in ggplot2library(colorspace) # Lighten and Darken colours# Getting geographic data library(sf) # Simple Features in Rlibrary(terra) # Cropping / Masking rasterslibrary(tidyterra) # Rasters with ggplot2library(ggspatial) # Scales and Arrows on maps# Data Wrangling & ggplot2library(tidyverse) # All things tidylibrary(patchwork) # Composing plots# Accessing Harvard Dataverselibrary(dataverse) # Access Harvard Dataversesessioninfo::session_info()$packages |>as_tibble() |>select(package, version = loadedversion, date, source) |>arrange(package) |> janitor::clean_names(case ="title" ) |> gt::gt() |> gt::opt_interactive(use_search =TRUE ) |> gtExtras::gt_theme_espn()
Table 1: R Packages and their versions used in the creation of this page and graphics