| Title: | UC R Package for Econometrics and Data Science |
|---|---|
| Description: | Provides plotting helpers, table-formatting utilities, and report templates for econometrics, model development, and applied data analysis. Includes University of Cincinnati branded themes for 'ggplot2', 'modelsummary', 'flextable', 'rmarkdown', 'bookdown', and 'quarto'. |
| Authors: | Saannidhya Rawat [aut, cre] |
| Maintainer: | Saannidhya Rawat <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.2.0 |
| Built: | 2026-05-30 09:11:18 UTC |
| Source: | https://github.com/saannidhya/rbearcat |
An R Markdown output format for Beamer presentations (PDF).
bcat_beamer(in_header = NULL, ...)bcat_beamer(in_header = NULL, ...)
in_header |
relative path to a tex formatting document included in the preamble.
If |
... |
other options passed to |
Saannidhya Rawat
Produce a formatted correlation matrix with significance stars and UC styling. By default shows only the lower triangle.
bcat_cor_table( df, method = c("pearson", "spearman", "kendall"), full_matrix = FALSE, digits = 2, stars = TRUE, p_threshold = c(0.01, 0.05, 0.1), caption = NULL, font_size = 12, header_bg_color = palette_UC[["UC Red"]], header_txt_color = palette_UC[["White"]], striped = TRUE, doc_type = NULL, ... )bcat_cor_table( df, method = c("pearson", "spearman", "kendall"), full_matrix = FALSE, digits = 2, stars = TRUE, p_threshold = c(0.01, 0.05, 0.1), caption = NULL, font_size = 12, header_bg_color = palette_UC[["UC Red"]], header_txt_color = palette_UC[["White"]], striped = TRUE, doc_type = NULL, ... )
df |
A data frame of numeric columns. |
method |
Character. Correlation method: |
full_matrix |
Logical. Show full matrix? Default is FALSE (lower triangle only). |
digits |
Integer. Decimal places. Default is 2. |
stars |
Logical. Show significance stars? Default is TRUE. |
p_threshold |
Numeric vector of p-value thresholds for stars.
Default: |
caption |
Character. Table caption. |
font_size |
Numeric. Font size. Default is 12. |
header_bg_color |
Background color for header. |
header_txt_color |
Text color for header. |
striped |
Logical. Zebra striping? |
doc_type |
Character. Force output format. Auto-detected if NULL. |
... |
Additional arguments passed to table formatting. |
A formatted table object.
Saannidhya Rawat
Other tables:
bcat_fmt_style_table(),
bcat_reg_table(),
bcat_sum_table()
bcat_cor_table(mtcars[, c("mpg", "wt", "hp", "disp")]) bcat_cor_table(mtcars[, c("mpg", "wt", "hp")], method = "spearman")bcat_cor_table(mtcars[, c("mpg", "wt", "hp", "disp")]) bcat_cor_table(mtcars[, c("mpg", "wt", "hp")], method = "spearman")
This utility function is useful for extracting column values that will be used for inline text by saving metadata column values in a nested (named) list.
bcat_extract_metadata(df, id_col)bcat_extract_metadata(df, id_col)
df |
input data |
id_col |
ID column used identify observations |
Saannidhya Rawat
Other utilities:
bcat_import_data(),
bcat_new_quarto(),
bcat_setup_rmd(),
bcat_source_rmd()
library(Rbearcat) library(tibble) lob_df <- tibble(lob = c("drl", "mla", "rac"), balance = bcat_fmt_dollar(c(11, 26, 7)), nco = bcat_fmt_dollar(c(80, 45, 800))) # extract metadata from each column and save to list lob_meta <- bcat_extract_metadata(lob_df, lob) # extract individual values from list lob_meta$balance$mla lob_meta$nco$raclibrary(Rbearcat) library(tibble) lob_df <- tibble(lob = c("drl", "mla", "rac"), balance = bcat_fmt_dollar(c(11, 26, 7)), nco = bcat_fmt_dollar(c(80, 45, 800))) # extract metadata from each column and save to list lob_meta <- bcat_extract_metadata(lob_df, lob) # extract individual values from list lob_meta$balance$mla lob_meta$nco$rac
A wrapper for scales::label_comma to format a numeric vector
to force decimal display of numbers with comma separators.
bcat_fmt_comma(x, accuracy = NULL, scale = 1, ...)bcat_fmt_comma(x, accuracy = NULL, scale = 1, ...)
x |
a numeric vector |
accuracy |
A number to round to. Use (e.g.) |
scale |
A scaling factor: |
... |
other arguments passed to label_comma |
Other formatting:
bcat_fmt_date(),
bcat_fmt_dollar(),
bcat_fmt_percent(),
bcat_fmt_pvalue(),
bcat_fmt_scientific()
bcat_fmt_comma(c(5000, 10000, 8000)) bcat_fmt_comma(c(5000, 10000, 8000), scale = 10e-4, accuracy = 1, suffix = "K")bcat_fmt_comma(c(5000, 10000, 8000)) bcat_fmt_comma(c(5000, 10000, 8000), scale = 10e-4, accuracy = 1, suffix = "K")
A wrapper for base::format to convert character or date vector to specfied
date/time format.
bcat_fmt_date(x, format = "%B %e, %Y", ...)bcat_fmt_date(x, format = "%B %e, %Y", ...)
x |
a character or date/datetime vector |
format |
a date/time format string using standard POSIX specification |
... |
other arguments passed to format |
Other formatting:
bcat_fmt_comma(),
bcat_fmt_dollar(),
bcat_fmt_percent(),
bcat_fmt_pvalue(),
bcat_fmt_scientific()
bcat_fmt_date(Sys.Date()) bcat_fmt_date(c("2019-12-03", "2020-05-22"))bcat_fmt_date(Sys.Date()) bcat_fmt_date(c("2019-12-03", "2020-05-22"))
A wrapper for scales::label_dollar to format a numeric vector to dollars and cents.
bcat_fmt_dollar( x, accuracy = NULL, scale = 1, largest_with_cents = 1e+05, style_negative = c("hyphen", "parens"), ... )bcat_fmt_dollar( x, accuracy = NULL, scale = 1, largest_with_cents = 1e+05, style_negative = c("hyphen", "parens"), ... )
x |
a numeric vector |
accuracy |
Number to round to. If NULL, the default, values will be rounded to the nearest integer |
scale |
A scaling factor: |
largest_with_cents |
largest numeric value for which cents will be displayed |
style_negative |
Character. How to display negative values:
|
... |
other arguments passed on to label_dollar |
Other formatting:
bcat_fmt_comma(),
bcat_fmt_date(),
bcat_fmt_percent(),
bcat_fmt_pvalue(),
bcat_fmt_scientific()
bcat_fmt_dollar(1:4) bcat_fmt_dollar(c(-20, -10, 10, 20)) bcat_fmt_dollar(c(-20, -10, 10, 20), style_negative = "parens")bcat_fmt_dollar(1:4) bcat_fmt_dollar(c(-20, -10, 10, 20)) bcat_fmt_dollar(c(-20, -10, 10, 20), style_negative = "parens")
A wrapper for scales::label_percent to format a numeric vector to percentages.
bcat_fmt_percent(x, accuracy = NULL, scale = 100, ...)bcat_fmt_percent(x, accuracy = NULL, scale = 100, ...)
x |
a numeric vector |
accuracy |
A number to round to. Use (e.g.) |
scale |
A scaling factor: |
... |
other arguments passed to label_percent |
Other formatting:
bcat_fmt_comma(),
bcat_fmt_date(),
bcat_fmt_dollar(),
bcat_fmt_pvalue(),
bcat_fmt_scientific()
bcat_fmt_percent(c(0.01, 0.05, 0.02)) bcat_fmt_percent(c(0.0151321, 0.090115, 0.022141)) bcat_fmt_percent(c(0.0151321, 0.090115, 0.022141), accuracy = 0.001) bcat_fmt_percent(c(1.31, 2.44, 3.0), scale = 1)bcat_fmt_percent(c(0.01, 0.05, 0.02)) bcat_fmt_percent(c(0.0151321, 0.090115, 0.022141)) bcat_fmt_percent(c(0.0151321, 0.090115, 0.022141), accuracy = 0.001) bcat_fmt_percent(c(1.31, 2.44, 3.0), scale = 1)
A wrapper for scales::label_pvalue to format a numeric vector to
p-values, using "<" and ">" for p-values close to 0 and 1.
bcat_fmt_pvalue(x, accuracy = 0.001, add_p = FALSE, ...)bcat_fmt_pvalue(x, accuracy = 0.001, add_p = FALSE, ...)
x |
a numeric vector |
accuracy |
A number to round to. Use (e.g.) |
add_p |
logical. Add "p=" before the value? |
... |
other arguments passed to label_pvalue |
Other formatting:
bcat_fmt_comma(),
bcat_fmt_date(),
bcat_fmt_dollar(),
bcat_fmt_percent(),
bcat_fmt_scientific()
bcat_fmt_pvalue(c(0.01, 0.05, 0.02)) bcat_fmt_pvalue(c(0.000001, 0.999115, 0.022141)) bcat_fmt_pvalue(c(0.000001, 0.999115, 0.022141), add_p = TRUE)bcat_fmt_pvalue(c(0.01, 0.05, 0.02)) bcat_fmt_pvalue(c(0.000001, 0.999115, 0.022141)) bcat_fmt_pvalue(c(0.000001, 0.999115, 0.022141), add_p = TRUE)
A wrapper for scales::label_scientific to format a numeric
vector to scientific notation.
bcat_fmt_scientific(x, digits = 3, scale = 1, ...)bcat_fmt_scientific(x, digits = 3, scale = 1, ...)
x |
a numeric vector |
digits |
number of digits to show before exponent. |
scale |
A scaling factor: |
... |
other arguments passed to label_scientific |
Other formatting:
bcat_fmt_comma(),
bcat_fmt_date(),
bcat_fmt_dollar(),
bcat_fmt_percent(),
bcat_fmt_pvalue()
bcat_fmt_scientific(c(1:10)*10e5)bcat_fmt_scientific(c(1:10)*10e5)
Format tables for output to final documentation. Automatically detects output format (HTML, PDF, Word, PPTX) and applies UC styling.
bcat_fmt_style_table( df, caption = NULL, footer = NULL, header = NULL, header_bg_color = palette_UC[["UC Red"]], header_txt_color = palette_UC[["White"]], align, font_size = 12, striped = TRUE, full_width = FALSE, scale_down = FALSE, longtable = FALSE, col_names = NA, threeparttable = FALSE, doc_type = c(knitr::opts_knit$get("rmarkdown.pandoc.to"), "html", "pdf", "docx", "pptx"), ... )bcat_fmt_style_table( df, caption = NULL, footer = NULL, header = NULL, header_bg_color = palette_UC[["UC Red"]], header_txt_color = palette_UC[["White"]], align, font_size = 12, striped = TRUE, full_width = FALSE, scale_down = FALSE, longtable = FALSE, col_names = NA, threeparttable = FALSE, doc_type = c(knitr::opts_knit$get("rmarkdown.pandoc.to"), "html", "pdf", "docx", "pptx"), ... )
df |
Data frame to format. |
caption |
Character. Table caption. |
footer |
Character. Table footnote. |
header |
Character. Spanning header text above all columns. |
header_bg_color |
Background fill color for header. Default is UC Red. |
header_txt_color |
Text color for header. Default is white. |
align |
Character vector of column alignments: 'l' (left), 'c' (center), 'r' (right). |
font_size |
Numeric. Font size for table. Default is 12. |
striped |
Logical. Enable zebra striping? Default is TRUE. |
full_width |
Logical. Should HTML table be full width? Default is FALSE. |
scale_down |
Logical. Scale LaTeX table to fit page? Default is FALSE. |
longtable |
Logical. Use longtable for multi-page PDF tables? Default is FALSE. |
col_names |
Character vector of column names. Set to NULL to remove header row. |
threeparttable |
Logical. Use LaTeX threeparttable for footnotes? Default is FALSE. |
doc_type |
Manually set document type. Auto-detected if not specified. |
... |
Additional arguments passed to |
A formatted table object (kableExtra for HTML/PDF, flextable for Word/PPTX).
Saannidhya Rawat
Other tables:
bcat_cor_table(),
bcat_reg_table(),
bcat_sum_table()
bcat_fmt_style_table(iris[1:10, ]) bcat_fmt_style_table(iris[1:5, ], caption = "Iris Sample", striped = TRUE)bcat_fmt_style_table(iris[1:10, ]) bcat_fmt_style_table(iris[1:5, ], caption = "Iris Sample", striped = TRUE)
An R Markdown output format for the Gitbook format (HTML).
bcat_gitbook(css = NULL, after_body = NULL, collapse = "subsection", ...)bcat_gitbook(css = NULL, after_body = NULL, collapse = "subsection", ...)
css |
relative path to a css formatting document.
If |
after_body |
relative path to HTML file to include after body of each chapter.
If |
collapse |
specify level at which to collapse the table of contents. |
... |
other options passed to |
Saannidhya Rawat
Utility to import multiple data sets from a directory into a named list.
bcat_import_data(location, extension, import_function, recursive = TRUE)bcat_import_data(location, extension, import_function, recursive = TRUE)
location |
Character. Directory from which to import data. |
extension |
Character. File extension to match (without "."). |
import_function |
Function used to read each file (e.g., |
recursive |
Logical. Search subdirectories? Default is |
A named list of data frames. Names are derived from filenames (without extension).
Use list2env(result, envir = .GlobalEnv) to assign each to the global environment.
Saannidhya Rawat
Other utilities:
bcat_extract_metadata(),
bcat_new_quarto(),
bcat_setup_rmd(),
bcat_source_rmd()
## Not run: # Import all CSV files from a directory datasets <- bcat_import_data("data/", "csv", readr::read_csv) # Access individual datasets datasets$my_file # Optionally assign all to global environment list2env(datasets, envir = .GlobalEnv) ## End(Not run)## Not run: # Import all CSV files from a directory datasets <- bcat_import_data("data/", "csv", readr::read_csv) # Access individual datasets datasets$my_file # Optionally assign all to global environment list2env(datasets, envir = .GlobalEnv) ## End(Not run)
Copies a UC Quarto template into the specified directory, ready to edit and render.
bcat_new_quarto( type = c("html", "pdf", "revealjs"), path = getwd(), overwrite = FALSE )bcat_new_quarto( type = c("html", "pdf", "revealjs"), path = getwd(), overwrite = FALSE )
type |
Character. Template type: |
path |
Character. Directory to copy the template into. Default is current working directory. |
overwrite |
Logical. Overwrite existing files? Default is FALSE. |
Invisible path to the created template file.
Saannidhya Rawat
Other utilities:
bcat_extract_metadata(),
bcat_import_data(),
bcat_setup_rmd(),
bcat_source_rmd()
## Not run: bcat_new_quarto("html") bcat_new_quarto("revealjs", path = "slides/") ## End(Not run)## Not run: bcat_new_quarto("html") bcat_new_quarto("revealjs", path = "slides/") ## End(Not run)
An R Markdown output format for the PDF books.
bcat_pdf_book(in_header = NULL, before_body = NULL, toc_depth = 4, ...)bcat_pdf_book(in_header = NULL, before_body = NULL, toc_depth = 4, ...)
in_header |
relative path to a tex formatting document included in the preamble.
If |
before_body |
relative path to a tex document included in before the body of the document.
If |
toc_depth |
depth of headers to include in table of contents |
... |
other options passed to |
Saannidhya Rawat
Create an area plot using ggplot2 graphics. This function is a wrapper to create commonly used styles of area plots. Additional layers can be added to this plot as needed. More complicated plots can be creating using individual ggplot2 layers.
bcat_plt_area( df, x = NULL, y = NULL, fill = NULL, facet = NULL, position = c("stack", "fill"), x_lab = ggplot2::waiver(), y_lab = ggplot2::waiver(), title = ggplot2::waiver(), subtitle = ggplot2::waiver(), caption = ggplot2::waiver(), legend_lab = ggplot2::waiver(), legend_position = "right", legend_hide = FALSE, x_scale = NULL, y_scale = NULL, fill_scale = Rbearcat::scale_fill_UC(), facet_scale = c("fixed", "free_y", "free_x", "free"), nrow = NULL, ncol = NULL, x_refline = NULL, y_refline = NULL )bcat_plt_area( df, x = NULL, y = NULL, fill = NULL, facet = NULL, position = c("stack", "fill"), x_lab = ggplot2::waiver(), y_lab = ggplot2::waiver(), title = ggplot2::waiver(), subtitle = ggplot2::waiver(), caption = ggplot2::waiver(), legend_lab = ggplot2::waiver(), legend_position = "right", legend_hide = FALSE, x_scale = NULL, y_scale = NULL, fill_scale = Rbearcat::scale_fill_UC(), facet_scale = c("fixed", "free_y", "free_x", "free"), nrow = NULL, ncol = NULL, x_refline = NULL, y_refline = NULL )
df |
The data to be displayed |
x |
variable to map to the x-axis |
y |
Variable to map to the y-axis |
fill |
Variable to map to the fill aesthetic |
facet |
Facetting variable(s). Note: must wrap in |
position |
Either stack values in cumulative fashion ( |
x_lab |
Label for x-axis |
y_lab |
Label for y-axis |
title |
Plot title |
subtitle |
Plot subtitle |
caption |
Plot caption |
legend_lab |
Legend title |
legend_position |
legend position. "bottom" or "right" |
legend_hide |
Set to |
x_scale |
|
y_scale |
|
fill_scale |
|
facet_scale |
Shoud facet scales be fixed ("fixed", the default), free ("free"), or free in one dimension ("free_x", "free_y") |
nrow |
Number of facet rows |
ncol |
Number of facet columns |
x_refline |
Vector of x-values at which to draw vertical reference lines |
y_refline |
Vector of y-values at which to draw horizontal reference lines |
Saannidhya Rawat
Other plots:
bcat_plt_bar(),
bcat_plt_box(),
bcat_plt_coef(),
bcat_plt_diag(),
bcat_plt_hist(),
bcat_plt_line(),
bcat_plt_point(),
bcat_plt_ts()
set.seed(1234) d <- data.frame(t=rep(0:23,each=4),var=rep(LETTERS[1:4],4),val=round(runif(4*24,0,50))) # stacked area plot bcat_plt_area(df = d, x = t, y = val, fill = var, position = "stack", fill_scale = ggplot2::scale_fill_viridis_d(), legend_lab = NULL) # filled area plot bcat_plt_area(df = d, x = t, y = val, fill = var, position = "fill", fill_scale = ggplot2::scale_fill_viridis_d(), legend_lab = NULL)set.seed(1234) d <- data.frame(t=rep(0:23,each=4),var=rep(LETTERS[1:4],4),val=round(runif(4*24,0,50))) # stacked area plot bcat_plt_area(df = d, x = t, y = val, fill = var, position = "stack", fill_scale = ggplot2::scale_fill_viridis_d(), legend_lab = NULL) # filled area plot bcat_plt_area(df = d, x = t, y = val, fill = var, position = "fill", fill_scale = ggplot2::scale_fill_viridis_d(), legend_lab = NULL)
Create a bar plot using ggplot2 graphics. This function is a wrapper to create commonly used styles of bar plots. Additional layers can be added to this plot as needed. More complicated plots can be creating using individual ggplot2 layers.
bcat_plt_bar( df, x = NULL, y = NULL, fill = NULL, facet = NULL, stat = c("freq", "identity", "sum", "mean", "median"), position = c("stack", "dodge", "fill"), x_lab = ggplot2::waiver(), y_lab = ggplot2::waiver(), title = ggplot2::waiver(), subtitle = ggplot2::waiver(), caption = ggplot2::waiver(), legend_lab = ggplot2::waiver(), legend_position = "bottom", legend_hide = FALSE, x_scale = NULL, y_scale = NULL, fill_scale = Rbearcat::scale_fill_UC(), facet_scale = c("fixed", "free_y", "free_x", "free"), nrow = NULL, ncol = NULL, x_refline = NULL, y_refline = NULL, coord_flip = FALSE, order = FALSE )bcat_plt_bar( df, x = NULL, y = NULL, fill = NULL, facet = NULL, stat = c("freq", "identity", "sum", "mean", "median"), position = c("stack", "dodge", "fill"), x_lab = ggplot2::waiver(), y_lab = ggplot2::waiver(), title = ggplot2::waiver(), subtitle = ggplot2::waiver(), caption = ggplot2::waiver(), legend_lab = ggplot2::waiver(), legend_position = "bottom", legend_hide = FALSE, x_scale = NULL, y_scale = NULL, fill_scale = Rbearcat::scale_fill_UC(), facet_scale = c("fixed", "free_y", "free_x", "free"), nrow = NULL, ncol = NULL, x_refline = NULL, y_refline = NULL, coord_flip = FALSE, order = FALSE )
df |
The data to be displayed |
x |
Categorical variable to map to the x-axis |
y |
Variable to map to the y-axis. Only applicable if |
fill |
Variable to map to the fill aesthetic |
facet |
Facetting variable(s). Note: must wrap in |
stat |
Statistic to map to y-axis. Default ("freq") calculates frequencies,
"identity" plots the data as-is. "sum", "mean", and "median" calculate
and display the respective summary stats
Must specify |
position |
For grouped data, either stack bars ( |
x_lab |
Label for x-axis |
y_lab |
Label for y-axis |
title |
Plot title |
subtitle |
Plot subtitle |
caption |
Plot caption |
legend_lab |
Legend title |
legend_position |
legend position. "bottom" or "right" |
legend_hide |
Set to |
x_scale |
|
y_scale |
|
fill_scale |
|
facet_scale |
Shoud facet scales be fixed ("fixed", the default), free ("free"), or free in one dimension ("free_x", "free_y")? |
nrow |
Number of facet rows |
ncol |
Number of facet columns |
x_refline |
Vector of x-values at which to draw vertical reference lines |
y_refline |
Vector of y-values at which to draw horizontal reference lines |
coord_flip |
Set to |
order |
Set to |
Saannidhya Rawat
Other plots:
bcat_plt_area(),
bcat_plt_box(),
bcat_plt_coef(),
bcat_plt_diag(),
bcat_plt_hist(),
bcat_plt_line(),
bcat_plt_point(),
bcat_plt_ts()
library(ggplot2) library(dplyr) library(scales) # basic plot of frequencies bcat_plt_bar(df = mpg, x = toupper(class), order = TRUE, x_lab = NULL, y_lab = NULL, title = "Number of Vehicles by Class and Drive Type", legend_lab = "Drive Type") # can plot relative frequencies for each `x` by `fill` using `position = "fill"` bcat_plt_bar(df = mpg, x = toupper(class), fill = drv, position = "fill", x_lab = NULL, y_lab = NULL, y_scale = scale_y_continuous(labels = percent_format()), title = "Percent of Vehicle Class for Each Drive Type", legend_lab = "Drive Type") # use `stat` to compute and plot other statistics of interest bcat_plt_bar(mpg, x = toupper(class), y = hwy, fill = factor(year), stat = "mean", order = TRUE, position = "dodge", y_refline = round(mean(mpg$hwy), 2), coord_flip = TRUE, x_lab = NULL, y_lab = "Highway MPG", title = "Average Highway MPG by Vehicle Class", legend_lab = NULL) # use `stat = "identity"` to plot data directly from data set mpg %>% group_by(year, class) %>% summarise(hwy = mean(hwy)) %>% bcat_plt_bar(x = toupper(class), y = hwy, fill = factor(year), stat = "identity", order = TRUE, position = "dodge", y_refline = round(mean(mpg$hwy), 2), coord_flip = TRUE, x_lab = NULL, y_lab = "Highway MPG", title = "Average Highway MPG by Vehicle Class", legend_lab = NULL)library(ggplot2) library(dplyr) library(scales) # basic plot of frequencies bcat_plt_bar(df = mpg, x = toupper(class), order = TRUE, x_lab = NULL, y_lab = NULL, title = "Number of Vehicles by Class and Drive Type", legend_lab = "Drive Type") # can plot relative frequencies for each `x` by `fill` using `position = "fill"` bcat_plt_bar(df = mpg, x = toupper(class), fill = drv, position = "fill", x_lab = NULL, y_lab = NULL, y_scale = scale_y_continuous(labels = percent_format()), title = "Percent of Vehicle Class for Each Drive Type", legend_lab = "Drive Type") # use `stat` to compute and plot other statistics of interest bcat_plt_bar(mpg, x = toupper(class), y = hwy, fill = factor(year), stat = "mean", order = TRUE, position = "dodge", y_refline = round(mean(mpg$hwy), 2), coord_flip = TRUE, x_lab = NULL, y_lab = "Highway MPG", title = "Average Highway MPG by Vehicle Class", legend_lab = NULL) # use `stat = "identity"` to plot data directly from data set mpg %>% group_by(year, class) %>% summarise(hwy = mean(hwy)) %>% bcat_plt_bar(x = toupper(class), y = hwy, fill = factor(year), stat = "identity", order = TRUE, position = "dodge", y_refline = round(mean(mpg$hwy), 2), coord_flip = TRUE, x_lab = NULL, y_lab = "Highway MPG", title = "Average Highway MPG by Vehicle Class", legend_lab = NULL)
Create a box plot or violin plot with UC styling. Includes optional jittered point overlay and outlier highlighting.
bcat_plt_box( df, x, y, fill = NULL, facet = NULL, violin = FALSE, jitter = TRUE, jitter_width = 0.2, notch = FALSE, order = FALSE, coord_flip = FALSE, alpha = 0.3, x_lab = ggplot2::waiver(), y_lab = ggplot2::waiver(), title = ggplot2::waiver(), subtitle = ggplot2::waiver(), caption = ggplot2::waiver(), legend_lab = ggplot2::waiver(), legend_position = "bottom", legend_hide = FALSE, x_scale = NULL, y_scale = NULL, fill_scale = scale_fill_UC(), facet_scale = c("fixed", "free_y", "free_x", "free"), nrow = NULL, ncol = NULL, x_refline = NULL, y_refline = NULL )bcat_plt_box( df, x, y, fill = NULL, facet = NULL, violin = FALSE, jitter = TRUE, jitter_width = 0.2, notch = FALSE, order = FALSE, coord_flip = FALSE, alpha = 0.3, x_lab = ggplot2::waiver(), y_lab = ggplot2::waiver(), title = ggplot2::waiver(), subtitle = ggplot2::waiver(), caption = ggplot2::waiver(), legend_lab = ggplot2::waiver(), legend_position = "bottom", legend_hide = FALSE, x_scale = NULL, y_scale = NULL, fill_scale = scale_fill_UC(), facet_scale = c("fixed", "free_y", "free_x", "free"), nrow = NULL, ncol = NULL, x_refline = NULL, y_refline = NULL )
df |
The data to be displayed. |
x |
Categorical variable for the x-axis. |
y |
Numeric variable for the y-axis. |
fill |
Variable to map to fill aesthetic. If NULL, uses x for coloring. |
facet |
Facetting variable(s). Wrap in |
violin |
Logical. Use violin plot instead of box plot? Default is FALSE. |
jitter |
Logical. Overlay jittered points? Default is TRUE. |
jitter_width |
Jitter width. Default is 0.2. |
notch |
Logical. Add notches? Default is FALSE. |
order |
Logical. Reorder x by median of y? Default is FALSE. |
coord_flip |
Logical. Flip coordinates? Default is FALSE. |
alpha |
Point transparency. Default is 0.3. |
x_lab |
Label for x-axis. |
y_lab |
Label for y-axis. |
title |
Plot title. |
subtitle |
Plot subtitle. |
caption |
Plot caption. |
legend_lab |
Legend title. |
legend_position |
Legend position. |
legend_hide |
Logical. Hide legend? |
x_scale |
|
y_scale |
|
fill_scale |
|
facet_scale |
Facet scales. |
nrow |
Number of facet rows. |
ncol |
Number of facet columns. |
x_refline |
Vertical reference lines. |
y_refline |
Horizontal reference lines. |
A ggplot object.
Saannidhya Rawat
Other plots:
bcat_plt_area(),
bcat_plt_bar(),
bcat_plt_coef(),
bcat_plt_diag(),
bcat_plt_hist(),
bcat_plt_line(),
bcat_plt_point(),
bcat_plt_ts()
library(ggplot2) # Basic box plot bcat_plt_box(mtcars, x = factor(cyl), y = mpg) # Violin plot bcat_plt_box(mtcars, x = factor(cyl), y = mpg, violin = TRUE) # Ordered and flipped bcat_plt_box(mtcars, x = factor(cyl), y = mpg, order = TRUE, coord_flip = TRUE)library(ggplot2) # Basic box plot bcat_plt_box(mtcars, x = factor(cyl), y = mpg) # Violin plot bcat_plt_box(mtcars, x = factor(cyl), y = mpg, violin = TRUE) # Ordered and flipped bcat_plt_box(mtcars, x = factor(cyl), y = mpg, order = TRUE, coord_flip = TRUE)
Visualize regression coefficients and confidence intervals for one or more
models. Uses broom::tidy() to extract estimates.
bcat_plt_coef( models, conf_level = 0.95, intercept = FALSE, coef_rename = NULL, highlight = NULL, dodge_width = 0.4, x_lab = "Estimate", y_lab = ggplot2::waiver(), title = ggplot2::waiver(), subtitle = ggplot2::waiver(), caption = ggplot2::waiver(), legend_lab = "Model", legend_position = "bottom", legend_hide = FALSE, color_scale = scale_colour_UC() )bcat_plt_coef( models, conf_level = 0.95, intercept = FALSE, coef_rename = NULL, highlight = NULL, dodge_width = 0.4, x_lab = "Estimate", y_lab = ggplot2::waiver(), title = ggplot2::waiver(), subtitle = ggplot2::waiver(), caption = ggplot2::waiver(), legend_lab = "Model", legend_position = "bottom", legend_hide = FALSE, color_scale = scale_colour_UC() )
models |
A model object or a named list of model objects. |
conf_level |
Numeric. Confidence level. Default is 0.95. |
intercept |
Logical. Include intercept? Default is FALSE. |
coef_rename |
Named character vector to rename coefficients. If NULL (default), auto-cleans names to Title Case. |
highlight |
Character vector of term names to highlight in UC Red. |
dodge_width |
Numeric. Dodge width for multi-model comparison. Default is 0.4. |
x_lab |
Label for x-axis (coefficient values). |
y_lab |
Label for y-axis (term names). |
title |
Plot title. |
subtitle |
Plot subtitle. |
caption |
Plot caption. |
legend_lab |
Legend title. |
legend_position |
Legend position. |
legend_hide |
Logical. Hide legend? |
color_scale |
|
A ggplot object.
Saannidhya Rawat
Other plots:
bcat_plt_area(),
bcat_plt_bar(),
bcat_plt_box(),
bcat_plt_diag(),
bcat_plt_hist(),
bcat_plt_line(),
bcat_plt_point(),
bcat_plt_ts()
library(ggplot2) m <- lm(mpg ~ wt + hp + cyl, data = mtcars) bcat_plt_coef(m) m1 <- lm(mpg ~ wt + hp, data = mtcars) m2 <- lm(mpg ~ wt + hp + cyl + disp, data = mtcars) bcat_plt_coef(list("Base" = m1, "Full" = m2))library(ggplot2) m <- lm(mpg ~ wt + hp + cyl, data = mtcars) bcat_plt_coef(m) m1 <- lm(mpg ~ wt + hp, data = mtcars) m2 <- lm(mpg ~ wt + hp + cyl + disp, data = mtcars) bcat_plt_coef(list("Base" = m1, "Full" = m2))
Produce a multi-panel diagnostic plot for a fitted model with UC styling. Optionally prints assumption test results (Breusch-Pagan, Shapiro-Wilk, Durbin-Watson) to the console.
bcat_plt_diag( model, which = c(1, 2, 3, 4), labels = TRUE, n_labels = 3, tests = TRUE, nrow = NULL, ncol = NULL )bcat_plt_diag( model, which = c(1, 2, 3, 4), labels = TRUE, n_labels = 3, tests = TRUE, nrow = NULL, ncol = NULL )
model |
A fitted model object (e.g., |
which |
Integer vector specifying which panels to include:
1 = Residuals vs Fitted, 2 = Q-Q Plot, 3 = Scale-Location,
4 = Residuals vs Leverage. Default: |
labels |
Logical. Label influential observations? Default is TRUE. |
n_labels |
Integer. Number of extreme observations to label. Default is 3. |
tests |
Logical. Print assumption test results to console? Default is TRUE. |
nrow |
Number of panel rows. |
ncol |
Number of panel columns. |
A patchwork object combining the diagnostic panels.
Saannidhya Rawat
Other plots:
bcat_plt_area(),
bcat_plt_bar(),
bcat_plt_box(),
bcat_plt_coef(),
bcat_plt_hist(),
bcat_plt_line(),
bcat_plt_point(),
bcat_plt_ts()
m <- lm(mpg ~ wt + hp + cyl, data = mtcars) bcat_plt_diag(m) bcat_plt_diag(m, which = c(1, 2))m <- lm(mpg ~ wt + hp + cyl, data = mtcars) bcat_plt_diag(m) bcat_plt_diag(m, which = c(1, 2))
Create a histogram using ggplot2 graphics with UC styling. Includes optional density curve overlay and mean reference line.
bcat_plt_hist( df, x, bins = NULL, fill = palette_UC[["Steger Silver"]], facet = NULL, density = FALSE, mean_line = TRUE, rug = FALSE, x_lab = ggplot2::waiver(), y_lab = ggplot2::waiver(), title = ggplot2::waiver(), subtitle = ggplot2::waiver(), caption = ggplot2::waiver(), legend_position = "bottom", legend_hide = FALSE, x_scale = NULL, y_scale = NULL, facet_scale = c("fixed", "free_y", "free_x", "free"), nrow = NULL, ncol = NULL, x_refline = NULL, y_refline = NULL )bcat_plt_hist( df, x, bins = NULL, fill = palette_UC[["Steger Silver"]], facet = NULL, density = FALSE, mean_line = TRUE, rug = FALSE, x_lab = ggplot2::waiver(), y_lab = ggplot2::waiver(), title = ggplot2::waiver(), subtitle = ggplot2::waiver(), caption = ggplot2::waiver(), legend_position = "bottom", legend_hide = FALSE, x_scale = NULL, y_scale = NULL, facet_scale = c("fixed", "free_y", "free_x", "free"), nrow = NULL, ncol = NULL, x_refline = NULL, y_refline = NULL )
df |
The data to be displayed. |
x |
Variable to map to the x-axis. |
bins |
Number of bins. If NULL (default), uses ggplot2's automatic selection. |
fill |
Fill color for bars. Default is UC Steger Silver. |
facet |
Facetting variable(s). Wrap in |
density |
Logical. Overlay density curve? Default is FALSE. |
mean_line |
Logical. Draw dashed vertical line at mean? Default is TRUE. |
rug |
Logical. Add rug plot at bottom? Default is FALSE. |
x_lab |
Label for x-axis. |
y_lab |
Label for y-axis. |
title |
Plot title. |
subtitle |
Plot subtitle. |
caption |
Plot caption. |
legend_position |
Legend position: |
legend_hide |
Logical. Hide legend? |
x_scale |
|
y_scale |
|
facet_scale |
Facet scales: |
nrow |
Number of facet rows. |
ncol |
Number of facet columns. |
x_refline |
Vector of x-values for vertical reference lines. |
y_refline |
Vector of y-values for horizontal reference lines. |
A ggplot object.
Saannidhya Rawat
Other plots:
bcat_plt_area(),
bcat_plt_bar(),
bcat_plt_box(),
bcat_plt_coef(),
bcat_plt_diag(),
bcat_plt_line(),
bcat_plt_point(),
bcat_plt_ts()
library(ggplot2) # Basic histogram bcat_plt_hist(mtcars, x = mpg) # With density curve and mean line bcat_plt_hist(mtcars, x = mpg, density = TRUE, mean_line = TRUE) # Faceted by cylinders bcat_plt_hist(mtcars, x = mpg, facet = vars(cyl), facet_scale = "free_x")library(ggplot2) # Basic histogram bcat_plt_hist(mtcars, x = mpg) # With density curve and mean line bcat_plt_hist(mtcars, x = mpg, density = TRUE, mean_line = TRUE) # Faceted by cylinders bcat_plt_hist(mtcars, x = mpg, facet = vars(cyl), facet_scale = "free_x")
Create a line plot using ggplot2 graphics. This function is a wrapper to create commonly used styles of line plots. Additional layers can be added to this plot as needed. More complicated plots can be creating using individual ggplot2 layers.
bcat_plt_line( df, x, y, color = NULL, linetype = NULL, facet = NULL, x_lab = ggplot2::waiver(), y_lab = ggplot2::waiver(), title = ggplot2::waiver(), subtitle = ggplot2::waiver(), caption = ggplot2::waiver(), legend_lab = ggplot2::waiver(), legend_position = "bottom", legend_hide = FALSE, x_scale = NULL, y_scale = NULL, color_scale = Rbearcat::scale_colour_UC(), facet_scale = c("fixed", "free_y", "free_x", "free"), nrow = NULL, ncol = NULL, layer_points = FALSE, x_refline = NULL, y_refline = NULL, x_highlight_min = NULL, x_highlight_max = NULL, y_highlight_min = NULL, y_highlight_max = NULL, y_ribbon_min = NULL, y_ribbon_max = NULL, y_error_min = NULL, y_error_max = NULL, y_error_width = 1 )bcat_plt_line( df, x, y, color = NULL, linetype = NULL, facet = NULL, x_lab = ggplot2::waiver(), y_lab = ggplot2::waiver(), title = ggplot2::waiver(), subtitle = ggplot2::waiver(), caption = ggplot2::waiver(), legend_lab = ggplot2::waiver(), legend_position = "bottom", legend_hide = FALSE, x_scale = NULL, y_scale = NULL, color_scale = Rbearcat::scale_colour_UC(), facet_scale = c("fixed", "free_y", "free_x", "free"), nrow = NULL, ncol = NULL, layer_points = FALSE, x_refline = NULL, y_refline = NULL, x_highlight_min = NULL, x_highlight_max = NULL, y_highlight_min = NULL, y_highlight_max = NULL, y_ribbon_min = NULL, y_ribbon_max = NULL, y_error_min = NULL, y_error_max = NULL, y_error_width = 1 )
df |
The data to be displayed |
x |
Variable to map to the x-axis |
y |
Variable to map to the y-axis |
color |
Variable to map to the color aesthetic |
linetype |
Variable to map to the linetype aesthetic |
facet |
Facetting variable(s). Note: must wrap in |
x_lab |
Label for x-axis |
y_lab |
Label for y-axis |
title |
Plot title |
subtitle |
Plot subtitle |
caption |
Plot caption |
legend_lab |
Legend title |
legend_position |
legend position. "bottom" or "right" |
legend_hide |
Set to |
x_scale |
|
y_scale |
|
color_scale |
|
facet_scale |
Shoud facet scales be fixed ("fixed", the default), free ("free"), or free in one dimension ("free_x", "free_y")? |
nrow |
Number of facet rows |
ncol |
Number of facet columns |
layer_points |
Set to |
x_refline |
Vector of x-values at which to draw vertical reference lines |
y_refline |
Vector of y-values at which to draw horizontal reference lines |
x_highlight_min |
Vector of min x-values at which to start draw rectangle annotation |
x_highlight_max |
Vector of max x-values at which to end rectangle annotation |
y_highlight_min |
Vector of min y-values at which to start draw rectangle annotation |
y_highlight_max |
Vector of max y-values at which to end rectangle annotation |
y_ribbon_min |
Variable to use as minimum values for ribbon around y at each value of x |
y_ribbon_max |
Variable to use as maximum values for ribbon around y at each value of x |
y_error_min |
Variable to use as minimum values for error bars around y at each value of x |
y_error_max |
Variable to use as maximum values for error bars around y at each value of x |
y_error_width |
Width of error bars |
Saannidhya Rawat
Other plots:
bcat_plt_area(),
bcat_plt_bar(),
bcat_plt_box(),
bcat_plt_coef(),
bcat_plt_diag(),
bcat_plt_hist(),
bcat_plt_point(),
bcat_plt_ts()
library(ggplot2) library(scales) # basic time series plot with a reference line bcat_plt_line(df = economics, x = date, y = unemploy, y_scale = scale_y_continuous(labels = comma_format()), y_refline = 10000) # line plot with facets and highlight periods bcat_plt_line(df = economics_long, x = date, y = value, color = variable, facet = vars(variable), x_lab = "Decade", y_lab = "Value", legend_lab = NULL, facet_scale = "free_y", x_highlight_min = as.Date(c("2000-01-01", "2008-01-01")), x_highlight_max = as.Date(c("2002-01-01", "2010-01-01")), ncol = 1)library(ggplot2) library(scales) # basic time series plot with a reference line bcat_plt_line(df = economics, x = date, y = unemploy, y_scale = scale_y_continuous(labels = comma_format()), y_refline = 10000) # line plot with facets and highlight periods bcat_plt_line(df = economics_long, x = date, y = value, color = variable, facet = vars(variable), x_lab = "Decade", y_lab = "Value", legend_lab = NULL, facet_scale = "free_y", x_highlight_min = as.Date(c("2000-01-01", "2008-01-01")), x_highlight_max = as.Date(c("2002-01-01", "2010-01-01")), ncol = 1)
Create a scatter plot using ggplot2 graphics. This function is a wrapper to create commonly used styles of scatter plots. Additional layers can be added to this plot as needed. More complicated scatter plots can be creating using individual ggplot2 layers.
bcat_plt_point( df, x, y, color = NULL, size = NULL, facet = NULL, jitter = FALSE, jitter_width = NULL, smooth = FALSE, method = "lm", se = TRUE, x_lab = ggplot2::waiver(), y_lab = ggplot2::waiver(), title = ggplot2::waiver(), subtitle = ggplot2::waiver(), caption = ggplot2::waiver(), legend_lab = ggplot2::waiver(), legend_position = "bottom", legend_hide = FALSE, x_scale = NULL, y_scale = NULL, color_scale = Rbearcat::scale_colour_UC(), fill_scale = Rbearcat::scale_fill_UC(), facet_scale = c("fixed", "free_y", "free_x", "free"), alpha = 0.6, nrow = NULL, ncol = NULL, x_refline = NULL, y_refline = NULL, identity_line = FALSE, x_highlight_min = NULL, x_highlight_max = NULL, y_highlight_min = NULL, y_highlight_max = NULL, y_error_min = NULL, y_error_max = NULL, y_error_width = 1 )bcat_plt_point( df, x, y, color = NULL, size = NULL, facet = NULL, jitter = FALSE, jitter_width = NULL, smooth = FALSE, method = "lm", se = TRUE, x_lab = ggplot2::waiver(), y_lab = ggplot2::waiver(), title = ggplot2::waiver(), subtitle = ggplot2::waiver(), caption = ggplot2::waiver(), legend_lab = ggplot2::waiver(), legend_position = "bottom", legend_hide = FALSE, x_scale = NULL, y_scale = NULL, color_scale = Rbearcat::scale_colour_UC(), fill_scale = Rbearcat::scale_fill_UC(), facet_scale = c("fixed", "free_y", "free_x", "free"), alpha = 0.6, nrow = NULL, ncol = NULL, x_refline = NULL, y_refline = NULL, identity_line = FALSE, x_highlight_min = NULL, x_highlight_max = NULL, y_highlight_min = NULL, y_highlight_max = NULL, y_error_min = NULL, y_error_max = NULL, y_error_width = 1 )
df |
The data to be displayed |
x |
Variable to map to the x-axis |
y |
Variable to map to the y-axis |
color |
Variable to map to the color aesthetic |
size |
Variable to map to the size aesthetic |
facet |
Facetting variable(s). Note: must wrap in |
jitter |
Set to |
jitter_width |
Set the jitter width. Leave as |
smooth |
Add fit line to plot |
method |
Method to use for fit line. "lm" is default |
se |
Set to |
x_lab |
Label for x-axis |
y_lab |
Label for y-axis |
title |
Plot title |
subtitle |
Plot subtitle |
caption |
Plot caption |
legend_lab |
Legend title |
legend_position |
legend position. "bottom" or "right" |
legend_hide |
Set to |
x_scale |
|
y_scale |
|
color_scale |
|
fill_scale |
|
facet_scale |
Shoud facet scales be fixed ("fixed", the default), free ("free"), or free in one dimension ("free_x", "free_y")? |
alpha |
level of point transparency. lower alpha leads to more transparency. |
nrow |
Number of facet rows |
ncol |
Number of facet columns |
x_refline |
Vector of x-values at which to draw vertical reference lines |
y_refline |
Vector of y-values at which to draw horizontal reference lines |
identity_line |
Set to |
x_highlight_min |
Vector of min x-values at which to start draw rectangle annotation |
x_highlight_max |
Vector of max x-values at which to end rectangle annotation |
y_highlight_min |
Vector of min y-values at which to start draw rectangle annotation |
y_highlight_max |
Vector of max y-values at which to end rectangle annotation |
y_error_min |
Variable to use as minimum values for error bars around y at each value of x |
y_error_max |
Variable to use as maximum values for error bars around y at each value of x |
y_error_width |
Width of error bars |
Saannidhya Rawat
Other plots:
bcat_plt_area(),
bcat_plt_bar(),
bcat_plt_box(),
bcat_plt_coef(),
bcat_plt_diag(),
bcat_plt_hist(),
bcat_plt_line(),
bcat_plt_ts()
library(ggplot2) # basic scatter plot bcat_plt_point(df = iris, x = Sepal.Length, y = Sepal.Width, x_lab = "Length", y_lab = "Width", title = "Sepal Width vs Length") # scatter plot with LOESS fit line bcat_plt_point(df = iris, x = Sepal.Length, y = Sepal.Width, x_lab = "Length", y_lab = "Width", smooth = TRUE, method = "loess", title = "Sepal Width vs Length", subtitle = "Loess Fit") # scatter plot with faceting and LM fit lines bcat_plt_point(df = iris, x = Sepal.Length, y = Sepal.Width, color = Species, facet = vars(Species), smooth = TRUE, x_lab = "Length", y_lab = "Width", legend_lab = NULL, title = "Sepal Width vs Length by Species", subtitle = "Linear Fit", nrow = 1)library(ggplot2) # basic scatter plot bcat_plt_point(df = iris, x = Sepal.Length, y = Sepal.Width, x_lab = "Length", y_lab = "Width", title = "Sepal Width vs Length") # scatter plot with LOESS fit line bcat_plt_point(df = iris, x = Sepal.Length, y = Sepal.Width, x_lab = "Length", y_lab = "Width", smooth = TRUE, method = "loess", title = "Sepal Width vs Length", subtitle = "Loess Fit") # scatter plot with faceting and LM fit lines bcat_plt_point(df = iris, x = Sepal.Length, y = Sepal.Width, color = Species, facet = vars(Species), smooth = TRUE, x_lab = "Length", y_lab = "Width", legend_lab = NULL, title = "Sepal Width vs Length by Species", subtitle = "Linear Fit", nrow = 1)
Create a time series visualization with UC styling. Supports decomposition into trend/seasonal/remainder, ACF/PACF display, and recession shading.
bcat_plt_ts( df, x = NULL, y = NULL, color = NULL, decompose = FALSE, acf = FALSE, recession_bars = NULL, x_lab = ggplot2::waiver(), y_lab = ggplot2::waiver(), title = ggplot2::waiver(), subtitle = ggplot2::waiver(), caption = ggplot2::waiver(), legend_lab = ggplot2::waiver(), legend_position = "bottom", legend_hide = FALSE, x_scale = NULL, y_scale = NULL, color_scale = scale_colour_UC(), layer_points = FALSE, x_highlight_min = NULL, x_highlight_max = NULL, y_refline = NULL )bcat_plt_ts( df, x = NULL, y = NULL, color = NULL, decompose = FALSE, acf = FALSE, recession_bars = NULL, x_lab = ggplot2::waiver(), y_lab = ggplot2::waiver(), title = ggplot2::waiver(), subtitle = ggplot2::waiver(), caption = ggplot2::waiver(), legend_lab = ggplot2::waiver(), legend_position = "bottom", legend_hide = FALSE, x_scale = NULL, y_scale = NULL, color_scale = scale_colour_UC(), layer_points = FALSE, x_highlight_min = NULL, x_highlight_max = NULL, y_refline = NULL )
df |
A data frame with date and value columns. |
x |
Date column. |
y |
Value column. |
color |
Variable for color aesthetic. |
decompose |
Logical. Show 4-panel decomposition? Default is FALSE. |
acf |
Logical. Show ACF/PACF side-by-side? Default is FALSE. |
recession_bars |
Data frame with |
x_lab |
Label for x-axis. |
y_lab |
Label for y-axis. |
title |
Plot title. |
subtitle |
Plot subtitle. |
caption |
Plot caption. |
legend_lab |
Legend title. |
legend_position |
Legend position. |
legend_hide |
Logical. Hide legend? |
x_scale |
|
y_scale |
|
color_scale |
|
layer_points |
Logical. Show points on line? Default is FALSE. |
x_highlight_min |
Date(s) at which to start highlight region(s). |
x_highlight_max |
Date(s) at which to end highlight region(s). |
y_refline |
Horizontal reference line(s). |
A ggplot or patchwork object.
Saannidhya Rawat
Other plots:
bcat_plt_area(),
bcat_plt_bar(),
bcat_plt_box(),
bcat_plt_coef(),
bcat_plt_diag(),
bcat_plt_hist(),
bcat_plt_line(),
bcat_plt_point()
library(ggplot2) library(scales) bcat_plt_ts(economics, x = date, y = unemploy, y_scale = scale_y_continuous(labels = comma_format()))library(ggplot2) library(scales) bcat_plt_ts(economics, x = date, y = unemploy, y_scale = scale_y_continuous(labels = comma_format()))
Produce publication-quality regression tables with UC styling.
Wraps modelsummary::modelsummary() with UC defaults for
formatting, colors, and statistical conventions.
bcat_reg_table( models, stars = c(`*` = 0.1, `**` = 0.05, `***` = 0.01), se_type = "default", coef_rename = NULL, gof_map = c("nobs", "r.squared", "adj.r.squared", "statistic"), caption = NULL, footer = NULL, font_size = 12, header_bg_color = palette_UC[["UC Red"]], header_txt_color = palette_UC[["White"]], striped = TRUE, doc_type = NULL, ... )bcat_reg_table( models, stars = c(`*` = 0.1, `**` = 0.05, `***` = 0.01), se_type = "default", coef_rename = NULL, gof_map = c("nobs", "r.squared", "adj.r.squared", "statistic"), caption = NULL, footer = NULL, font_size = 12, header_bg_color = palette_UC[["UC Red"]], header_txt_color = palette_UC[["White"]], striped = TRUE, doc_type = NULL, ... )
models |
A model object, or a list of model objects. Supports |
stars |
Named numeric vector for significance stars. Set to |
se_type |
Character. Standard error type passed to |
coef_rename |
Named character vector to rename coefficients.
If |
gof_map |
Character vector of goodness-of-fit statistics to include.
Default: |
caption |
Character. Table caption. |
footer |
Character. Table footnote. |
font_size |
Numeric. Font size. Default is 12. |
header_bg_color |
Background color for header. Default is UC Red. |
header_txt_color |
Text color for header. Default is white. |
striped |
Logical. Zebra striping? Default is TRUE. |
doc_type |
Character. Force output format. Auto-detected if NULL. |
... |
Additional arguments passed to |
A formatted table object.
Saannidhya Rawat
Other tables:
bcat_cor_table(),
bcat_fmt_style_table(),
bcat_sum_table()
# Single model m1 <- lm(mpg ~ wt + hp, data = mtcars) bcat_reg_table(m1) # Compare models side-by-side m2 <- lm(mpg ~ wt + hp + cyl, data = mtcars) bcat_reg_table(list("Base" = m1, "Extended" = m2))# Single model m1 <- lm(mpg ~ wt + hp, data = mtcars) bcat_reg_table(m1) # Compare models side-by-side m2 <- lm(mpg ~ wt + hp + cyl, data = mtcars) bcat_reg_table(list("Base" = m1, "Extended" = m2))
Sets default code chunk options and configures options for kable tables. Call at the start of Rmd file in "setup" chunk.
bcat_setup_rmd()bcat_setup_rmd()
Saannidhya Rawat
Other utilities:
bcat_extract_metadata(),
bcat_import_data(),
bcat_new_quarto(),
bcat_source_rmd()
## Not run: # Call in your Rmd setup chunk: bcat_setup_rmd() ## End(Not run)## Not run: # Call in your Rmd setup chunk: bcat_setup_rmd() ## End(Not run)
Utility function to run all code chunks in an Rmd file.
bcat_source_rmd(rmd)bcat_source_rmd(rmd)
rmd |
character. Rmd file from which to run all code chunks. |
Saannidhya Rawat
https://stackoverflow.com/questions/10966109/how-to-source-r-markdown-file-like-sourcemyfile-r
Other utilities:
bcat_extract_metadata(),
bcat_import_data(),
bcat_new_quarto(),
bcat_setup_rmd()
Produce a descriptive statistics table with UC styling. Displays mean, SD, min, median, max, N, and percent missing for numeric columns.
bcat_sum_table( df, by = NULL, stats = c("mean", "sd", "min", "median", "max", "n", "pct_missing"), digits = 2, caption = NULL, footer = NULL, font_size = 12, header_bg_color = palette_UC[["UC Red"]], header_txt_color = palette_UC[["White"]], striped = TRUE, doc_type = NULL, ... )bcat_sum_table( df, by = NULL, stats = c("mean", "sd", "min", "median", "max", "n", "pct_missing"), digits = 2, caption = NULL, footer = NULL, font_size = 12, header_bg_color = palette_UC[["UC Red"]], header_txt_color = palette_UC[["White"]], striped = TRUE, doc_type = NULL, ... )
df |
A data frame, tibble, or data.table. |
by |
Character. Column name for grouped summaries. Default is NULL. |
stats |
Character vector of statistics to compute. Default includes all. |
digits |
Integer. Number of decimal places. Default is 2. |
caption |
Character. Table caption. |
footer |
Character. Table footnote. |
font_size |
Numeric. Font size. Default is 12. |
header_bg_color |
Background color for header. Default is UC Red. |
header_txt_color |
Text color for header. Default is white. |
striped |
Logical. Zebra striping? Default is TRUE. |
doc_type |
Character. Force output format. Auto-detected if NULL. |
... |
Additional arguments passed to table formatting. |
A formatted table object.
Saannidhya Rawat
Other tables:
bcat_cor_table(),
bcat_fmt_style_table(),
bcat_reg_table()
bcat_sum_table(mtcars[, c("mpg", "wt", "hp")]) bcat_sum_table(mtcars[, c("mpg", "wt", "cyl")], by = "cyl")bcat_sum_table(mtcars[, c("mpg", "wt", "hp")]) bcat_sum_table(mtcars[, c("mpg", "wt", "cyl")], by = "cyl")
An R Markdown output format for remark.js slides (HTML).
bcat_xaringan(css = NULL, after_body = NULL, ...)bcat_xaringan(css = NULL, after_body = NULL, ...)
css |
A vector of CSS file paths.
If |
after_body |
relative path to HTML document to include after body of each slide.
If |
... |
arguments passed to |
Saannidhya Rawat
Two color palettes taken from the article "Color Universal Design" by
Okabe and Ito.
The variant palette_OkabeIto contains a gray color, while palette_OkabeIto_black contains black instead.
palette_OkabeIto_light contains a lightened version of the palette_OkabeIto colors.
Note: To extract hex colors, convert palette using as.vector.
palette_OkabeIto palette_OkabeIto_black palette_OkabeIto_lightpalette_OkabeIto palette_OkabeIto_black palette_OkabeIto_light
An object of class character of length 8.
An object of class character of length 8.
An object of class character of length 8.
Other palettes:
palette_UC,
scale_OkabeIto(),
scale_UC()
Official University of Cincinnati brand colors.
palette_UCpalette_UC
An object of class character of length 17.
The palette combines the current primary colors from UC's visual identity
system with the expanded palette recommended for data visualization.
Canonical brand names are included alongside a small set of legacy aliases
used by earlier versions of this package.
Note: To extract hex colors, convert palette using as.vector.
Other palettes:
palette_OkabeIto,
scale_OkabeIto(),
scale_UC()
This is a color-blind friendly, qualitative scale with eight different colors from the colorblindr package (https://github.com/clauswilke/colorblindr).
use_black |
If |
order |
Numeric vector listing the order in which the colors should be used. Default is 1:8. |
darken |
Relative amount by which the scale should be darkened (for positive values) or lightened (for negative values). |
alpha |
Alpha transparency level of the color. Default is no transparency. |
... |
common discrete scale parameters: |
Other palettes:
palette_OkabeIto,
palette_UC,
scale_UC()
library(ggplot2) ggplot(iris, aes(Sepal.Length, Sepal.Width, color = Species)) + geom_point() + scale_color_OkabeIto() ggplot(iris, aes(Sepal.Length, fill = Species)) + geom_density(alpha = 0.7) + scale_fill_OkabeIto(order = c(1, 3, 5))library(ggplot2) ggplot(iris, aes(Sepal.Length, Sepal.Width, color = Species)) + geom_point() + scale_color_OkabeIto() ggplot(iris, aes(Sepal.Length, fill = Species)) + geom_density(alpha = 0.7) + scale_fill_OkabeIto(order = c(1, 3, 5))
Apply the official University of Cincinnati expanded palette to ggplot graphics. The default ordering prioritizes the primary UC colors, followed by expanded brand accents intended for data visualization.
order |
Numeric vector listing the order in which the colors should be used. |
darken |
Relative amount by which the scale should be darkened (for positive values) or lightened (for negative values). |
alpha |
Alpha transparency level of the color. Default is no transparency. |
... |
common discrete scale parameters: |
Other palettes:
palette_OkabeIto,
palette_UC,
scale_OkabeIto()
library(ggplot2) ggplot(iris, aes(Sepal.Length, Sepal.Width, color = Species)) + geom_point() + scale_color_UC() ggplot(iris, aes(Sepal.Length, fill = Species)) + geom_density(alpha = 0.7) + scale_fill_UC()library(ggplot2) ggplot(iris, aes(Sepal.Length, Sepal.Width, color = Species)) + geom_point() + scale_color_UC() ggplot(iris, aes(Sepal.Length, fill = Species)) + geom_density(alpha = 0.7) + scale_fill_UC()
Wrapper for ggplot2::scale_x_date that generates labels for data variable on x-axis based on input data.
scale_x_dt( df, x, break_by = "year", round_unit = "year", labels = scales::date_format("'%y"), ... )scale_x_dt( df, x, break_by = "year", round_unit = "year", labels = scales::date_format("'%y"), ... )
df |
data set used for plotting |
x |
date variable mapped to x-axis |
break_by |
a character string specifying a time unit to use for axis breaks |
round_unit |
a character string specifying a time unit or a multiple of a unit to be rounded to for the axis breaks.
Valid base units are |
labels |
format to use for displaying labels |
... |
additional arguments passed to |
Saannidhya Rawat
library(ggplot2) # use default ggplot2 scale bcat_plt_line(df = economics, x = date, y = unemploy, y_ref = 10000) # use scale_x_dt to break by every 5 years bcat_plt_line(df = economics, x = date, y = unemploy, y_ref = 10000, x_scale = scale_x_dt(economics, date, round_unit = "5 years"))library(ggplot2) # use default ggplot2 scale bcat_plt_line(df = economics, x = date, y = unemploy, y_ref = 10000) # use scale_x_dt to break by every 5 years bcat_plt_line(df = economics, x = date, y = unemploy, y_ref = 10000, x_scale = scale_x_dt(economics, date, round_unit = "5 years"))
Apply UC default colors to ggplot2 geoms. Note: only applies during session.
set_UC_geoms()set_UC_geoms()
Saannidhya Rawat
These functions allow you to add University of Cincinnati themes to ggplot graphics using the official UC color system and digital typography fallbacks.
theme_UC( border = TRUE, legend_position = c("bottom", "right"), legend_hide = FALSE ) theme_UC_hgrid(border = FALSE, ...) theme_UC_vgrid(border = FALSE, ...) theme_UC_nogrid(border = FALSE, ...)theme_UC( border = TRUE, legend_position = c("bottom", "right"), legend_hide = FALSE ) theme_UC_hgrid(border = FALSE, ...) theme_UC_vgrid(border = FALSE, ...) theme_UC_nogrid(border = FALSE, ...)
border |
If |
legend_position |
legend position. "bottom" or "right" |
legend_hide |
If |
... |
Additional arguments passed into |
The main theme is theme_UC, while theme_UC_hgrid and
theme_UC_vgrid are used for plots that benefit from a single grid
direction. theme_UC_nogrid removes all gridlines.
Saannidhya Rawat
library(ggplot2) p <- ggplot( data = iris, mapping = aes(x = Petal.Width, y = Petal.Length, color = Species) ) + geom_jitter(size = 1.5) + labs( x = "Petal Width", y = "Petal Length", title = "Iris Example", subtitle = "Width vs Length by Species", caption = "Note: This is a caption" ) + facet_wrap(~Species) p + theme_UC() p + theme_UC_hgrid() p + theme_UC_vgrid()library(ggplot2) p <- ggplot( data = iris, mapping = aes(x = Petal.Width, y = Petal.Length, color = Species) ) + geom_jitter(size = 1.5) + labs( x = "Petal Width", y = "Petal Length", title = "Iris Example", subtitle = "Width vs Length by Species", caption = "Note: This is a caption" ) + facet_wrap(~Species) p + theme_UC() p + theme_UC_hgrid() p + theme_UC_vgrid()
An R Markdown output format for HTML documents.
UC_html_document( number_sections = FALSE, toc = TRUE, toc_depth = 2, css = NULL, ... )UC_html_document( number_sections = FALSE, toc = TRUE, toc_depth = 2, css = NULL, ... )
number_sections |
logical. Set to |
toc |
logical. set to |
toc_depth |
number of layers in TOC. |
css |
relative path to a css formatting document.
If |
... |
other options passed to |
Saannidhya Rawat
An R Markdown output format for PDF documents.
UC_pdf_document( number_sections = FALSE, toc = FALSE, toc_depth = 2, highlight_bw = FALSE, in_header = NULL, ... )UC_pdf_document( number_sections = FALSE, toc = FALSE, toc_depth = 2, highlight_bw = FALSE, in_header = NULL, ... )
number_sections |
logical. Set to |
toc |
logical. set to |
toc_depth |
number of layers in TOC. |
highlight_bw |
set to |
in_header |
relative path to a tex formatting document included in the preamble.
If |
... |
other options passed to |
Saannidhya Rawat
An R Markdown output format for Word documents (docx).
UC_word_document(toc = FALSE, toc_depth = 2, reference_docx = NULL, ...)UC_word_document(toc = FALSE, toc_depth = 2, reference_docx = NULL, ...)
toc |
logical. set to |
toc_depth |
number of layers in TOC. |
reference_docx |
relative path to a docx reference document.
If |
... |
other options passed to |
Saannidhya Rawat
Check if git repo has uncommitted changes
util_git_check_uncommitted(path = ".", dir_ignore = "docs/")util_git_check_uncommitted(path = ".", dir_ignore = "docs/")
path |
the path to the directory to check. |
dir_ignore |
name of subdirectory to skip over for uncommitted files. should generally be the output directory for rmarkdown rendered files (e.g., "docs/" for bookdown projects.) |
Saannidhya Rawat
Get git commit ID
util_git_commit_id(path = ".")util_git_commit_id(path = ".")
path |
the path to the directory |
Saannidhya Rawat