plotKaya | R Documentation |
Creates barplot of the change in a target variable and its decomposition into drivers over time. The target variable is shown as points, the drivers as bars. The plot can be faceted by region and/or scenario. As input, the function needs a MAgPIE object with the kaya decomposition, as provided by kayaLaspeyres().
plotKaya(
data,
scenario = NULL,
region = NULL,
unit = "%",
startYear = 2000,
addVline = NULL,
title = NULL,
reducedYlabel = FALSE,
labels = TRUE,
legend = TRUE,
lemonLegend = TRUE,
colors = NULL,
localTheme = theme_bw(),
printPlot = TRUE,
filename = NULL
)
data |
MAgPIE object with kaya decomposition as provided by kayaLaspeyres(). |
scenario |
Scenario to plot. If NULL, all scenarios are plotted. Function cannot work with multiple scenarios and regions (one needs to be specified or just one to start with). Default is NULL. |
region |
Region to plot. If NULL, all regions are plotted. Function cannot work with multiple scenarios and regions (one needs to be specified or just one to start with). Default is NULL. |
unit |
Unit of y-axis. Needs to be either percentage (if decomposition has been done in relative terms), or the unit of the target variable. Default is percentage. |
startYear |
Year to start plotting. Default is 2000. |
addVline |
Add vertical line at specified year, can be used to visualize change between historic and scenario driven timesteps. Default is NULL. |
title |
Title of the plot. If NULL, a default title is created based on the target variable. If "off", no title is shown. If a different string is provided, this string is used as title. Default is NULL. |
reducedYlabel |
Logical. If TRUE, the y-axis label is reduced to the unit of the target variable. If FALSE, the y-axis label contains the unit and a description of the variable. Default is FALSE. |
labels |
Logical. If FALSE, axis labels are removed. Default is TRUE. |
legend |
Logical. If FALSE, legend is removed. Default is TRUE. |
lemonLegend |
Logical. If TRUE, legend is repositioned to an empty facet of the plot if available. Default is TRUE. |
colors |
Vector of colors for the drivers. If NULL, the default RColorBrewer palette "Set2" is used. Default is NULL. |
localTheme |
ggplot2 theme to use for the plot. Default is theme_bw(). |
printPlot |
Logical. If TRUE, the plot is printed. Default is TRUE. |
filename |
If not NULL, the plot is saved as a png file with the provided filename. Default is NULL. |
The function returns a ggplot object.
Debbora Leip
## Not run:
data <- new.magpie(cells_and_regions = c("EUR", "SSA", "USA", "LAM", "IND", "OAS"),
years = c(2000, 2005, 2010),
names = as.vector(outer(c("Area", "Population", "Supply"),
c("SSP1", "SSP2"), paste, sep = ".")),
sets = c("Region", "Year", "Variable", "Scenario"), fill = runif(108))
kaya <- kayaLaspeyres(data)
plotKaya(kaya, scenario = "SSP1")
plotKaya(kaya, region = "EUR")
plotKaya(kaya, region = "EUR", scenario = "SSP1")
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.