Background

We are constantly looking at our data. Graphs and charts let us explore and learn about the structure of the information we collect. Good data visualizations also make it easier to communicate our ideas and findings to other people. Beyond that, producing effective plots from our own data is the best way to develop a good eye for reading and understanding graphs—good and bad—made by others, whether presented in research articles, business slide decks, public policy advocacy, or media reports.

ggplot2 is R’s most popular graphic library. Unlike most other graphics packages, ggplot2 has an underlying grammar, based on the Grammar of Graphics1 (Leland Wilkinson, 2005) that allows the user to compose graphs by combining independent components. This makes ggplot2 extremely powerful. In this short article we will present the application of ggplot2 and other R packages to visualize the electricity generated by some technologies in the Spanish power market within the period 2018-2022.

The datasets with the daily output by year and technology have been downloaded from the Spanish TSO website: https://www.ree.es/es/datos/generacion/estructura-generacion

R libraries used:

  • ggplot2: A system for ‘declaratively’ creating graphics, based on “The Grammar of Graphics”
  • readxl: Import excel files into R
  • dplyr: A Grammar of Data Manipulation
  • dygraphs: Interface to ‘Dygraphs’ Interactive Time Series Charting Library
  • ggridges: Ridgeline Plots in ggplot2
  • patchwork: The Composer of Plots
  • RColorBrewer: Provides color schemes for maps and other graphics
  • viridis: Colorblind-Friendly Color Maps for R
  • hrbrthemes: Additional Themes, Theme Components and Utilities for ggplot2
  • TSstudio: Functions for Time Series Analysis and Forecasting

Time series plots

The datasets are simply a collection of time series with daily productions (GWh) by technology for the period 2018-2022. Typically, we want to plot a time series to visualize how the values of the time series are changing over time. The attached figures show the daily electricity production of some selected technologies: nuclear, CCGT, wind, solar PV.

Ridgeline plots

Another way to represent and visualize the electricity production is with ridgeline plots, which are partially overlapping line plots that create the impression of a mountain range. They can be quite useful for visualizing changes in distributions over time or space (in this case, the distribution of daily GWh over 5 years).

Heat maps

A heat map is a graphical representation of data where the individual values contained in a matrix are represented as colors.

We present below the heat maps showing the total production by year and month for some selected technologies.