This manual provides an explanation of the file
2.PlotGens.R
1.ProjectSetup
with plot_data <-
TRUE
before running this script.
2.PlotGens.R
.
This manual provides an explanation of the file
2.PlotGens.R
If you are unsure, please refer to: Plot Catalogs
You may define a custom output folder to create separate directories for each plot.
# Define new output location (or leave it as deafult)
output.folder <- output.folder
Define the dataframe to be plotted using either
sl4.plot.data
or har.plot.data
,
obtained by running 1.ProjectSetup.R
with
plot_data = TRUE
.
Depending on your data extraction method, you must assign the
dataframe
to be plotted from the corresponding data list.
All plot functions require a data frame as an input, so you must unlist the data structure before using it.
This an example of how to extract the dataframe from the data list:
comparison_plot_data <- sl4.plot.data[["REG"]]
detail_plot_data <- sl4.plot.data[["COMM*REG"]]
stack_plot_data <- har.plot.data[["A"]]
If you used the data extraction method
group_data_by_dims
, you may need to define the plot data as
follows:
plot_data <- sl4.plot.data[["Sector"]][["REG"]]
Do not forget to change export parameters to TRUE!
export_picture_c = TRUE
export_as_pdf_c = "merged" or TRUE
(merged will
combine all plots into one PDF file)
Time to copy and paste code to your R script!
This function is suitable for one-dimensional data such as qgdp
, u
, EV
, or qpriv
, allowing comparison of effects across regions (e.g., REG
).
# For help function use: ?comparison_plot
comparison.data <- sl4.plot.data[["REG"]] # Replace with your actual dataframe name
default_compare.plot <- comparison_plot( # ! Do not change this line
data = comparison.data,
x_axis_from = "Region", # Column used for the x-axis
filter_var = NULL, # Filter data based on specific values in the defined column(s)
split_by = "Variable", # Column(s) used to split data into separate plots
panel_var = "Experiment", # Column used for paneling (faceting)
invert_axis = FALSE, # Whether to invert the panel (facet) order
separate_figure = FALSE, # Whether to generate a separate figure for each panel
var_name_by_description = FALSE, # Use description as variable name
add_var_info = FALSE, # Add variable code in parentheses
export_picture = TRUE, # Export as image
export_as_pdf = "merged", # Export the plots as PDF. Use "merged" to combine all plots into one PDF
output_path = output.folder,
# Output Configurations
## Try adjusting widgth and height if output is too dense, too small, or not displayed properly
export_config = create_export_config(
width = 18,
height = 10
),
# Some Plot Style Configurations
plot_style_config = create_plot_style(
show_title = TRUE, # FALSE to hide plot title
title_format = create_title_format(
type = "dynamic", # dynamic allows use of {Description}
text = "Impacts on {Description}",
sep = ""
),
all_font_size = 1,
panel_rows = 1,
panel_cols = NULL,
color_tone = "gtap"
)
)
This setup is designed to report multiple variables within a single experiment. For example, you can plot Exports, Imports, and Real GDP as panels, instead of using experiments as the default facet. This is useful when you want to display a group of meaningful variables from one simulation.
# For help function use: ?comparison_plot
comparison.data <- sl4.plot.data[["REG"]] # Replace with your actual dataframe name
comparison_plot_var <- comparison_plot( # ! Do not change this line
data = comparison.data,
x_axis_from = "Region", # Column used for the x-axis
filter_var = list(Experiment = c("IncreaseTar10")), # Filter data based on specific values in the defined column(s)
split_by = "Unit", # No need to split, only 1 variable
panel_var = "Variable", # Column used for paneling (faceting)
invert_axis = FALSE, # Whether to invert the panel (facet) order
separate_figure = FALSE, # Whether to generate a separate figure for each panel
var_name_by_description = TRUE, # Use description as variable name
add_var_info = FALSE, # Add variable code in parentheses
export_picture = TRUE, # Export as image
export_as_pdf = "merged", # Export the plots as PDF. Use "merged" to combine all plots into one PDF
output_path = output.folder,
# Output Configurations
export_config = create_export_config(
width = 18,
height = 10
),
# Some Plot Style Configurations
plot_style_config = create_plot_style(
show_title = TRUE,
title_format = create_title_format(
type = "full",
text = "IncreaseTar10 - Economic Impacts",
sep = ""
),
all_font_size = 1,
panel_rows = 1,
panel_cols = NULL,
color_tone = "gtap"
)
)
This function is suitable for global impacts (i.e., no dimensions); it uses data from the Macros
header in the sl4
solution file.
# For help function use: ?comparison_plot
comparison.data <- GTAPMacro # Replace with your actual dataframe name
default_compare.plot <- comparison_plot( # ! Do not change this line
data = comparison.data,
x_axis_from = "Variable", # Column used for the x-axis
filter_var = NULL, # Filter data based on specific values in the defined column(s)
split_by = "Unit", # Column(s) used to split data into separate plots
panel_var = "Experiment", # Column used for paneling (faceting)
invert_axis = TRUE, # Whether to invert the panel (facet) order
separate_figure = FALSE, # Whether to generate a separate figure for each panel
var_name_by_description = FALSE, # Use description as variable name
add_var_info = FALSE, # Add variable code in parentheses
export_picture = TRUE, # Export as image
export_as_pdf = "merged", # Export the plots as PDF. Use "merged" to combine all plots into one PDF
output_path = output.folder,
# Output Configurations
## Try adjusting widgth and height if output is too dense, too small, or not displayed properly
export_config = create_export_config(
width = 18,
height = 15
),
plot_style_config = create_plot_style(
show_title = TRUE, # FALSE to hide plot title
title_format = create_title_format(
type = "full", # Full title with static text
text = "Global Economic Impacts",
sep = ""
),
show_axis_titles_on_all_facets = FALSE, # To show label only at first panel
all_font_size = 1,
panel_rows = 1,
panel_cols = NULL,
color_tone = "grey_mono" # Add "_mono" to use a single color for all bars
)
)
This R script is designed for full customization—everything must be defined from scratch. Please refer to the Plot Style Configs section before using it.
# For help function use: ?comparison_plot
comparison.data <- your_dataframe # Replace with your actual dataframe name
adv.compare.plot <- comparison_plot(
data = comparison.data,
x_axis_from = "Region",
filter_var = NULL,
split_by = NULL,
panel_var = "Experiment",
variable_col = "Variable",
unit_col = "Unit",
desc_col = "Description",
invert_axis = FALSE,
separate_figure = FALSE,
var_name_by_description = FALSE,
add_var_info = FALSE,
export_picture = FALSE,
export_as_pdf = FALSE,
output_path = "/your/path",
# Output Configurations
export_config = create_export_config(
width = NULL,
height = NULL,
dpi = 300,
bg = "white",
limitsize = FALSE
)
# All Plot Configurations
plot_style_config = create_plot_style(
# Title settings
show_title = TRUE,
title_face = "bold",
title_size = 20,
title_hjust = 0.5,
add_unit_to_title = TRUE,
title_margin = c(10, 0, 10, 0), #c(top, right, bottom, left)
title_format = create_title_format(
type = "standard", #option: standard (default), prefix, suffix, full, dynamic
text = "",
sep = ""
),
# X-Axis settings
show_x_axis_title = TRUE,
x_axis_title_face = "bold",
x_axis_title_size = 16,
x_axis_title_margin = c(25, 25, 0, 0), #c(top, right, bottom, left)
show_x_axis_labels = TRUE,
x_axis_text_face = "plain",
x_axis_text_size = 14,
x_axis_text_angle = 0,
x_axis_text_hjust = 0,
x_axis_description = "",
# Y-Axis settings
show_y_axis_title = TRUE,
y_axis_title_face = "bold",
y_axis_title_size = 16,
y_axis_title_margin = c(25, 25, 0, 0), #c(top, right, bottom, left)
show_y_axis_labels = TRUE,
y_axis_text_face = "plain",
y_axis_text_size = 14,
y_axis_text_angle = 0,
y_axis_text_hjust = 0,
y_axis_description = "",
show_axis_titles_on_all_facets = TRUE,
# Value Labels
show_value_labels = TRUE,
value_label_face = "plain",
value_label_size = 5,
value_label_position = "above",
value_label_decimal_places = 2,
# Legend
show_legend = FALSE,
show_legend_title = FALSE,
legend_position = "bottom",
legend_title_face = "bold",
legend_text_face = "plain",
legend_text_size = 14,
# Panel Strip
strip_face = "bold",
strip_text_size = 16,
strip_background = "lightgrey",
strip_text_margin = c(10, 0, 10, 0), #c(top, right, bottom, left)
# Panel Layout
panel_spacing = 2,
panel_rows = NULL,
panel_cols = NULL,
theme = NULL,
# Colors and Grid
color_tone = NULL,
color_palette_type = "qualitative", #option: qualitative, sequential, diverging
positive_color = "#2E8B57",
negative_color = "#CD5C5C",
background_color = "white",
grid_color = "grey90",
show_grid_major_x = FALSE,
show_grid_major_y = FALSE,
show_grid_minor_x = FALSE,
show_grid_minor_y = FALSE,
# Zero Line
show_zero_line = TRUE,
zero_line_type = "dashed",
zero_line_color = "black",
zero_line_size = 0.5,
zero_line_position = 0,
# Bar Chart
bar_width = 0.9,
bar_spacing = 0.9,
# Scale Settings
scale_limit = NULL,
scale_increment = NULL,
# Scale Expansion
expansion_y_mult = c(0.05, 0.1),
expansion_x_mult = c(0.05, 0.05),
# Font Size Control
all_font_size = 1,
# Data Sorting
sort_data_by_value = FALSE,
# Plot Margin
plot.margin = c(10, 25, 10, 10) #c(top, right, bottom, left)
)
)
This function is suitable for any dimensional data, with a focus on detailed overviews rather than comparisons across a few observations—such as plotting qgdp
for all countries.
Note: "REG"
has been renamed to "Region"
, and "COMM"
to "Commodity"
.
# For help function use: ?detail_plot
detail.data <- sl4.plot.data[["COMM*REG"]] # Replace with your actual dataframe
default_detail <- detail_plot(
data = detail.data,
x_axis_from = "Commodity", # Column used for the x-axis
filter_var = NULL, # Filter data based on specific values in the defined column(s)
split_by = c("Region", "Variable"), # Column(s) used to split data into separate plots (e.g., one plot per variable)
panel_var = "Experiment", # Column used for paneling (faceting)
top_impact = NULL, # Optionally limit to top-N most impactful entries per panel (e.g., top_impact = 10)
invert_axis = TRUE, # Whether to invert the panel (facet) order
separate_figure = FALSE, # Whether to generate a separate figure for each panel
var_name_by_description = TRUE, # Use the description as the variable name (e.g., qgdp becomes Real GDP)
add_var_info = FALSE, # Add variable code in parentheses (e.g., Real GDP (qgdp))
export_picture = FALSE, # Export the plots as image files
export_as_pdf = FALSE, # Export the plots as PDF. Use "merged" to combine all plots into one PDF
output_path = output.folder,
# Output Configurations
## Try adjusting widgth and height if output is too dense, too small, or not displayed properly
export_config = create_export_config(
width = 23, # Width of the output plot in inches
height = 9 # Height of the output plot in inches
),
plot_style_config = create_plot_style(
show_title = TRUE, # FALSE to hide plot title
title_format = create_title_format(
type = "dynamic", # option: standard (default), prefix, suffix, full, dynamic
text = "{Region}: Change in {Description}",
sep = " - "
),
positive_color = "#2E8B57", # Color for positive values
negative_color = "#CD5C5C", # Color for negative values
all_font_size = 1.1, # Scale for all font sizes in the plot
panel_rows = 1, # Number of rows for the panel layout, NULL for automatic calculation
panel_cols = NULL, # Number of columns for the panel layout, NULL for automatic calculation
show_axis_titles_on_all_facets = FALSE # To show label only at first panel
)
)
This R script is designed for one-dimensional data plot like qgdp
, EV
, etc. across all regions
# For help function use: ?detail_plot
detail.data <- sl4.plot.data[["REG"]] # Dataframe with one-dimensional data
oned_detail <- detail_plot(
data = detail.data,
x_axis_from = "Region", # Column used for the x-axis
filter_var = NULL, # Filter data based on specific values in the defined column(s)
split_by = "Variable", # Column(s) used to split data into separate plots
panel_var = "Experiment", # Column used for paneling (faceting)
top_impact = NULL, # Optionally limit to top-N most impactful entries per panel
invert_axis = TRUE, # Whether to invert the panel (facet) order
separate_figure = FALSE, # Whether to generate a separate figure for each panel
var_name_by_description = TRUE, # Use the description as the variable name (e.g., qgdp becomes Real GDP)
add_var_info = FALSE, # Add variable code in parentheses (e.g., Real GDP (qgdp))
export_picture = TRUE, # Export the plots as image files
export_as_pdf = "merged", # Export the plots as PDF. Use "merged" to combine all plots into one PDF
output_path = output.folder,
# Output Configurations
## Try adjusting widgth and height if output is too dense, too small, or not displayed properly
export_config = create_export_config(
width = 20, # Width of the output plot in inches
height = 12 # Height of the output plot in inches
),
plot_style_config = create_plot_style(
show_title = TRUE, # FALSE to hide plot title
title_format = create_title_format(
type = "prefix", # option: standard (default), prefix, suffix, full, dynamic
text = "Change in",
sep = " - "
),
positive_color = "#2E8B57", # Color for positive values
negative_color = "#CD5C5C", # Color for negative values
all_font_size = 1.1, # Scale for all font sizes in the plot
panel_rows = 1, # Number of rows for the panel layout, NULL for automatic calculation
panel_cols = NULL, # Number of columns for the panel layout, NULL for automatic calculation
show_axis_titles_on_all_facets = FALSE # To show label only at first panel
)
)
This R script is designed for two-dimensional data plot like qo
, qxw
, qmw
, etc., impacts across all regions ("REG"
).
# For help function use: ?detail_plot
detail.data <- sl4.plot.data[["COMM*REG"]] # Dataframe with two-dimensional data
twod_detail <- detail_plot(
data = detail.data,
x_axis_from = "Commodity", # Column used for the x-axis
filter_var = NULL, # Filter data based on specific values in the defined column(s)
split_by = c("Region","Variable"), # Column(s) used to split data into separate plots
panel_var = "Experiment", # Column used for paneling (faceting)
top_impact = NULL, # Optionally limit to top-N most impactful entries per panel
invert_axis = TRUE, # Whether to invert the panel (facet) order
separate_figure = FALSE, # Whether to generate a separate figure for each panel
var_name_by_description = TRUE, # Use the description as the variable name
add_var_info = FALSE, # Add variable code in parentheses
export_picture = TRUE, # Export the plots as image files
export_as_pdf = "merged", # Export the plots as PDF. Use "merged" to combine all plots into one PDF
output_path = output.folder,
# Output Configurations
## Try adjusting widgth and height if output is too dense, too small, or not displayed properly
export_config = create_export_config(
width = 23, # Width of the output plot in inches
height = 9 # Height of the output plot in inches
),
plot_style_config = create_plot_style(
show_title = TRUE, # FALSE to hide plot title
title_format = create_title_format(
type = "dynamic", # option: standard (default), prefix, suffix, full, dynamic
text = "{Region}: Change in {Description}",
sep = " - "
),
positive_color = "#2E8B57", # Color for positive values
negative_color = "#CD5C5C", # Color for negative values
all_font_size = 1.1, # Scale for all font sizes in the plot
panel_rows = 1, # Number of rows for the panel layout, NULL for automatic calculation
panel_cols = NULL, # Number of columns for the panel layout, NULL for automatic calculation
show_axis_titles_on_all_facets = FALSE # To show label only at first panel
)
)
This R script is designed for three-dimensional data plot like qxs
. This example assumes that you chose to extract qxs
during 1.ProjectSetup
Note: This code can be applied to any dimensional data by adding more columns to split_by
.
# For help function use: ?detail_plot
detail.data <- bilateral_data[["qxs"]] # Dataframe with three-dimensional data
threed_detail <- detail_plot(
data = detail.data,
x_axis_from = "Commodity", # Column used for the x-axis
filter_var = NULL, # Filter data based on specific values in the defined column(s)
split_by = c("Source", "Destination"), # Split plots by Source & Destination
panel_var = "Experiment", # Column used for paneling (faceting)
top_impact = NULL, # Optionally limit to top-N most impactful entries per panel
invert_axis = TRUE, # Whether to invert the panel (facet) order
separate_figure = FALSE, # Whether to generate a separate figure for each panel
var_name_by_description = TRUE, # Use the description as the variable name
add_var_info = FALSE, # Add variable code in parentheses
export_picture = TRUE, # Export the plots as image files
export_as_pdf = "merged", # Export the plots as PDF. Use "merged" to combine all plots into one PDF
output_path = output.folder,
# Output Configurations
## Try adjusting widgth and height if output is too dense, too small, or not displayed properly
export_config = create_export_config(
width = 30, # Width of the output plot in inches
height = 12 # Height of the output plot in inches
),
plot_style_config = create_plot_style(
show_title = TRUE, # FALSE to hide plot title
title_format = create_title_format(
type = "dynamic", # Use {Source} and {Destination} from column values
text = "Change in bilateral trade between {Source} and {Destination}",
sep = ""
),
positive_color = "#2E8B57", # Color for positive values
negative_color = "#CD5C5C", # Color for negative values
all_font_size = 1.1, # Scale for all font sizes in the plot
panel_rows = 1, # Number of rows for the panel layout, NULL for automatic calculation
panel_cols = NULL, # Number of columns for the panel layout, NULL for automatic calculation
show_axis_titles_on_all_facets = FALSE # To show label only at first panel
)
)
This function is similar to the "Default" code, but adds top_impact = 10
to automatically filter the top 10 most impacted sectors (e.g., x_axis_from = "Commodity"
).
Note: When using top_impact
, it is highly recommended to set sort_data_by_value = TRUE
to ensure consistent axis ordering across panels. This is because each panel may display different sectors based on the top impacts.
# For help function use: ?detail_plot
## You can change `top_impact` to any numeric value.
detail.data <- sl4.plot.data[["COMM*REG"]] # Replace with your actual dataframe
default_detail <- detail_plot(
data = detail.data,
x_axis_from = "Commodity", # Column used for the x-axis
filter_var = NULL, # Filter data based on specific values in the defined column(s)
split_by = "Region", # Column(s) used to split data into separate plots (e.g., one plot per variable)
panel_var = "Experiment", # Column used for paneling (faceting)
top_impact = 5, # Optionally limit to top-N most impactful entries per panel (e.g., top_impact = 10)
invert_axis = TRUE, # Whether to invert the panel (facet) order
separate_figure = FALSE, # Whether to generate a separate figure for each panel
var_name_by_description = TRUE, # Use the description as the variable name (e.g., qgdp becomes Real GDP)
add_var_info = FALSE, # Add variable code in parentheses (e.g., Real GDP (qgdp))
export_picture = TRUE, # Export the plots as image files
export_as_pdf = "merged", # Export the plots as PDF. Use "merged" to combine all plots into one PDF
output_path = output.folder,
# Output Configurations
## Try adjusting widgth and height if output is too dense, too small, or not displayed properly
export_config = create_export_config(
width = 20, # Width of the output plot in inches
height = 8 # Height of the output plot in inches
),
plot_style_config = create_plot_style(
show_title = TRUE, # FALSE to hide plot title
title_format = create_title_format(
type = "prefix", # option: standard (default), prefix, suffix, full, dynamic
text = "Change in",
sep = " - "
),
positive_color = "#2E8B57", # Color for positive values
negative_color = "#CD5C5C", # Color for negative values
all_font_size = 1, # Scale for all font sizes in the plot
panel_rows = 1, # Number of rows for the panel layout, NULL for automatic calculation
panel_cols = NULL, # Number of columns for the panel layout, NULL for automatic calculation
show_axis_titles_on_all_facets = TRUE, # To show label of each panel separately
sort_data_by_value = TRUE # Sorting the plot by positive-negative impact
)
)
This R script is designed for full customization—everything must be defined from scratch. Please refer to the Plot Style Configs section before using it.
# For help function use: ?detail_plot
detail.data <- sl4.plot.data[["COMM*REG"]] # Replace with your actual dataframe name
adv.detail.plot <- detail_plot(
data = detail.data,
x_axis_from = "Colname",
filter_var = NULL,
split_by = c("Var1", "Var2", "Var3"),
panel_var = "Experiment",
variable_col = "Variable",
unit_col = "Unit",
desc_col = "Description",
top_impact = NULL,
invert_axis = FALSE,
separate_figure = FALSE,
var_name_by_description = FALSE,
add_var_info = FALSE,
export_picture = FALSE,
export_as_pdf = FALSE,
output_path = "/your/path",
# Output Configurations
export_config = create_export_config(
width = NULL,
height = NULL,
dpi = 300,
bg = "white",
limitsize = FALSE
)
# All Plot Configurations
plot_style_config = create_plot_style(
# Title settings
show_title = TRUE,
title_face = "bold",
title_size = 20,
title_hjust = 0.5,
add_unit_to_title = TRUE,
title_margin = c(10, 0, 10, 0), #c(top, right, bottom, left)
title_format = create_title_format(
type = "standard", #option: standard (default), prefix, suffix, full, dynamic
text = "",
sep = ""
),
# X-Axis settings
show_x_axis_title = TRUE,
x_axis_title_face = "bold",
x_axis_title_size = 16,
x_axis_title_margin = c(25, 25, 0, 0), #c(top, right, bottom, left)
show_x_axis_labels = TRUE,
x_axis_text_face = "plain",
x_axis_text_size = 14,
x_axis_text_angle = 0,
x_axis_text_hjust = 0,
x_axis_description = "",
# Y-Axis settings
show_y_axis_title = TRUE,
y_axis_title_face = "bold",
y_axis_title_size = 16,
y_axis_title_margin = c(25, 25, 0, 0), #c(top, right, bottom, left)
show_y_axis_labels = TRUE,
y_axis_text_face = "plain",
y_axis_text_size = 14,
y_axis_text_angle = 0,
y_axis_text_hjust = 0,
y_axis_description = "",
show_axis_titles_on_all_facets = TRUE,
# Value Labels
show_value_labels = TRUE,
value_label_face = "plain",
value_label_size = 5,
value_label_position = "above",
value_label_decimal_places = 2,
# Legend
show_legend = FALSE,
show_legend_title = FALSE,
legend_position = "bottom",
legend_title_face = "bold",
legend_text_face = "plain",
legend_text_size = 14,
# Panel Strip
strip_face = "bold",
strip_text_size = 16,
strip_background = "lightgrey",
strip_text_margin = c(10, 0, 10, 0), #c(top, right, bottom, left)
# Panel Layout
panel_spacing = 2,
panel_rows = NULL,
panel_cols = NULL,
theme = NULL,
# Colors and Grid
color_tone = NULL,
color_palette_type = "qualitative", #option: qualitative, sequential, diverging
positive_color = "#2E8B57",
negative_color = "#CD5C5C",
background_color = "white",
grid_color = "grey90",
show_grid_major_x = FALSE,
show_grid_major_y = FALSE,
show_grid_minor_x = FALSE,
show_grid_minor_y = FALSE,
# Zero Line
show_zero_line = TRUE,
zero_line_type = "dashed",
zero_line_color = "black",
zero_line_size = 0.5,
zero_line_position = 0,
# Bar Chart
bar_width = 0.9,
bar_spacing = 0.9,
# Scale Settings
scale_limit = NULL,
scale_increment = NULL,
# Scale Expansion
expansion_y_mult = c(0.05, 0.1),
expansion_x_mult = c(0.05, 0.05),
# Font Size Control
all_font_size = 1,
# Data Sorting
sort_data_by_value = FALSE,
# Plot Margin
plot.margin = c(10, 25, 10, 10) #c(top, right, bottom, left)
)
)
This R script is designed to create a stack plot suitable for decomposition analysis—such as welfare decomposition from header A
of -WEL.har
.
# For help function use: ?stack_plot
stack.data <- har.plot.data[["A"]] # Replace with your actual dataframe
default_stack <- stack_plot(
data = stack.data,
x_axis_from = "Region", # Column used for the x-axis
filter_var = NULL, # Optional column to filter data based on x-axis
stack_value_from = "COLUMN", # Column that defines the components of the stack plot
show_total = TRUE, # Show the total value label in the stack plot
unstack_plot = FALSE, # If TRUE, unstack the bars and display them separately
split_by = FALSE, # Column(s) used to split data into separate plots; FALSE disables splitting
panel_var = "Experiment", # Column used for paneling (faceting)
top_impact = NULL, # Optionally limit to top-N most impactful entries per panel
invert_axis = FALSE, # Whether to invert the panel (facet) order
separate_figure = FALSE, # Whether to generate a separate figure for each panel
var_name_by_description = FALSE, # Use the description as the variable name (e.g., qgdp becomes Real GDP)
add_var_info = FALSE, # Add variable code in parentheses (e.g., Real GDP (qgdp))
export_picture = TRUE, # Export the plots as image files
export_as_pdf = "merged", # Export the plots as PDF; use "merged" to combine all plots into one PDF
output_path = output.folder,
# Output Configurations
export_config = create_export_config(
width = 20, # Width of the output plot in inches
height = 12 # Height of the output plot in inches
),
# Styling
plot_style_config = create_plot_style(
title_format = create_title_format(
type = "full", # Options: standard, prefix, suffix, full, dynamic
text = "Welfare Decomposition",
sep = ""
),
color_tone = "purdue", # Color palette for the plot
all_font_size = 1, # Scale for all font sizes in the plot
panel_rows = 1, # Number of rows for the panel layout; NULL for automatic calculation
panel_cols = NULL # Number of columns for the panel layout; NULL for automatic calculation
)
)
This R script is designed to create an unstacked plot, suitable for further analyzing decomposition results at a disaggregated level (e.g., by country).
# For help function use: ?stack_plot
stack.data <- har.plot.data[["A"]] # Replace with your actual dataframe
default_unstack <- stack_plot(
data = stack.data,
x_axis_from = "Region", # Column used for the x-axis
filter_var = NULL, # Filter data based on specific values in the defined column(s)
stack_value_from = "COLUMN", # Column that defines the components of the stack plot
show_total = TRUE, # Show the total value label in the stack plot
unstack_plot = TRUE, # If TRUE, unstack the bars and display them separately (comparison style)
split_by = "Region", # Column(s) used to split data into separate plots
panel_var = "Experiment", # Column used for paneling (faceting)
top_impact = NULL, # Optionally limit to top-N most impactful entries per panel
invert_axis = TRUE, # Whether to invert the panel (facet) order
separate_figure = FALSE, # Whether to generate a separate figure for each panel
var_name_by_description = FALSE, # Use the description as the variable name
add_var_info = FALSE, # Add variable code in parentheses
export_picture = TRUE, # Export the plots as image files
export_as_pdf = "merged", # Export the plots as PDF; use "merged" to combine all plots into one PDF
output_path = output.folder,
# Output Configurations
export_config = create_export_config(
width = 20, # Width of the output plot in inches
height = 9 # Height of the output plot in inches
),
# Styling
plot_style_config = create_plot_style(
show_title = TRUE, # FALSE to hide plot title
title_format = create_title_format(
type = "full", # Options: standard, prefix, suffix, full, dynamic
text = "Welfare Decomposition (Unstack)",
sep = ""
),
color_tone = "purdue", # Color palette for the plot
all_font_size = 1, # Scale for all font sizes in the plot
panel_rows = 1, # Number of rows for the panel layout; NULL for auto
panel_cols = NULL, # Number of columns for the panel layout; NULL for auto
show_axis_titles_on_all_facets = FALSE
)
)
This R script is designed for full customization—everything must be defined from scratch. Please refer to the Plot Style Configs section before using it.
# For help function use: ?stack_plot
stack_plot_data <- har.plot.data[["A"]] # Replace with your actual dataframe name
adv.stack.plot <- stack_plot(
data = detail.data,
x_axis_from = "Colname",
filter_var = NULL,
split_by = NULL,
stack_value_from = "Colname",
unstack_plot = TRUE,
panel_var = "Experiment",
variable_col = "Variable",
unit_col = "Unit",
desc_col = "Description",
top_impact = NULL,
invert_axis = FALSE,
separate_figure = FALSE,
var_name_by_description = FALSE,
add_var_info = FALSE,
export_picture = FALSE,
export_as_pdf = FALSE,
output_path = "/your/path",
# Output Configurations
export_config = create_export_config(
width = NULL,
height = NULL,
dpi = 300,
bg = "white",
limitsize = FALSE
)
# All Plot Configurations
plot_style_config = create_plot_style(
# Title settings
show_title = TRUE,
title_face = "bold",
title_size = 20,
title_hjust = 0.5,
add_unit_to_title = TRUE,
title_margin = c(10, 0, 10, 0), #c(top, right, bottom, left)
title_format = create_title_format(
type = "standard", #option: standard (default), prefix, suffix, full, dynamic
text = "",
sep = ""
),
# X-Axis settings
show_x_axis_title = TRUE,
x_axis_title_face = "bold",
x_axis_title_size = 16,
x_axis_title_margin = c(25, 25, 0, 0), #c(top, right, bottom, left)
show_x_axis_labels = TRUE,
x_axis_text_face = "plain",
x_axis_text_size = 14,
x_axis_text_angle = 0,
x_axis_text_hjust = 0,
x_axis_description = "",
# Y-Axis settings
show_y_axis_title = TRUE,
y_axis_title_face = "bold",
y_axis_title_size = 16,
y_axis_title_margin = c(25, 25, 0, 0), #c(top, right, bottom, left)
show_y_axis_labels = TRUE,
y_axis_text_face = "plain",
y_axis_text_size = 14,
y_axis_text_angle = 0,
y_axis_text_hjust = 0,
y_axis_description = "",
show_axis_titles_on_all_facets = TRUE,
# Value Labels
show_value_labels = TRUE,
value_label_face = "plain",
value_label_size = 5,
value_label_position = "above",
value_label_decimal_places = 2,
# Legend
show_legend = FALSE,
show_legend_title = FALSE,
legend_position = "bottom",
legend_title_face = "bold",
legend_text_face = "plain",
legend_text_size = 14,
# Panel Strip
strip_face = "bold",
strip_text_size = 16,
strip_background = "lightgrey",
strip_text_margin = c(10, 0, 10, 0), #c(top, right, bottom, left)
# Panel Layout
panel_spacing = 2,
panel_rows = NULL,
panel_cols = NULL,
theme = NULL,
# Colors and Grid
color_tone = NULL,
color_palette_type = "qualitative", #option: qualitative, sequential, diverging
positive_color = "#2E8B57",
negative_color = "#CD5C5C",
background_color = "white",
grid_color = "grey90",
show_grid_major_x = FALSE,
show_grid_major_y = FALSE,
show_grid_minor_x = FALSE,
show_grid_minor_y = FALSE,
# Zero Line
show_zero_line = TRUE,
zero_line_type = "dashed",
zero_line_color = "black",
zero_line_size = 0.5,
zero_line_position = 0,
# Bar Chart
bar_width = 0.9,
bar_spacing = 0.9,
# Scale Settings
scale_limit = NULL,
scale_increment = NULL,
# Scale Expansion
expansion_y_mult = c(0.05, 0.1),
expansion_x_mult = c(0.05, 0.05),
# Font Size Control
all_font_size = 1,
# Data Sorting
sort_data_by_value = FALSE,
# Plot Margin
plot.margin = c(10, 25, 10, 10) #c(top, right, bottom, left)
)
)
get_all_config()
Rename the list outputs my_export_config
and
my_style_config
to any names you prefer; you can create as
many styles as needed.
Enter the name of your custom style list into the plot function,
while other settings in (...)
remain unchanged, as shown in
the sample below:
comparison_plot <- (...,
export_config = my_export_config,
plot_style_config = my_style_config
)