STAA 566 - Dynamic Graphs

Author

Bogarth Hernandez

Summary

The last decades the electricity production has been changing in favor of the environment due to the commitment of goverments and society to have a more sustainable energy generation. An important alternative to achieve the decarbonization of the generation of electricity is the use solar energy to generate electricity.

This graph shows how the 5 biggest economies countries are changing their electricity production in favor of solar energy.

Data Source :

Hannah Ritchie, Max Roser and Pablo Rosado (2020) - “Energy”.

Published online at OurWorldInData.org. Retrieved from: ‘https://ourworldindata.org/energy

Functionalities & Formating:

  • Range slider to be able analyze specific ranges of year and see detailed information.

  • hovermode option to make easy comparitions

  • positioning the legend to save space

R Code

library(tidyverse)
── Attaching packages ─────────────────────────────────────── tidyverse 1.3.2 ──
✔ ggplot2 3.3.6      ✔ purrr   0.3.4 
✔ tibble  3.1.8      ✔ dplyr   1.0.10
✔ tidyr   1.2.1      ✔ stringr 1.4.1 
✔ readr   2.1.2      ✔ forcats 0.5.2 
── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
✖ dplyr::filter() masks stats::filter()
✖ dplyr::lag()    masks stats::lag()
library(plotly)

Attaching package: 'plotly'

The following object is masked from 'package:ggplot2':

    last_plot

The following object is masked from 'package:stats':

    filter

The following object is masked from 'package:graphics':

    layout
solar <- read_csv('share-electricity-solar.csv', show_col_types = FALSE)

solar$Solar <- round(solar$Solar,2)

#Five Biggest economies countries
solar_c <-  filter(solar, Entity %in% c("China", "United States", "Japan", "Germany", "United Kingdom") & Year >= 1990)

solar_g <- plot_ly(solar_c , x= ~Year, y= ~Solar, name = ~Entity ,type = 'scatter', mode = 'lines')

#adding range slider and hovermode option

solar_g <- solar_g %>% rangeslider() %>% layout(hovermode = "x")

#seting layout

solar_g <- solar_g %>%  layout( title = "Share of Electricity Production From Solar 1990-2021 \n Five Biggest Economies", xaxis = list(title="Year"), yaxis = list(title = "Solar Share", ticksuffix = "%"), legend = list(x = 0.05, y = 0.8))

solar_g