Title: | Comparison of multi-model runs |
---|---|
Description: | Package contains generic functions to produce comparison plots of multi-model runs. |
Authors: | David Klein [aut, cre], Jan Philipp Dietrich [aut], Lavinia Baumstark [aut], Florian Humpenoeder [aut], Miodrag Stevanovic [aut], Stephen Wirth [aut], Pascal Führlich [aut], Oliver Richters [aut], Tonn Rüter [aut] |
Maintainer: | David Klein <[email protected]> |
License: | BSD_2_clause + file LICENSE |
Version: | 0.151.1 |
Built: | 2024-11-22 05:38:25 UTC |
Source: | https://github.com/pik-piam/mip |
Contains the routines for plotting multi model and multi scenario comparisons
Package: | mip |
Type: | Package |
Version: | 7.6 |
Date: | 2016-06-13 |
License: | LGPL-3 |
LazyLoad: | yes |
David Klein
Maintainer: Anastasis Giannousakis <[email protected]>
Useful links:
Report bugs at https://github.com/pik-piam/mip/issues
Changes the value of variables given in numerators
by dividing by
denominator
and multiplying conversionFactor
. Sets unit
of these variables to newUnit
.
calculateRatio( data, numerators, denominator, newUnit = "1", conversionFactor = 1 )
calculateRatio( data, numerators, denominator, newUnit = "1", conversionFactor = 1 )
data |
A quitte object. |
numerators |
A character vector. Entries in the variable column of data. |
denominator |
A single string. An entry in the variable column of data. |
newUnit |
A single string. |
conversionFactor |
A single numerical value. |
A quitte object with changed values and new unit. Unused levels are dropped.
The function checks whether a variable of the name optNames
is
available. If not a warning message is produced, indicating how this variable
can be set using options()
.
checkGlobalOptionsProvided(optNames, envir = rlang::caller_env())
checkGlobalOptionsProvided(optNames, envir = rlang::caller_env())
optNames |
A character vector. The names of the variables. |
envir |
The environment where to look for the variables. |
Returns NULL
invisibly.
Read data for a given symbol from a gdx file and return it as a dataframe.
dataframeFromGdx(symbolName, pathToGdx, ...)
dataframeFromGdx(symbolName, pathToGdx, ...)
symbolName |
The name of a symbol to be extracted from gdx. |
pathToGdx |
Path to a gdx file. |
... |
Additional arguments passed to gdxrrw::rgdx. |
This function is similar to gdxrrw::rgdx.param, but it also works for variables.
A data frame with data about symbolName from the given gdx file. All columns are character vectors, except the last column which holds numeric values, because that is the format that rgdx returns.
Pascal Führlich
Groups variable names by summation groups based on the |+| separators given in the variable names. If no |+| are present the function will try to derive summation groups based on | separators.
extractVariableGroups(x, keepOrigNames = FALSE, sorted = FALSE)
extractVariableGroups(x, keepOrigNames = FALSE, sorted = FALSE)
x |
a vector of variable names |
keepOrigNames |
if set, the returned list contains the original variables (to the value of which the grouped ones have to sum up) as names instead of made up group names, if they exist. |
sorted |
boolean, indicating whether the variables within each group should be returned alp |
a named list of variable groups with group name as name and vector of entities as content
Anastasis Giannousakis, David Klein, Jan Philipp Dietrich
x <- c("a|+|1|+|aa","a|+|2|abc","a|+|1|+|bb","a|+|1|+|cc","a|+|3|+|aa","a|+|3|+|bb") mip::extractVariableGroups(x)
x <- c("a|+|1|+|aa","a|+|2|abc","a|+|1|+|bb","a|+|1|+|cc","a|+|3|+|aa","a|+|3|+|bb") mip::extractVariableGroups(x)
The function extracts the legend of a ggplot object.
getLegend(plt)
getLegend(plt)
plt |
A ggplot object. |
The legend of plt
or NULL
if no legend was found.
Get ready-to-plot data from one or more gdx files.
getPlotData(symbolName, pathToGdx = ".", ...)
getPlotData(symbolName, pathToGdx = ".", ...)
symbolName |
The name of a symbol to be extracted from gdx. |
pathToGdx |
Path to one or more gdx files or a a path to a folder with fulldata gdx files. If multiple paths are provided each one represents data after a specific iteration. The order of paths should match iteration order, e.g. pathToGdx[1] should hold data for the first iteration, pathToGdx[2] for the second iteration etc. If the path to a folder is given the fulldata gdx files in it are used. |
... |
Additional arguments passed to gdxrrw::rgdx. |
A data frame with data from the given gdx file(s). If multiple gdx files are provided an additional "iteration" column is added. The iteration value will be 1 for data rows from the first gdx, 2 for the second etc. The last column will always be the actual value column called <symbolName>.
Pascal Führlich
mipIterations
, dataframeFromGdx
Harmonization of model data to historical data, using harmonization methods of aneris, ported to R. See: https://github.com/iiasa/aneris/blob/ad6301eb42155c968f20b2c7e071cbec039acc03/aneris/methods.py
harmonize( df, hist, finalYear = "2050", harmonizeYear = "2015", method = "ratio", suffix = "" )
harmonize( df, hist, finalYear = "2050", harmonizeYear = "2015", method = "ratio", suffix = "" )
df |
data frame with model data to be harmonized, must have the following columns: variable, region, scenario, model, period |
hist |
data frame with historical data to be used for harmonization, must also have the following columns: variable, region, scenario, model, period |
finalYear |
when should harmonized data match model data again? |
harmonizeYear |
when should harmonization begin? sets model data = reference data for this year |
method |
harmonization method, currently supported methods are "ratio" and "offset" |
suffix |
to be appended to harmonized variables |
Falk Benke
add identifier based on model and scenario names
identifierModelScen(x)
identifierModelScen(x)
x |
A quitte object |
A factor. If more than one model but only one scenario, use model. If more than one scenario but only one model, use scenario. Else, combine them.
Longest Common Prefix
longestCommonPrefix(x)
longestCommonPrefix(x)
x |
A character vector. |
A single string. The longest common prefix of x
.
mip_example_data
Regional sulfur emissions from CRESCENDO project
David Klein
Generic area plot function. Automatically creates facet grid from data. Optionally adds total line.
mipArea( x, stack_priority = c("variable", "region"), total = TRUE, scales = "fixed", shorten = TRUE, hist = NULL, hist_source = "first", ylab = NULL )
mipArea( x, stack_priority = c("variable", "region"), total = TRUE, scales = "fixed", shorten = TRUE, hist = NULL, hist_source = "first", ylab = NULL )
x |
Data to plot. Allowed data formats: magpie or quitte. NOTE: To ensure correct conversion to quitte objects, the dimension that contains the variables must have one of the following names: variable, scenario, or model. |
stack_priority |
Name of column you want to stack. If you provide more than one column name the function will scan the columns in the given order and use the first dimension for stacking that has more than one element. |
total |
total data to plot. Allowed inputs: magpie, quitte or boolean. If total data is provided by user in magpie or quitte format it will be added to the plot. If user sets total to TRUE total will be calculated by the function and added to the plot. If total is FALSE the plot will ignore it. |
scales |
scales can be fixed ("fixed", default), free ("free"), or free in one dimension ("free_x", "free_y")? |
shorten |
Shorten variable names (default is TRUE) by removing categories only if they are identical (for short names in the legend) |
hist |
Historical data. Allowed data formats: magpie or quitte. NOTE: To ensure correct conversion to quitte objects, the dimension that contains the variables must have one of the following names: variable, scenario, model. |
hist_source |
If there are multiple historical sources the name of the source that you want to be plotted. |
ylab |
y-axis text |
David Klein, Jan Philipp Dietrich
p <- mipArea(x = mip_example_data) # create plot with best-guess design (internally using theme_mip(size=12)) p <- mipArea(mip_example_data) # override default theme with theme_grey and move legend to top library(ggplot2) p <- p + theme_grey() + theme(legend.position = "top") # go back to theme_mip and increase font size p <- p + theme_mip(size = 18) # change facetting p <- p + facet_grid(region ~ scenario)
p <- mipArea(x = mip_example_data) # create plot with best-guess design (internally using theme_mip(size=12)) p <- mipArea(mip_example_data) # override default theme with theme_grey and move legend to top library(ggplot2) p <- p + theme_grey() + theme(legend.position = "top") # go back to theme_mip and increase font size p <- p + theme_mip(size = 18) # change facetting p <- p + facet_grid(region ~ scenario)
Function for plotting (bar-plot) MAgPIE objects and compare different scenarios or models, on the x-axis for some time steps one bar for each scenario/model is generated
mipBarYearData( x, colour = NULL, ylab = NULL, xlab = NULL, title = NULL, scenario_markers = TRUE )
mipBarYearData( x, colour = NULL, ylab = NULL, xlab = NULL, title = NULL, scenario_markers = TRUE )
x |
Data to plot. Allowed data formats: magpie or quitte |
colour |
Dimension to be colored, default: "Scenario" |
ylab |
y-axis text |
xlab |
x-axis text |
title |
title appearing at the top of the plot |
scenario_markers |
Use markers to conserve space with long scenario
names. Symbols are either picked automatically (default), or can be
passed as a named vector in the form of
|
Lavinia Baumstark, Oliver Richters
## Not run: plotCompBarYearData(EnInv, ylab = "Energy Investments|Elec (billion US$2005/yr)", colour = plotstyle(getNames(EnInv, dim = 2))) ## End(Not run)
## Not run: plotCompBarYearData(EnInv, ylab = "Energy Investments|Elec (billion US$2005/yr)", colour = plotstyle(getNames(EnInv, dim = 2))) ## End(Not run)
Creates interactive line plots using ggplot and plotly. Creates one plot for each combination of values in columns not plotted via this function's arguments. If the special value "year" is passed as xAxis, color, slider or facets a list of possible column names representing years (e.g. "ttot", "tall", "t_all") is checked, the first one in names(x) is used.
mipIterations( plotData, returnGgplots = FALSE, xAxis = "year", color = NULL, slider = "iteration", facets = "region", facetScales = "fixed" )
mipIterations( plotData, returnGgplots = FALSE, xAxis = "year", color = NULL, slider = "iteration", facets = "region", facetScales = "fixed" )
plotData |
A data frame. The actual value column must be the last. Use mip::getPlotData to get a ready-to-plot data frame from one or more gdx files. |
returnGgplots |
If FALSE (the default) show interactive plotly plots with slider support. Set to TRUE to return ggplots which can be customized, but are not interactive. To re-enable slider support and interactivity run lapply(ggplots, plotly::ggplotly) after customizing the ggplots. |
xAxis |
A string from names(x), defining which column is plotted on the x-axis of the plots. Must not be NULL. |
color |
A string from names(x), defining which column is plotted as color. If NULL color is not used. |
slider |
A string from names(x), defining which column is plotted as a slider. The slider requires plotly. If NULL no slider is used. |
facets |
A string from names(x), defining which column is used for grouping. A small plot (facet) is shown for each group. If NULL facets are not used. |
facetScales |
The 'scales' argument for facets (if used), defaults to 'fixed'. See help(facet_wrap) for more info. |
A list of plotly plots, if returnGgplots is TRUE a list of ggplots instead
Pascal Führlich
Compares data by producing line plot
mipLineHistorical( x, x_hist = NULL, color.dim = "identifier", linetype.dim = NULL, facet.dim = "region", funnel.dim = NULL, ylab = NULL, xlab = "Year", title = NULL, color.dim.name = NULL, ybreaks = NULL, ylim = 0, ylog = NULL, size = 14, scales = "fixed", leg.proj = FALSE, plot.priority = c("x", "x_hist", "x_proj"), ggobject = TRUE, paper_style = FALSE, xlim = NULL, facet.ncol = 3, legend.ncol = 1, hlines = NULL, hlines.labels = NULL, color.dim.manual = NULL, color.dim.manual.hist = NULL )
mipLineHistorical( x, x_hist = NULL, color.dim = "identifier", linetype.dim = NULL, facet.dim = "region", funnel.dim = NULL, ylab = NULL, xlab = "Year", title = NULL, color.dim.name = NULL, ybreaks = NULL, ylim = 0, ylog = NULL, size = 14, scales = "fixed", leg.proj = FALSE, plot.priority = c("x", "x_hist", "x_proj"), ggobject = TRUE, paper_style = FALSE, xlim = NULL, facet.ncol = 3, legend.ncol = 1, hlines = NULL, hlines.labels = NULL, color.dim.manual = NULL, color.dim.manual.hist = NULL )
x |
Data to plot. Allowed data formats: magpie or quitte |
x_hist |
historical data to plot. Allowed data formats: magpie or quitte, If no historic information is provided the plot will ignore it. |
color.dim |
dimension used for different colors, default="identifier"; can only be chosen freely if x_hist is NULL. |
linetype.dim |
dimension used for different line types, default=NULL |
facet.dim |
dimension used for the facets, default="region" |
funnel.dim |
dimension used for different funnels, default=NULL |
ylab |
y-axis label |
xlab |
x-axis label, default="Year" |
title |
title of the plot |
color.dim.name |
name for the color-dimension used in the legend |
ybreaks |
add breaks for the y axis |
ylim |
y limits |
ylog |
=T if the-axis should be logarithmic |
size |
text size in the plot |
scales |
Are scales shared across all facets (the default, "fixed"), or do they vary across rows ("free_x"), columns ("free_y"), or both rows and columns ("free") |
leg.proj |
to add a detailed legend for the projected data. Default is |
plot.priority |
Sets the order of ploting and overlap of the data by specifying a vector of three stirng elements. Argument |
ggobject |
returns a ggplot object. Default is |
paper_style |
removes grey color from facets if |
xlim |
x axis limits as vector with min and max year |
facet.ncol |
number of columns used for faceting, default=3. |
legend.ncol |
number of columns used in legends, default=1. |
hlines |
optional horizontal lines to be added to the plot, Allowed data formats: magpie, Default is |
hlines.labels |
optional labels for horizontal lines, Allowed data formats: named vector, where each name corresponds to exactly one variable in hlines, Default is |
color.dim.manual |
optional vector with manual colors replacing default colors of color.dim, default is |
color.dim.manual.hist |
optional vector with manual colors replacing default colors of color.dim for historical data, default is |
Lavinia Baumstark, Mishko Stevanovic, Florian Humpenoeder
## Not run: p <- mipLineHistorical(x,x_hist=hist,ylab="example",xlab="Year",title=NULL) ## End(Not run)
## Not run: p <- mipLineHistorical(x,x_hist=hist,ylab="example",xlab="Year",title=NULL) ## End(Not run)
Line plots show median (50th percentile) of user selected variable(s) obtained from different scenario runs. If available in the data, ribbon plots will also show the 33th - 67th percentile region in a darker color and the 5th – 95th percentile region in a lighter color. Note: the 5th, 33th, 67th and 95th percentiles must be provided in the data set as the percentiles are not computed
plotPercentiles(df, scenarios = NULL, variables = NULL)
plotPercentiles(df, scenarios = NULL, variables = NULL)
df |
The |
scenarios |
Character vector containing names of the desired scenarios. If |
variables |
Character vector containing names of the desired variables. If |
Tonn Rüter
## Not run: # Plot atmospheric CO2 concentrations for all scenarios available in the data p <- plotPercentiles( data, # Use variable name without "X-th Percentile"-suffix variables = c("AR6 climate diagnostics|Atmospheric Concentrations|CO2|MAGICCv7.5.3") ) # Plot all available variables for selected scenarios p <- plotPercentiles(data, scenarios = c("d_delfrag", "d_another")) ## End(Not run)
## Not run: # Plot atmospheric CO2 concentrations for all scenarios available in the data p <- plotPercentiles( data, # Use variable name without "X-th Percentile"-suffix variables = c("AR6 climate diagnostics|Atmospheric Concentrations|CO2|MAGICCv7.5.3") ) # Plot all available variables for selected scenarios p <- plotPercentiles(data, scenarios = c("d_delfrag", "d_another")) ## End(Not run)
Returns a named vector (using entity names) with style codes (e.g. colors) for given entities.
plotstyle( ..., out = "color", unknown = NULL, plot = FALSE, verbosity = getOption("plotstyle.verbosity"), regexp = FALSE, strip_units = getOption("plotstyle.strip_units", default = TRUE) )
plotstyle( ..., out = "color", unknown = NULL, plot = FALSE, verbosity = getOption("plotstyle.verbosity"), regexp = FALSE, strip_units = getOption("plotstyle.strip_units", default = TRUE) )
... |
One or more strings or a vector of strings with names of entities (regions, variable names, etc.). Units in brackets "(US$2005/GJ)" will be ignored. If left empty all available entities will be used |
out |
Switch defining which type of plot style you want to get: Currently you can choose between "color", "legend" and "all" (the latter will return a dataframe with all available plot styles) |
unknown |
Optional data frame defining plot styles for unknown entities. A default color map will be used for unknown entities if nothing is provided here |
plot |
If TRUE plots with all given entities and their colors will be
produced (to produce plots with all available entities leave the |
verbosity |
Set to 1 if you want to know for which unknown entities plotstyle brewed colors |
regexp |
If |
strip_units |
If |
Plot styles for given entities
David Klein, Jan Philipp Dietrich
entities <- c("AFR", "AAA", "AFR", "UNKNOWN_ELEMENT2") plotstyle(entities) unknown <- data.frame(row.names = c("AAA", "UNKNOWN_ELEMENT2"), color = c("#123456", "#345678"), legend = c("l_AAA", "l_UNKNOWN_ELEMENT2")) plotstyle(entities, unknown = unknown) plotstyle(entities, out = "legend") plotstyle(entities, out = "all") # search for all 'Final Energy Biomass' entities plotstyle("^Final Energy\\|.*Biomass", regexp = TRUE) # search for all three-letter entities (a.k.a. regions) plotstyle("^[A-Z]{3}$", regexp = TRUE, out = "all")
entities <- c("AFR", "AAA", "AFR", "UNKNOWN_ELEMENT2") plotstyle(entities) unknown <- data.frame(row.names = c("AAA", "UNKNOWN_ELEMENT2"), color = c("#123456", "#345678"), legend = c("l_AAA", "l_UNKNOWN_ELEMENT2")) plotstyle(entities, unknown = unknown) plotstyle(entities, out = "legend") plotstyle(entities, out = "all") # search for all 'Final Energy Biomass' entities plotstyle("^Final Energy\\|.*Biomass", regexp = TRUE) # search for all three-letter entities (a.k.a. regions) plotstyle("^[A-Z]{3}$", regexp = TRUE, out = "all")
Adds plot styles locally to plotstyle object and returns a dataframe with all plotstyles including the added data. However, it does NOT change the "./inst/extdata/plotstyle.csv".
To add new entities to "./inst/extdata/plotstyle.csv" please open the file in your editor and add or change values by hand.
By default plotstyles of already existing entities will not be changed. Only new entities will be added. Use the replace
switch to replace existing styles.
If you want to keep the legend text or the color of an already existing entity and only replace one of the two values, use the string "keep" for the value you want to keep.
plotstyle.add( entity, legend, color, marker = NULL, linestyle = NULL, replace = FALSE )
plotstyle.add( entity, legend, color, marker = NULL, linestyle = NULL, replace = FALSE )
entity |
Vector of strings with names of entities (regions, variable names, etc.) |
legend |
Vector of strings with legend names of entities. |
color |
Vector of strings containing hexadecimal color codes. |
marker |
optional Vector of strings with marker codes. |
linestyle |
optional Vector of strings containing linestyle codes . |
replace |
Logical (default FALSE) indicating whether existing data should be replaced with new data. |
David Klein, Jan Philipp Dietrich
## Not run: plotstyle.add("AFR","Africa","#000000") ## Not run: plotstyle.add("AFR","keep","#FFFFFF") ## Not run: plotstyle.add("AFR","keep","keep",marker=20,replace=TRUE)
## Not run: plotstyle.add("AFR","Africa","#000000") ## Not run: plotstyle.add("AFR","keep","#FFFFFF") ## Not run: plotstyle.add("AFR","keep","keep",marker=20,replace=TRUE)
scenTool allows to explore and visualize time series of modelling results. The app is based on shiny opens in an external web brower. For more details: https://github.com/flohump/scenTool
scenTool(file = NULL, valfile = NULL)
scenTool(file = NULL, valfile = NULL)
file |
model data in CSV file in MIF format (NULL by default; in this case the user can upload files directly in the tool) |
valfile |
validation data in CSV file in MIF format (NULL by default; in this case the user can upload files directly in the tool) |
Florian Humpenoeder
## Not run: scenTool("testdata.mif") ## End(Not run)
## Not run: scenTool("testdata.mif") ## End(Not run)
scenToolMAgPIE allows to explore and visualize time series of modelling results. The app is based on shiny opens in an external web brower. For more details: https://github.com/flohump/scenTool
scenToolMAgPIE(file = NULL, valfile = NULL)
scenToolMAgPIE(file = NULL, valfile = NULL)
file |
report data. Can be a CSV/MIF file or rds file with a quitte object (saved with saveRDS). file can also be a vector of rds files. NULL by default; in this case the user can upload files directly in the tool |
valfile |
validation data. Can be a CSV/MIF file or rds file with a quitte object (saved with saveRDS). NULL by default; in this case the user can upload files directly in the tool |
Florian Humpenoeder
## Not run: scenToolMAgPIE("testdata.mif") ## End(Not run)
## Not run: scenToolMAgPIE("testdata.mif") ## End(Not run)
Fast visualization of a magpie object or quitte object as bar plot. If available, the years 2020 and 2050 will be selected; if not available the first and last year of the available years.
scratchBar(x, complete = "default", simplify = "default", ...)
scratchBar(x, complete = "default", simplify = "default", ...)
x |
an object that can be converted to a quitte (e.g. a quitte object or a magpie objet) |
complete |
"default" or list with specifications for scratchComplete |
simplify |
"default" or list with specifications for scratchSimplify |
... |
furhter arguments handed on to mipBarYearData function |
ggplot object
Benjamin Leon Bodirsky
## Not run: x <- Intake(gdx) ## End(Not run)
## Not run: x <- Intake(gdx) ## End(Not run)
1. If ylab is specified, the function just returns everything after the ylab. 2. If identical_only = TRUE is specified, it removes identical parts in the name, independent of maxchar. 3. If maxchar is specified, the function will first try to return vector as it is, then remove elements which are identical between all elements and finally cut the end of the character vectors so that it fits the given maxchar setting. Underscores will be replaced with empty spaces for further processing
shorten_legend( x, maxchar = 20, identical_only = FALSE, ylab = NULL, sep = c(" ", "|", "_"), unit = NULL )
shorten_legend( x, maxchar = 20, identical_only = FALSE, ylab = NULL, sep = c(" ", "|", "_"), unit = NULL )
x |
A character vector or a factor vector that should be shortened |
maxchar |
Maximum number of characters allowed |
identical_only |
If set to TRUE identical parts in the name will be removed, independent of the character length (maxchar will be ignored!) |
ylab |
If specified this part will be removed, independent of maxchar and identical_only |
sep |
A vector of characters which should be interpreted as separators |
unit |
A vector of characters with units, pasted to ylab |
Jan Philipp Dietrich, Oliver Richters
a <- c("Model Scenario_BLUB", "Model Scenario_BLA", "Model Scenario_BLA_BLA_BLUB") # do nothing shorten_legend(a, 30) # remove identical parts shorten_legend(a, 15) # or ... shorten_legend(a, identical_only=TRUE) # cutoff end of string shorten_legend(a, 5) # cut off the first part as explicitly specified shorten_legend(a, ylab = "Model Scenario")
a <- c("Model Scenario_BLUB", "Model Scenario_BLA", "Model Scenario_BLA_BLA_BLUB") # do nothing shorten_legend(a, 30) # remove identical parts shorten_legend(a, 15) # or ... shorten_legend(a, identical_only=TRUE) # cutoff end of string shorten_legend(a, 5) # cut off the first part as explicitly specified shorten_legend(a, ylab = "Model Scenario")
Creates 4 sets of plots from scenario data and shows them.
showAreaAndBarPlots( data, vars, tot = NULL, fill = FALSE, orderVars = c("mean", "user", "userRev"), mainReg = getOption("mip.mainReg"), yearsBarPlot = getOption("mip.yearsBarPlot"), scales = "free_y" )
showAreaAndBarPlots( data, vars, tot = NULL, fill = FALSE, orderVars = c("mean", "user", "userRev"), mainReg = getOption("mip.mainReg"), yearsBarPlot = getOption("mip.yearsBarPlot"), scales = "free_y" )
data |
A quitte object or an object that can be transformed into a quitte object. |
vars |
A character vector. The variables to be plotted. |
tot |
A single string. A total value to be shown in the area plots. |
fill |
Logical. Should the vars be normalized so that their values add to 1? (Plot shares instead of absolute values.) |
orderVars |
In what order should the variables be shown?
|
mainReg |
A single string. The plots for this region are shown enlarged.
Use |
yearsBarPlot |
A numeric vector. The years shown in the bar plots. Use
|
scales |
adjusts how axes are harmonized. Default is free_y |
Creates 2 sets of area plots (main region + others) and 2 sets of bar plots
(main region + others) of the variables specified in vars over time. For area
plots, faceting is done by region and scenario; for bar plots over region. If
a variables is given in tot, this is shown as a black line. If not the sum of
the values of vars is drawn. If fill=TRUE
, the values of vars are
divided by the values of tot to show share of total. The plots arranged and
shown.
NULL
is returned invisible.
page 1 - fill=FALSE
:
page 2 - fill=FALSE
:
page 1 - fill=TRUE
:
page 2 - fill=TRUE
:
## Not run: options(mip.yearsBarPlot = c(2010, 2030, 2050, 2100)) options(mip.mainReg = "World") data <- as.quitte(data) vars <- c( "FE|CDR", "FE|Transport", "FE|Buildings", "FE|Industry") showAreaAndBarPlots(data, vars) showAreaAndBarPlots(data, vars, orderVars = "user") ## End(Not run)
## Not run: options(mip.yearsBarPlot = c(2010, 2030, 2050, 2100)) options(mip.mainReg = "World") data <- as.quitte(data) vars <- c( "FE|CDR", "FE|Transport", "FE|Buildings", "FE|Industry") showAreaAndBarPlots(data, vars) showAreaAndBarPlots(data, vars, orderVars = "user") ## End(Not run)
Automatically infers disaggregation of a variable using the '+'-notation and
calls showAreaAndBarPlots
.
showAreaAndBarPlotsPlus( data, tot, plusNum = 1, fill = FALSE, mainReg = getOption("mip.mainReg"), yearsBarPlot = getOption("mip.yearsBarPlot"), scales = "free_y" )
showAreaAndBarPlotsPlus( data, tot, plusNum = 1, fill = FALSE, mainReg = getOption("mip.mainReg"), yearsBarPlot = getOption("mip.yearsBarPlot"), scales = "free_y" )
data |
A quitte object or an object that can be transformed into a quitte object. |
tot |
A single string. A total value to be shown in the area plots. |
plusNum |
A single number. Number of "+"symbols for disaggregation. |
fill |
Logical. Should the vars be normalized so that their values add to 1? (Plot shares instead of absolute values.) |
mainReg |
A single string. The plots for this region are shown enlarged.
Use |
yearsBarPlot |
A numeric vector. The years shown in the bar plots. Use
|
scales |
adjusts how axes are harmonized. Default is free_y |
The function requires data
to have a character column named
varplus
containing variable names that use the '+'-notaion. The
function searches for values in varplus
that start with tot
followed by "|"
, plusNum
-times "+"
, and "|"
.
These variables are then used in a call to showAreaAndBarPlots
.
NULL
is returned invisible.
## Not run: options(mip.yearsBarPlot = c(2010, 2030, 2050, 2100)) options(mip.mainReg = "World") data <- as.quitte(data) showAreaAndBarPlotsPlus(data, "SE|Liquids") ## End(Not run)
## Not run: options(mip.yearsBarPlot = c(2010, 2030, 2050, 2100)) options(mip.mainReg = "World") data <- as.quitte(data) showAreaAndBarPlotsPlus(data, "SE|Liquids") ## End(Not run)
Creates 2 sets of line plots from scenario data and shows them.
showLinePlots( data, vars = NULL, histVars = NULL, scales = "free_y", color.dim.name = NULL, mainReg = getOption("mip.mainReg"), color.dim.manual = NULL, histModelsExclude = NULL, vlines = NULL )
showLinePlots( data, vars = NULL, histVars = NULL, scales = "free_y", color.dim.name = NULL, mainReg = getOption("mip.mainReg"), color.dim.manual = NULL, histModelsExclude = NULL, vlines = NULL )
data |
A quitte object or an object that can be transformed into a quitte object. |
vars |
A character vector. Usually just a single string. The variables
to be plotted. If |
histVars |
A character vector. Usually just a single string. The historical variables
to be plotted. If |
scales |
A single string. choose either |
color.dim.name |
name for the color-dimension used in the legend |
mainReg |
A single string. The plots for this region are shown enlarged.
Use |
color.dim.manual |
optional vector with manual colors replacing default
colors of color.dim, default is |
histModelsExclude |
A character vector with historical models to exclude.
Set to |
vlines |
period used for vertical line |
Two sets of line plots are shown (main region + others), depicting the values
in vars
over time. Faceting is done by region
. The plots
arranged and shown.
NULL
is returned invisible.
## Not run: options(mip.mainReg = "World") data <- as.quitte(data) showLinePlots(data, "Policy Cost|GDP Loss") ## End(Not run)
## Not run: options(mip.mainReg = "World") data <- as.quitte(data) showLinePlots(data, "Policy Cost|GDP Loss") ## End(Not run)
Shows line plots of a variable with additional target data.
showLinePlotsWithTarget(data, vars, scales = "free_y", color.dim.name = NULL)
showLinePlotsWithTarget(data, vars, scales = "free_y", color.dim.name = NULL)
data |
A quitte object or an object that can be transformed into a quitte object. |
vars |
A character vector. Usually just a single string. The variables to be plotted. |
scales |
A single string. choose either |
color.dim.name |
name for the color-dimension used in the legend |
Creates a line plot showing single line plot of vars over time. Additionally
target values given in variables of the form <vars>|target|<sth>
are
shown. The plot is shown.
NULL
is returned invisible.
## Not run: data <- as.quitte(data) showLinePlotsWithTarget(data, "Emi|GHG") ## End(Not run)
## Not run: data <- as.quitte(data) showLinePlotsWithTarget(data, "Emi|GHG") ## End(Not run)
Show 2 sets of plots with different regions in the same plot (value over time).
showMultiLinePlots( data, vars, scales = "free_y", nrowNum = 1, mainReg = getOption("mip.mainReg") )
showMultiLinePlots( data, vars, scales = "free_y", nrowNum = 1, mainReg = getOption("mip.mainReg") )
data |
A quitte object or an object that can be transformed into a quitte object. |
vars |
A character vector. The variables to be plotted. |
scales |
A single string. choose either |
nrowNum |
An integer value. Number of rows of the panel figures |
mainReg |
A single string. The plots for this region are shown enlarged.
Use |
Creates two plots (main region + others) with the values of vars
over
time. Different regions are shown in the same plot. Faceting is done by
variable
. The plots arranged and shown.
NULL
is returned invisible.
page 1: page 2:
## Not run: options(mip.mainReg = "World") data <- as.quitte(data) vars <- c( "FE|Transport pCap", "FE|Buildings pCap", "FE|Industry pCap") showMultiLinePlots(data, vars) ## End(Not run)
## Not run: options(mip.mainReg = "World") data <- as.quitte(data) vars <- c( "FE|Transport pCap", "FE|Buildings pCap", "FE|Industry pCap") showMultiLinePlots(data, vars) ## End(Not run)
Show plots with different regions in the same plot; x-axis variable chosen by user.
showMultiLinePlotsByVariable( data, vars, xVar, scales = "free_y", showHistorical = FALSE, showGlobal = FALSE, nrowNum = 1, mainReg = getOption("mip.mainReg"), histRefModel = getOption("mip.histRefModel"), yearsByVariable = getOption("mip.yearsBarPlot"), logscale = "" )
showMultiLinePlotsByVariable( data, vars, xVar, scales = "free_y", showHistorical = FALSE, showGlobal = FALSE, nrowNum = 1, mainReg = getOption("mip.mainReg"), histRefModel = getOption("mip.histRefModel"), yearsByVariable = getOption("mip.yearsBarPlot"), logscale = "" )
data |
A quitte object or an object that can be transformed into a quitte object. |
vars |
A character vector. The variables to be plotted. |
xVar |
A single string. The variable for the x-axis. |
scales |
A single string. choose either |
showHistorical |
A single logical value. Should historical data be
shown? It is not recommended to set this to |
showGlobal |
A single logical value. Should global data be shown? Default is false to save space in pdf |
nrowNum |
An integer value. Number of rows of the panel figures |
mainReg |
A single string. The plots for this region are shown enlarged.
Use |
histRefModel |
A named character vector identifying the unique model to
be chosen for historical data. Use |
yearsByVariable |
A numeric vector. The years to be marked in the plots.
As default it uses the value globally set by |
logscale |
A string such as "x", "y" or "xy". Each axis mentioned in this string is displayed in logarithmic scale (base 10) instead of linear. |
Same as showMultiLinePlots
but with the variable specified by
xVar
on x-axis. For every y-axis-value, we need a unique x-axis-value.
For historical data, there may be several sources / models of the same
variable. For the x-axis-variable a unique historical source / model is
chosen via histRefModel
.
NULL
is returned invisible.
page 1: page 2:
## Not run: options(mip.mainReg = "World") options(mip.yearsBarPlot = c(2010, 2030, 2050, 2100)) options(mip.histRefModel = c("GDP|PPP pCap" = "James_IMF")) data <- as.quitte(data) vars <- c( "FE|Transport pCap", "FE|Buildings pCap", "FE|Industry pCap") showMultiLinePlotsByVariable(data, vars, "GDP|PPP pCap") ## End(Not run)
## Not run: options(mip.mainReg = "World") options(mip.yearsBarPlot = c(2010, 2030, 2050, 2100)) options(mip.histRefModel = c("GDP|PPP pCap" = "James_IMF")) data <- as.quitte(data) vars <- c( "FE|Transport pCap", "FE|Buildings pCap", "FE|Industry pCap") showMultiLinePlotsByVariable(data, vars, "GDP|PPP pCap") ## End(Not run)
Shows line plots of a variable with different regions in the same plot and faceting by scenario.
showRegiLinePlots( data, vars, scales = "free_y", excludeMainRegion = TRUE, mainReg = getOption("mip.mainReg") )
showRegiLinePlots( data, vars, scales = "free_y", excludeMainRegion = TRUE, mainReg = getOption("mip.mainReg") )
data |
A quitte object or an object that can be transformed into a quitte object. |
vars |
A character vector. The variables to be plotted. |
scales |
A single string. choose either |
excludeMainRegion |
A single logical value. Should the main region be excluded (or shown in the same plot)? |
mainReg |
A single string. Use options(mip.mainReg=<value>) to set globally. |
Creates one set of plots with the values of vars
over time. Does not
show historical data. Different regions are shown in the same plot. Faceting
is done by scenario
. The plots arranged and shown.
NULL
is returned invisible.
## Not run: options(mip.mainReg = "World") data <- as.quitte(data) showRegiLinePlots(data, "Price|Carbon") ## End(Not run)
## Not run: options(mip.mainReg = "World") data <- as.quitte(data) showRegiLinePlots(data, "Price|Carbon") ## End(Not run)
Show multiple plots side by side in one row, using the same plotly slider (frame aesthetic) if that is used.
sideBySidePlots(ggplots, margin = 0.05)
sideBySidePlots(ggplots, margin = 0.05)
ggplots |
A list of ggplots. These plots are converted via plotly::ggplotly, however, passing plotly plots is not allowed, because they cannot be customized anymore. When using mipIterations set the argument returnGgplots to TRUE ot get ggplots instead of plotly plots. |
margin |
Margin between plots, passed on to plotly::subplot. |
A tagList containing an h3 for the titles and the ggplots in a plotly::subplot.
Pascal Führlich
MIP theme settings
theme_mip(size = 12)
theme_mip(size = 12)
size |
Font size |
Jan Philipp Dietrich
## Not run: p <- mipArea(x) + theme_mip(10) ## End(Not run)
## Not run: p <- mipArea(x) + theme_mip(10) ## End(Not run)
Create a validation PDF file
validationpdf( x, hist, file = "validation.pdf", style = "comparison", only_historical = FALSE, digits = 3, filter = NULL, prefix = NULL, hideEmptySection = FALSE, show_stats = TRUE, debug = getOption("debug"), pdfStyle = NULL )
validationpdf( x, hist, file = "validation.pdf", style = "comparison", only_historical = FALSE, digits = 3, filter = NULL, prefix = NULL, hideEmptySection = FALSE, show_stats = TRUE, debug = getOption("debug"), pdfStyle = NULL )
x |
Data to be validated. All formats allowed which can be converted to quitte (including characters containing the path to a mif or rds file) |
hist |
Validation data.All formats allowed which can be converted to quitte (including characters containing the path to a mif or rds file) |
file |
file name of the output PDF or a Sweave object. If a sweave object is provided the function will return the updated object, otherwise it will write its content to the file |
style |
data style for the returned data. Currently available: "trafficlight", "detailed", "comparison" |
only_historical |
boolean deciding whether only historical data should be used for validation or also projections from other sources |
digits |
integer indicating the number of digits to be shown. |
filter |
Additional filter to be applied on the data to only plot a subset of the provided data |
prefix |
Prefix which will be put in front of each part title (useful if validation is integrated into a bigger document) |
hideEmptySection |
removes sections in output file which would be empty for the reason that variables in input 'x' has have correspondance in the hist file |
show_stats |
boolean specifying whether additional statistic section should show up or not |
debug |
Switch to activate or deactivate debug mode. |
pdfStyle |
list of style-options for the pdf |
Jan Philipp Dietrich
Generates a warning if some of the variable names in vars
vars are not
entries of the variables-column of data
.
warnMissingVars(data, vars)
warnMissingVars(data, vars)
data |
A quitte object. |
vars |
A character vector. |
Returns NULL
invisibly.