Giter Site home page Giter Site logo

irenabpdata's Introduction

irenabpdata

This R-package downloads the BP Statistical Review of World Energy and the IRENA renewable energy and capacity database and provides an interface to it. It also integrates with wbstats, a package used to read data from the World Bank Indicators Database.

Dependencies

Dependencies are automatically installed: dplyr, readxl, stringr, feather, tidyr, magrittr, ggplot2, wbstats

Installation

Works with package devtools (install before usage!).


devtools::install_github("inwe-boku/irenabpdata")

How it works

The package downloads the respective databases from BP and Irena and saves them to feather files locally. This download has to be done only once. Afterwards, the package can load the converted files and provides functions to plot values from the database and to join them with data from the world bank.

Example


library(irenabpdata)
library(tidyverse)
library(ggplot2)

Download data:


# This has to be executed only once - will save the bp file in your local directory
guess_url(2021) %>% download_clean_save_bp()

Load BP database as tibble:


bp <- load_latest_db_bp()

Plot primary energy consumption and electricity generation for some regions:


plot_bp_primary_energy_mix(bp, c("World"))

plot_bp_electricity_generation(bp, c("World"))

plot_bp_electricity_generation(bp, c("Brazil",
                                    "Germany",
                                    "United Kingdom"))

Plot pipeline gas imports of Russia:

bp %>%
filter(Country=="Russian Federation") %>%
filter(str_detect(Variable,"Pipeline" )) %>%
ggplot(aes(x=Year,y=Value))+
geom_line(aes(col=Variable))+
scale_color_manual(values=COLORS10)+
theme_bw()+
ylab("Imports/Exports (bcm)")

Join BP Data with world bank data on GDP and plot GDP vs. Carbon Dioxide Emissions:



gdp_bp <- join_wb_db("NY.GDP.MKTP.PP.KD", bp, "BP") %>% 
  na.omit()

gdp_bp %>% 
  filter(Variable_db=="Carbon Dioxide Emissions") %>% 
  filter(Country %in% c("North America",
                        "China",
                        "European Union",
                        "South Africa",
                        "Brazil",
                        "World")) %>% 
  ggplot(aes(x=Value_wb/10^12,y=Value_db/1000)) + 
  geom_point() +
  xlab("GDP (Constant 2017 international bn$)") +
  ylab("Carbon Dioxide Emissions \n(Gt CO2)") +
  facet_wrap(.~Country,scales="free") +
  theme_bw()

Acknowledgements

We gratefully acknowledge support from the European Research Council (“reFUEL” ERC2017-STG 758149).

irenabpdata's People

Contributors

joph avatar

Stargazers

Adrian Odenweller avatar  avatar  avatar

Watchers

 avatar James Cloos avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.