Generates comparative bar charts using GTAP data, allowing multiple visualization options such as panel facets, split grouping, and customizable styles.
Usage
comparison_plot(
data,
filter_var = NULL,
x_axis_from,
split_by = NULL,
panel_var = "Experiment",
variable_col = "Variable",
unit_col = "Unit",
desc_col = "Description",
invert_pane = FALSE,
separate_figure = FALSE,
var_name_by_description = FALSE,
add_var_info = FALSE,
output_path = NULL,
export_picture = TRUE,
export_as_pdf = FALSE,
export_config = NULL,
plot_style_config = NULL
)
Arguments
- data
A data frame or a list of data frames containing GTAP results.
- filter_var
Vector or data frame. If a vector, filters the values in `x_axis_from`. If a data frame, filters `value_col` based on matching `variable_col` values.
- x_axis_from
Character. Column name for x-axis categories (e.g., "REG", "Sector").
- split_by
Character or vector. Column name(s) for data splitting (e.g., "COMM", "REG", "ACTS"). Set to NULL for no splitting, suitable for macro-level analysis.
- panel_var
Character. Column for panel facets (default: "Experiment").
- variable_col
Character. Column containing variable identifiers (default: "Variable").
- unit_col
Character. Column containing unit information (default: "Unit").
- desc_col
Character. Column containing variable descriptions (default: "Description").
- invert_pane
Logical. If TRUE, creates horizontal bars instead of vertical ones (default: FALSE).
- separate_figure
Logical. If TRUE, generates separate figures per panel value (default: FALSE).
- var_name_by_description
Logical. If TRUE, uses descriptions instead of variable codes in titles (default: FALSE).
- add_var_info
Logical. If TRUE, adds the variable code in parentheses after the description (default: FALSE).
- output_path
Character. Directory path for saving output files. If NULL, plots are only returned in R.
- export_picture
Logical. If TRUE, exports plots as image files (default: TRUE).
- export_as_pdf
Logical or "merged". If TRUE, exports separate PDFs; if "merged", creates a multi-page PDF; if FALSE, skips PDF (default: FALSE).
- export_config
List. Export settings, including:
`width`: Output file width (in inches).
`height`: Output file height (in inches).
Additional settings—see `?get_export_config`.
- plot_style_config
List. Custom plot styles—see `?get_plot_style_config`.
Examples
# \donttest{
# Input Path:
input_path <- system.file("extdata/in", package = "GTAPViz")
# GTAP Macro Variables from 2 .sl4 Files named (EXP1, EXP2)
# Note: No need to add .sl4 to the experiment name
gtap_data <- auto_gtap_data(experiment = c("EXP1", "EXP2"),
input_path = input_path, subtotal_level = FALSE,
process_sl4_vars = NULL, process_har_vars = NULL,
mapping_info = "GTAPv7", plot_data = TRUE)
#> All 2 requested experiment files are found with both SL4 and HAR data.
#> Mapping method used: GTAPv7
#> Processing GTAP Macro Data
#> Processing SL4 Data
#> Processing QXS Bilateral Trade Data
#> Processing HAR Data
#>
#> Summary of Processing:
#> GTAP Macro Data processed successfully
#> SL4 Data processed successfully
#> HAR Data processed successfully
#>
#> GTAP data processing completed successfully!
# Basic usage with data frame
p1 <- comparison_plot(
data = sl4.plot.data[["1D"]][["Region"]],
x_axis_from = "Region",
panel_var = "Experiment",
filter_var = c("qgdp", "EV"),
output_path = "/your/folder/path"
)
#> Warning: No matching data found for the specified filter_var values.
# Split by commodity with custom styling and export options
p2 <- comparison_plot(
data = sl4.plot.data[["1D"]][["Region"]],
x_axis_from = "Region",
split_by = "Variable",
panel_var = "Experiment",
filter_var = c("qgdp", "EV"),
var_name_by_description = TRUE,
output_path = "/your/folder/path",
export_as_pdf = TRUE,
export_config = list(
file_name = "commodity_impacts",
width = 12,
height = 8
),
plot_style_config = list(
color_tone = "economic",
title_size = 16,
show_grid_major_y = TRUE
)
)
#> Warning: No matching data found for the specified filter_var values.
# }