Three Decades of Gas and Diesel Prices in the U.S.
This graphic shows weekly U.S. fuel prices from 1995 to 2025, highlighting when gasoline prices exceeded diesel—and when the reverse was true.
#TidyTuesday
Line Graph
{ggbraid}
Author
Aditya Dahiya
Published
July 2, 2025
About the Data
This dataset explores weekly retail gas and diesel prices in the United States, sourced from the U.S. Energy Information Administration (EIA). Each Monday, the EIA collects prices from over 1,000 gasoline outlets and around 590 diesel stations across the country. These prices—captured as of 8:00 a.m. local time—include all taxes and represent the average self-serve cash pump price for different fuel grades and formulations. The gasoline data covers regular, midgrade, premium, and reformulated types, while diesel data reflects the cost of ultra low sulfur diesel (ULSD). The weekly time series used in this analysis was downloaded directly from this EIA Excel file. You can access the cleaned dataset prepared for this week’s #TidyTuesday challenge via GitHub. Special thanks to Jon Harmon and the Data Science Learning Community for curating and sharing this dataset for open exploration and learning.
Figure 1: Gasoline and diesel prices in the U.S. from 1995 to 2025, with shaded areas showing periods when gasoline was more expensive than diesel (in blue) or vice versa (in red). Patterns reflect economic shocks and long-term fuel trends.
How the Graphic Was Created
Loading required libraries
Code
pacman::p_load( tidyverse, # All things tidy scales, # Nice Scales for ggplot2 fontawesome, # Icons display in ggplot2 ggtext, # Markdown text support for ggplot2 showtext, # Display fonts in ggplot2 colorspace, # Lighten and Darken colours patchwork, # Composing Plots sf # Making maps)weekly_gas_prices <- readr::read_csv('https://raw.githubusercontent.com/rfordatascience/tidytuesday/main/data/2025/2025-07-01/weekly_gas_prices.csv')
Visualization Parameters
Code
# Font for titlesfont_add_google("Barlow",family ="title_font") # Font for the captionfont_add_google("Barlow Condensed",family ="caption_font") # Font for plot textfont_add_google("Barlow Semi Condensed",family ="body_font") showtext_auto()# A base Colourbg_col <-"white"seecolor::print_color(bg_col)# Colour for highlighted texttext_hil <-"grey20"seecolor::print_color(text_hil)# Colour for the texttext_col <-"grey20"seecolor::print_color(text_col)line_col <-"grey30"# Define Base Text Sizebts <-120# 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:** U.S. Energy Information Administration", " | **Code:** ", social_caption_1, " | **Graphics:** ", social_caption_2 )rm(github, github_username, xtwitter, xtwitter_username, social_caption_1, social_caption_2)# Add text to plot-------------------------------------------------plot_subtitle <-str_wrap("....................", 85)str_view(plot_subtitle)plot_title <-"...................."
# Saving a thumbnaillibrary(magick)# Saving a thumbnail for the webpageimage_read(here::here("data_vizs", "tidy_usa_gas_prices.png")) |>image_resize(geometry ="x400") |>image_write( here::here("data_vizs", "thumbnails", "tidy_usa_gas_prices.png" ) )
Session Info
Code
pacman::p_load( tidyverse, # All things tidy scales, # Nice Scales for ggplot2 fontawesome, # Icons display in ggplot2 ggtext, # Markdown text support for ggplot2 showtext, # Display fonts in ggplot2 colorspace, # Lighten and Darken colours patchwork # Composing Plots)sessioninfo::session_info()$packages |>as_tibble() |> dplyr::select(package, version = loadedversion, date, source) |> dplyr::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