| Title: | Personal Themes and Formatting Preferences |
|---|---|
| Description: | A collection of utility functions, themes, and templates to support personal data analysis workflows. Includes functions for formatting numeric values as text, custom themes and color scales for 'ggplot2', and automatic formatting for tables created with 'gt'. |
| Authors: | W. Jake Thompson [aut, cre, cph] (ORCID: <https://orcid.org/0000-0001-7339-0300>) |
| Maintainer: | W. Jake Thompson <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.1.0 |
| Built: | 2026-05-21 11:14:43 UTC |
| Source: | https://github.com/wjakethompson/wjake |
Create an announcement adjective
announce()announce()
A character string
announce()announce()
Confused about whether a number should be written out ("five") or use numerals ("5")? Use this function! Most useful for R Markdown in-text writing.
apa_words(x, ordinal = FALSE, negative = "negative")apa_words(x, ordinal = FALSE, negative = "negative")
x |
The number to be printed |
ordinal |
Do you want the ordinal numbering (e.g., 1st, 6th, etc.) |
negative |
The word used to indicate a negative number. |
A character string
Other formatters:
formatting
apa_words(5) apa_words(16) apa_words(6, ordinal = TRUE)apa_words(5) apa_words(16) apa_words(6, ordinal = TRUE)
Insert some hyphens padded to a specified console character width.
code_heading(width = 80)code_heading(width = 80)
width |
The width of console the hyphens should pad to |
A character string consisting of a ' ' and hyphens that fill to the
specified width.
code_heading()code_heading()
These color ramp functions create color scales that can be used for making ggplot2 plots and gt tables. Color ramps are based on the palette_wjake color palette.
make_color_pal(colors, bias = 1) ramp_blue(output, end = "#FFFFFF") ramp_yellow(output, end = "#FFFFFF") ramp_yelblu(output, mid = "#F0F0F0") ramp_orgblu(output, mid = "#999999")make_color_pal(colors, bias = 1) ramp_blue(output, end = "#FFFFFF") ramp_yellow(output, end = "#FFFFFF") ramp_yelblu(output, mid = "#F0F0F0") ramp_orgblu(output, mid = "#999999")
colors |
colors to interpolate; must be a valid argument to
|
bias |
a positive number. Higher values give more widely spaced colors at the high end. |
output |
Colors to pull from the color ramp. Numbers range from 0-1, which is a normalized sliding scale of the color ramp. |
end |
The end color that the base color should fade into. |
mid |
For pre-made diverging palettes, the color of the midpoint of the scale. |
make_color_pal() can be used to create a color ramp function for any set of
valid colors.
ramp_blue(), ramp_yellow(), and ramp_yelblu() are pre-made color ramps
based on the blue and yellow colors from the palette_wjake color palette.
ramp_orgblu() is a pre-made color ramp based on the first two colors from
the palette_okabeito color palette.
make_color_pal() returns a function that accepts a numeric vector
of values between 0 and 1 and returns a character vector of hex color
codes. ramp_blue(), ramp_yellow(), ramp_yelblu(), and ramp_orgblu()
return a character vector of hex color codes.
new_ramp <- make_color_pal(c("red", "grey", "blue")) new_ramp(seq(0, 1, length.out = 10)) # Pre-made palettes ramp_blue(seq(0, 1, by = 0.2)) ramp_yellow(seq(0.2, 1, length.out = 5))new_ramp <- make_color_pal(c("red", "grey", "blue")) new_ramp(seq(0, 1, length.out = 10)) # Pre-made palettes ramp_blue(seq(0, 1, by = 0.2)) ramp_yellow(seq(0.2, 1, length.out = 5))
These formatting functions are used to format numerical values in a consistent manner. This is useful for printing numbers inline with text, as well as for formatting tables.
fmt_digits( x, digits = 1, big_mark = ",", min_value = -Inf, max_value = Inf, sub_threshold = 1/(10^digits), keep_boundary = FALSE, ... ) fmt_count(x, ...) fmt_corr(x, digits = 3, ...) fmt_prop(x, digits = 2, ...) fmt_pct(x, digits = 0, ...) fmt_prop_pct(x, digits = 0, ...)fmt_digits( x, digits = 1, big_mark = ",", min_value = -Inf, max_value = Inf, sub_threshold = 1/(10^digits), keep_boundary = FALSE, ... ) fmt_count(x, ...) fmt_corr(x, digits = 3, ...) fmt_prop(x, digits = 2, ...) fmt_pct(x, digits = 0, ...) fmt_prop_pct(x, digits = 0, ...)
x |
Number to be formatted. |
digits |
Number of decimal places to retain. |
big_mark |
Character used between every 3 digits to separate thousands. |
min_value |
The minimum value |
max_value |
The maximum value |
sub_threshold |
The threshold to use when replacing value extremely
close to |
keep_boundary |
Whether to preserve true values of boundaries (i.e.,
|
... |
Additional arguments passed to |
fmt_digits() is a wrapper for scales::number_format() and prints a number
with the specified number of digits, suppressing values close to the minimum
and maximum values as necessary.
Several helper functions are provided that wrap fmt_digits() with common
patterns of min_value, max_value, and digits.
fmt_count() is used for formatting integer values. Prints whole numbers
with no decimals.
fmt_corr() is used to format correlations or similar indices that are
bounded between [-1, 1]. By default, these values report 3 decimal
places, and the leading 0 is removed as required by APA (2020; section
6.36).
fmt_prop() is used to format proportions or similar indices that are
bounded between [0, 1]. Similar to fmt_corr(), leading 0s are removed.
By default, 2 decimal places are reported.
fmt_pct() is used to format percentage values that are bounded
[0, 100]. By default, no decimal places are reported.
fmt_prop_pct() formats proportions bounded by [0, 1] as percentages.
That is, we first take x * 100 and then apply fmt_pct().
The updated character object of the same length as x.
American Psychological Association. (2020). Publication manual of the American Psychological Association (7th ed.). doi:10.1037/0000165-000
Other formatters:
apa_words()
fmt_digits(runif(5, min = 5, max = 15), digits = 1) fmt_digits(runif(5, min = 5, max = 15), digits = 3) fmt_count(sample(10000:99999, size = 5)) fmt_corr(runif(5, min = -1, max = 1)) fmt_prop(runif(5, min = 0, max = 1)) fmt_pct(runif(5, min = 0, max = 100)) fmt_prop_pct(runif(5, min = 0, max = 1))fmt_digits(runif(5, min = 5, max = 15), digits = 1) fmt_digits(runif(5, min = 5, max = 15), digits = 3) fmt_count(sample(10000:99999, size = 5)) fmt_corr(runif(5, min = -1, max = 1)) fmt_prop(runif(5, min = 0, max = 1)) fmt_pct(runif(5, min = 0, max = 100)) fmt_prop_pct(runif(5, min = 0, max = 1))
Title
gt_theme_apa( data, dec_dig = 1, corr_dig = 3, fmt_extreme = TRUE, bg_color = "#FFFFFF", font = "Arial", font_size = 11, ... )gt_theme_apa( data, dec_dig = 1, corr_dig = 3, fmt_extreme = TRUE, bg_color = "#FFFFFF", font = "Arial", font_size = 11, ... )
data |
The gt table data object. |
dec_dig |
The number of decimal places to round to for numeric values. |
corr_dig |
The number of decimal places to round to for numeric values all constrained to be between [-1, 1]. |
fmt_extreme |
Logical indicator for whether values close to extremes should be suppressed (e.g., .000001 becomes <.001). |
bg_color |
The background color of the table. |
font |
The font to use for the table. |
font_size |
The base font size for the table. |
... |
Additional options passed to |
An object of class gt-tbl.
gt::gt(head(penguins)) |> gt_theme_apa() |> gt::fmt_number(year, sep_mark = "", decimals = 0)gt::gt(head(penguins)) |> gt_theme_apa() |> gt::fmt_number(year, sep_mark = "", decimals = 0)
A custom theme for tables generated with gt::gt().
gt_theme_wjake(data, bg_color = "#F0F0F0", font_size = 16, ...)gt_theme_wjake(data, bg_color = "#F0F0F0", font_size = 16, ...)
data |
The gt table data object. |
bg_color |
The background color of the table. |
font_size |
The base font size for the table. |
... |
Additional arguments passed to |
An object of class gt_tbl.
gt::gt(head(penguins)) |> gt_theme_wjake()gt::gt(head(penguins)) |> gt_theme_wjake()
Colorblind friendly palette taken originally described by Okabe and Ito
(2008). The original palette has been modified slightly to make the yellow
more visible on a white background, as described by Lüdecke et al. (2021).
The palette also includes color scales that can be used in place of
ggplot2::scale_color_discrete() or ggplot2::scale_fill_discrete().
palette_okabeitopalette_okabeito
A character vector of 8 hex color codes.
Lüdecke, D., Patil, I., Ben-Shachar, M. S., Wiernik, B. M., Waggoner, P., & Makowski, D. (2021). see: An R package for visualizing statistical models. Journal of Open Source Software, 6(64), Article 3393. doi:10.21105/joss.03393
Okabe, M., & Ito, K. (2008). Color universal design (CUD): How to make figures and presentations that are friendly to colorblind people. https://jfly.uni-koeln.de/color/#pallet (Original work published 2002)
scales::show_col(palette_okabeito)scales::show_col(palette_okabeito)
Color palette used for theming https://wjakethompson.com. The palette also
includes color scales that can be used in place of
ggplot2::scale_color_discrete() or ggplot2::scale_fill_discrete().
palette_wjakepalette_wjake
A character vector of 5 hex color codes.
scales::show_col(palette_wjake)scales::show_col(palette_wjake)
Round to a specified value
round_to(x, accuracy, direction = c("nearest", "up", "down", "random"))round_to(x, accuracy, direction = c("nearest", "up", "down", "random"))
x |
A numeric value to round. |
accuracy |
The accuracy with which to round (i.e., round to the nearest
|
direction |
The direction to round. |
A numeric rounded to the specified accuracy.
Matthews, G., & Harel, O. (2011). Data confidentiality: A review of methods for statistical disclosure limitation and methods for assessing privacy. Statistics Surveys, 5, 1–29. doi:10.1214/11-SS074
round_to(15, accuracy = 7, direction = "nearest") round_to(15, accuracy = 7, direction = "up") round_to(20, accuracy = 7, direction = "down")round_to(15, accuracy = 7, direction = "nearest") round_to(15, accuracy = 7, direction = "up") round_to(20, accuracy = 7, direction = "down")
This is a qualitative scale using the color palette used for https://wjakethompson.com. See palette_wjake for details.
palette |
A character vector of the color palette to use in the scale (e.g., palette_wjake, palette_okabeito). |
order |
Numeric vector listing the order in which the colors should be used. Default is the order of the palette vector. |
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: |
A ScaleDiscrete object that can be added to a ggplot2::ggplot().
library(ggplot2) ggplot(penguins, aes(x = bill_len, y = flipper_len, color = species)) + geom_point() + scale_color_wjake() ggplot(penguins, aes(bill_len, fill = species)) + geom_density(alpha = 0.7) + scale_fill_okabeito(order = c(1, 2, 5))library(ggplot2) ggplot(penguins, aes(x = bill_len, y = flipper_len, color = species)) + geom_point() + scale_color_wjake() ggplot(penguins, aes(bill_len, fill = species)) + geom_density(alpha = 0.7) + scale_fill_okabeito(order = c(1, 2, 5))
Based on ggplot2::theme_minimal().
theme_wjake( base_size = 11.5, base_family = "Source Sans Pro", header_family = NULL, base_line_size = base_size/22, base_rect_size = base_size/22, ink = "black", paper = "white", accent = "#FED766", continuous = ramp_blue(c(0.1, 1), end = "#FFFFFF"), discrete = palette_wjake, transparent = FALSE, ... )theme_wjake( base_size = 11.5, base_family = "Source Sans Pro", header_family = NULL, base_line_size = base_size/22, base_rect_size = base_size/22, ink = "black", paper = "white", accent = "#FED766", continuous = ramp_blue(c(0.1, 1), end = "#FFFFFF"), discrete = palette_wjake, transparent = FALSE, ... )
base_size |
base font size, given in pts. |
base_family |
base font family |
header_family |
font family for titles and headers. The default, |
base_line_size |
base size for line elements |
base_rect_size |
base size for rect elements |
ink, paper, accent
|
colour for foreground, background, and accented elements respectively. |
continuous |
A character vector of valid colors that will be interpolated into a continuous color scale. |
discrete |
A character vector of colors to use for discrete color scales. |
transparent |
Logical indicator for whether the background of the plot should be transparent. |
... |
Additional parameters passed to |
A theme object that can be added to a ggplot2::ggplot().
## Not run: library(ggplot2) ggplot(penguins, aes(x = bill_len, y = flipper_len)) + geom_point(aes(color = species), na.rm = TRUE) + labs( x = "Bill length (mm)", y = "Flipper length (mm)", title = "Seminal ggplot2 scatterplot example", subtitle = "A plot that is only useful for demonstration purposes", caption = "Brought to you by the letter *p*", color = "Species" ) + theme_wjake() ## End(Not run)## Not run: library(ggplot2) ggplot(penguins, aes(x = bill_len, y = flipper_len)) + geom_point(aes(color = species), na.rm = TRUE) + labs( x = "Bill length (mm)", y = "Flipper length (mm)", title = "Seminal ggplot2 scatterplot example", subtitle = "A plot that is only useful for demonstration purposes", caption = "Brought to you by the letter *p*", color = "Species" ) + theme_wjake() ## End(Not run)
Write a bibliography for R packages
write_pkg_bib(pkg, file, update = FALSE)write_pkg_bib(pkg, file, update = FALSE)
pkg |
A vector of packages to create a |
file |
The file to save the references. |
update |
Should packages be updated before creating the bibliography? |
A list containing the citations. Citations are also written to the file as a side effect.
## Not run: write_pkg_bib(c("ggplot2", "gt"), file = "packages.bib") ## End(Not run)## Not run: write_pkg_bib(c("ggplot2", "gt"), file = "packages.bib") ## End(Not run)
Wrappers around ggplot2::continuous_scale() that provide automatic percent
or comma formatting.
scale_x_comma(...) scale_y_comma(...) scale_x_percent(...) scale_y_percent(...)scale_x_comma(...) scale_y_comma(...) scale_x_percent(...) scale_y_percent(...)
... |
Additional arguments passed to |
A ggplot2 continuous scale.
library(ggplot2) set.seed(1234) ggplot() + geom_point(aes(x = sample(1000:9999, size = 100), y = runif(100, 0, 1))) + scale_x_comma() + scale_y_percent(breaks = seq(0, 1, by = .2))library(ggplot2) set.seed(1234) ggplot() + geom_point(aes(x = sample(1000:9999, size = 100), y = runif(100, 0, 1))) + scale_x_comma() + scale_y_percent(breaks = seq(0, 1, by = .2))