Skip to contents

Generates detailed bar charts to visualize the distribution of impacts across multiple dimensions. The function supports top impact filtering, color coding, and flexible visualization settings.

Usage

detail_plot(
  data,
  filter_var = NULL,
  x_axis_from,
  split_by = NULL,
  panel_var = "Experiment",
  variable_col = "Variable",
  unit_col = "Unit",
  desc_col = "Description",
  var_name_by_description = FALSE,
  add_var_info = FALSE,
  output_path = NULL,
  export_picture = TRUE,
  export_as_pdf = FALSE,
  export_config = NULL,
  top_impact = NULL,
  separate_figure = FALSE,
  invert_pane = FALSE,
  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").

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`.

top_impact

Numeric or NULL. If specified, shows only the top N impactful values; NULL shows all values.

separate_figure

Logical. If TRUE, generates separate figures per panel value (default: FALSE).

invert_pane

Logical. If TRUE, creates horizontal bars instead of vertical ones (default: FALSE).

plot_style_config

List. Custom plot styles—see `?get_plot_style_config`.

Value

A ggplot2 object for a single plot or a list of ggplot2 objects for multiple plots.

Author

Pattawee Puangchit

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
detail_plot(sl4.plot.data[["2D"]],
            x_axis_from = "Sector",
            split_by = "Region",
            filter_var = "qo",

            top_impact = NULL,
            var_name_by_description = TRUE,
            
            invert_pane = TRUE,
            separate_figure = FALSE,
            
            export_config = list(
              width = 45,
              height = 20
            ),
            
            export_picture = TRUE,
            export_as_pdf = FALSE,   
            output_path = "/your/folder/path",
            
            plot_style_config = list(
              positive_color = "#2E8B57", 
              negative_color = "#CD5C5C",
              panel_rows = 1,
              panel_cols = NULL,
              show_axis_titles_on_all_facets = FALSE,
              y_axis_text_size = 25,
              bar_width = 0.6,
              all_font_size = 1.1
            ))
#> Warning: No matching data found for the specified filter_var values.
#> NULL
# }