Skip to contents

Returns configuration settings for plot styles, with options to view as a structured dataframe or to look up specific parameters. Also provides parameter validation for custom configurations.

Usage

get_plot_style_config(
  plot_type = "default",
  parameter_name = NULL,
  show_docs = FALSE,
  validate_custom = NULL,
  as_dataframe = FALSE,
  printing = TRUE
)

Arguments

plot_type

Character. Type of plot: "comparison" (default), "detail", or "stack".

parameter_name

Character or NULL. Name of specific parameter to return information about.

show_docs

Logical. Whether to include documentation in the output.

validate_custom

List or NULL. Custom configuration settings to validate.

as_dataframe

Logical. Whether to return settings as a dataframe.

printing

Logical. If TRUE, prints a formatted code snippet that can be copied and pasted to recreate the configuration. Default is FALSE.

Value

If parameter_name is specified, returns a list with the value and documentation for that parameter. If validate_custom is specified, returns the validated configuration list. If as_dataframe is TRUE, returns a dataframe with configuration settings. Otherwise, returns a list with all configuration settings.

Details

This function applies default styling for different types of plots and allows users to customize the appearance. The parameters are grouped as follows:

## **Title Settings** - `show_title`: Logical. Show or hide the plot title. Default: `TRUE` - `title_face`: Character. Font face (`"bold"`, `"plain"`, `"italic"`). Default: `"bold"` - `title_size`: Numeric. Font size of title. Default: `20` - `title_hjust`: Numeric. Horizontal alignment (0 = left, 1 = right). Default: `0.5` - `add_unit_to_title`: Logical. Append unit to title if applicable. Default: `TRUE` - `title_margin`: ggplot2 `margin()` object. Default: `ggplot2::margin(10, 0, 10, 0)` - `title_format`: List or NULL. Formatting options for the title, with elements:

  • type: Character. One of "prefix", "suffix", "full", or "dynamic".

  • text: Character. Text to add, or column names used for dynamic titles.

  • sep: Character. Separator used for dynamic titles. Default: " - ".

## **X-Axis Settings** - `show_x_axis_title`: Logical. Show or hide x-axis title. Default: `FALSE` - `x_axis_title_face`: Character. Font face for x-axis title. Default: `"bold"` - `x_axis_title_size`: Numeric. Font size of x-axis title. Default: `16` - `x_axis_title_margin`: ggplot2 `margin()`. Default: `ggplot2::margin(t = 20)` - `show_x_axis_labels`: Logical. Show or hide x-axis labels. Default: `TRUE` - `x_axis_text_face`: Character. Font face for x-axis labels. Default: `"bold"` - `x_axis_text_size`: Numeric. Font size of x-axis labels. Default: `14` - `x_axis_text_angle`: Numeric. Angle of x-axis labels. Default: `45` - `x_axis_text_hjust`: Numeric. Horizontal justification of x-axis labels. Default: `1` - `x_axis_description`: Character. Optional description for the x-axis. Default: `""`

## **Y-Axis Settings** - `show_y_axis_title`: Logical. Show or hide y-axis title. Default: `TRUE` - `y_axis_title_face`: Character. Font face for y-axis title. Default: `"bold"` - `y_axis_title_size`: Numeric. Font size of y-axis title. Default: `16` - `y_axis_title_margin`: ggplot2 `margin()`. Default: `ggplot2::margin(r = 20)` - `show_y_axis_labels`: Logical. Show or hide y-axis labels. Default: `TRUE` - `y_axis_text_face`: Character. Font face for y-axis labels. Default: `"plain"` - `y_axis_text_size`: Numeric. Font size of y-axis labels. Default: `14` - `y_axis_text_angle`: Numeric. Angle of y-axis labels. Default: `0` - `y_axis_text_hjust`: Numeric. Horizontal justification of y-axis labels. Default: `0` - `y_axis_description`: Character. Optional description for the y-axis. Default: `""` - `show_axis_titles_on_all_facets`: Logical. Show axis titles on all facets. Default: `TRUE`

## **Value Label Settings** - `show_value_labels`: Logical. Show or hide value labels. Default: `TRUE` - `value_label_face`: Character. Font face for value labels. Default: `"plain"` - `value_label_size`: Numeric. Font size of value labels. Default: `5` - `value_label_position`: Character. Position of value labels (`"above"`, `"outside"`, `"top"`). Default: `"above"` - `value_label_decimal_places`: Numeric. Number of decimal places in value labels. Default: `2`

## **Legend Settings** - `show_legend`: Logical. Show or hide legend. Default: `FALSE` - `show_legend_title`: Logical. Show or hide legend title. Default: `FALSE` - `legend_position`: Character. Legend position (`"none"`, `"bottom"`, `"right"`). Default: `"none"` - `legend_title_face`: Character. Font face for legend title. Default: `"bold"` - `legend_text_face`: Character. Font face for legend text. Default: `"plain"` - `legend_text_size`: Numeric. Font size for legend text. Default: `14`

## **Panel Strip Settings** - `strip_face`: Character. Font face for panel strip. Default: `"bold"` - `strip_text_size`: Numeric. Font size for panel strip. Default: `16` - `strip_background`: Character. Background color of strip. Default: `"lightgrey"` - `strip_text_margin`: ggplot2 `margin()`. Default: `ggplot2::margin(10, 0, 10, 0)`

## **Panel Layout** - `panel_spacing`: Numeric. Spacing between panels. Default: `2` - `panel_rows`: Numeric or `NULL`. Number of rows in panel layout. Default: `NULL` - `panel_cols`: Numeric or `NULL`. Number of columns in panel layout. Default: `NULL` - `theme`: ggplot2 theme object or `NULL`. Custom ggplot theme. Default: `NULL`

## **Color Settings** - `color_tone`: Character or `NULL`. Base color theme. Default: `NULL` - `positive_color`: Character. Color for positive values. Default: `"#2E8B57"` - `negative_color`: Character. Color for negative values. Default: `"#CD5C5C"` - `background_color`: Character. Background color of plot. Default: `"white"` - `grid_color`: Character. Color of grid lines. Default: `"grey90"` - `show_grid_major_x`: Logical. Show major grid lines on x-axis. Default: `FALSE` - `show_grid_major_y`: Logical. Show major grid lines on y-axis. Default: `TRUE` - `show_grid_minor_x`: Logical. Show minor grid lines on x-axis. Default: `FALSE` - `show_grid_minor_y`: Logical. Show minor grid lines on y-axis. Default: `FALSE`

## **Zero Line Settings** - `show_zero_line`: Logical. Show or hide zero line. Default: `TRUE` - `zero_line_type`: Character. Line type (`"solid"`, `"dashed"`, `"dotted"`). Default: `"dashed"` - `zero_line_color`: Character. Color of zero line. Default: `"black"` - `zero_line_size`: Numeric. Line thickness of zero line. Default: `0.5` - `zero_line_position`: Numeric. Position of the zero line. Default: `0`

## **Bar Chart Settings** - `bar_width`: Numeric. Width of bars. Default: `0.9` - `bar_spacing`: Numeric. Spacing between bars. Default: `0.9`

## **Scale Settings** - `scale_limit`: Numeric vector of length 2. Manual limits for value axis. Example: `c(-10, 10)` - `scale_increment`: Numeric. Step size for axis tick marks. Example: `2`

## **Scale Expansion Settings** - `expansion_y_mult`: Numeric vector. Y-axis expansion. Default: `c(0.05, 0.1)` - `expansion_x_mult`: Numeric vector. X-axis expansion. Default: `c(0.05, 0.05)`

## **All Font Adjustment** - `all_font_size`: Numeric. Master control for all font sizes. Default: `1`

Author

Pattawee Puangchit

Examples

# Get alldefault configuration
get_plot_style_config(printing = TRUE)
#> my_style_config <- list(
#> 
#>   # Title settings
#>   show_title = TRUE,
#>   title_face = "bold",
#>   title_size = 20,
#>   title_hjust = 0.5,
#>   add_unit_to_title = TRUE,
#>   title_margin = margin(t = 10, r = 0, b = 10, l = 0),
#>   title_format = list(
#>     type = "standard", #option: 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 = margin(t = 25, r = 25, b = 0, l = 0),
#>   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 = margin(t = 25, r = 25, b = 0, l = 0),
#>   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 = margin(t = 10, r = 0, b = 10, l = 0),
#> 
#>   # Panel Layout
#>   panel_spacing = 2,
#>   panel_rows = NULL,
#>   panel_cols = NULL,
#>   theme = NULL,
#> 
#>   # Colors
#>   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
#> )
#> 
#> # Example usage:
#> # comparison_plot(data, x_axis_from = "REG", plot_style_config = my_style_config)

# Get information about a specific parameter
param_info <- get_plot_style_config("default", "bar_width")

# Get as structured dataframe
config_df <- get_plot_style_config("default", as_dataframe = TRUE)

# Validate custom configuration
custom_config <- list(title_size = 24, bar_width = 0.7)
validated <- get_plot_style_config("default", validate_custom = custom_config)