knitr::opts_chunk$set( collapse = TRUE, comment = "#>", warning = FALSE, message = FALSE, eval = requireNamespace("GTAPViz", quietly = TRUE) )
devtools::load_all() try(devtools::load_all(".."), silent = TRUE) # go up one level from /vignettes/ input_path <- system.file("extdata/in", package = "GTAPViz") sl4.plot.data <- readRDS(file.path(input_path, "sl4.plot.data.rds")) har.plot.data <- readRDS(file.path(input_path, "har.plot.data.rds")) macro.data <- readRDS(file.path(input_path, "macro.data.rds"))
This vignette illustrates how to set up table configurations and generate outputs.
For a complete list of available tables with sample images, see the table catalog.
This is an example of how to create a structured pivot table suitable for inclusion in academic presentations.
report_table( data_list = sl4.plot.data, pivot_col = list(REG = "Variable", 'COMM*REG' = "Commodity"), group_by = list( REG = c("Experiment", "Region"), 'COMM*REG' = c("Experiment", "Region")), rename_cols = list("Experiment" = "Scenario"), total_column = FALSE, decimal = 4, subtotal_level = FALSE, repeat_label = FALSE, include_units = TRUE, var_name_by_description = TRUE, add_var_info = TRUE, add_group_line = FALSE, separate_sheet_by = "Unit", export_table = FALSE, output_path = NULL, separate_file = FALSE, workbook_name = "Comparison Table" )
đź’ˇ Tip
The same report_table function can be used to generate decomposition tables, including a total column, as shown in the example below:
report_table( data_list = har.plot.data, pivot_col = list(A = "COLUMN", E1 = "PRICES"), group_by = list( A = list("Experiment", "Region"), E1 = list("Experiment", "Commodity", "PRICES") ), rename_cols = list("Experiment" = "Scenario"), total_column = TRUE, decimal = 6, subtotal_level = FALSE, repeat_label = FALSE, include_units = TRUE, var_name_by_description = FALSE, add_var_info = FALSE, add_group_line = FALSE, separate_sheet_by = "Region", export_table = FALSE, output_path = NULL, separate_file = FALSE, workbook_name = "Decomposition Table" )
Unlike static tables generated by report_table(), pivot tables remain fully interactive in the Excel output. However, they work with a single data frame at a time (just like the plotting functions).
This function offers:
Comprehensive Filtering
Add multiple filtering dimensions to enhance flexibility and enable users to explore the data from different perspectives.
Retention of Raw Data
The raw dataset is included in the Excel file, allowing downstream users—especially in Excel—to reconstruct or customize pivot tables as needed.
User-Oriented Design
Ideal for sharing with non-R users, the output is organized for intuitive exploration and ease of use.
pivot_table_with_filter( data = sl4.plot.data[["COMM*REG"]], filter = c("Variable", "Unit"), # Allow filtering by variable type and unit rows = c("Region", "Commodity"), # Regions and sectors as row fields cols = c("Experiment"), # Experiments as column fields data_fields = "Value", # Values to be aggregated raw_sheet_name = "Raw_Data", # Sheet name for raw data pivot_sheet_name = "Sector_Pivot", # Sheet name for pivot table export_table = FALSE, output_path = NULL, workbook_name = "Sectoral_Impact_Analysis.xlsx" )
Sample data used in this vignette is obtained from the GTAPv7 model and utilizes data from the GTAP 11 database. For more details, refer to the GTAP Database Archive.
```{=html}
```
Any scripts or data that you put into this service are public.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.