/
kayadata.Rmd
85 lines (79 loc) · 2.52 KB
/
kayadata.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
---
title: "Getting Started with the kayadata Package"
author: "Jonathan Gilligan"
date: "2019-12-21"
vignette: >
%\VignetteEncoding{UTF-8}
%\VignetteIndexEntry{Getting Started with the kayadata Package}
%\VignetteEngine{knitr::rmarkdown}
editor_options:
chunk_output_type: console
output:
rmarkdown::html_vignette: default
rmarkdown::pdf_vignette: default
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE)
library(dplyr)
library(kayadata)
```
# kayadata
This package loads Kaya-identity data, synthesized from several sources.
To install and load the package, first install either the `pacman` or `devtools`
package from CRAN:
```{r initialize, echo=TRUE, eval=FALSE}
install.packages("devtools")
devtools::install_github("jonathan-g/kayadata")
library(kayadata)
```
or
```{r initialize-pacman, echo=TRUE, eval=FALSE}
install.packages("pacman")
library(pacman)
p_load_gh("jonathan-g/kayadata")
```
Once you've installed it, then you just need to use the command
`library(kayadata)` to load the package.
Some of the functions the package provides are:
* `kaya_region_list()`: Get a list of available countries and regions.
* `get_kaya_data()`: Get data for a specific country.
Example:
```{r get-kaya-data, echo=TRUE}
mexico_data = get_kaya_data("Mexico")
mexico_data %>% filter(year >= 1965) %>%
select(region:ef) %>%
head()
```
* `project_top_down()`: Project future population, GDP, energy use, and
emissions.
Example:
```{r project-top-down, echo=TRUE}
mexico_2050 = project_top_down("Mexico", 2050)
mexico_2050
```
* `plot_kaya`: Plot trends in Kaya variables for a given region or country.
Example:
```{r plot-kaya, echo=TRUE}
us_kaya = get_kaya_data("United States")
plot_kaya(us_kaya, "ef", y_lab = "Carbon intensity of economy",
start_year = 2000, stop_year = 2010, log_scale = TRUE,
trend_line = TRUE, font_size = 10)
```
```{r plot-kaya-world, echo=TRUE}
world_kaya = get_kaya_data("World")
plot_kaya(world_kaya, "P", start_year = 2000, stop_year = 2010,
log_scale = FALSE, trend_line = FALSE, font_size = 10)
```
* `get_fuel_mix`: Get the fuel mix (coal, gas, oil, nuclear, and renewables)
for a region or country.
Example:
```{r get-fuel-mix, echo=TRUE}
mexico_mix = get_fuel_mix("Mexico")
mexico_mix
```
* `plot_fuel_mix`: Plot the fuel mix in a donut chart
```{r plot-fuel-mix, echo=TRUE}
plot_fuel_mix(mexico_mix, font_size = 10)
```
After you install the package, you can get more help inside RStudio by typing
`help(package="kayadata")` in the R console window.