| Title: | Generating Bootstrap Estimation Distributions of HR Data |
|---|---|
| Description: | Creates plots showing scored HR experiments and plots of distribution of means of ranks of HR score from bootstrapping. |
| Authors: | Dan MacLean [aut, cre] |
| Maintainer: | Dan MacLean <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.4.0 |
| Built: | 2026-05-17 08:54:39 UTC |
| Source: | https://github.com/cran/besthr |
Applies the besthr theme and color scales to a ggplot object based on configuration settings. This ensures consistent theming across all plot components.
apply_besthr_theme(p, config, include_fill = TRUE, include_color = TRUE)apply_besthr_theme(p, config, include_fill = TRUE, include_color = TRUE)
p |
A ggplot object |
config |
A besthr_plot_config object |
include_fill |
Logical, whether to apply fill scale (default TRUE) |
include_color |
Logical, whether to apply color scale (default TRUE) |
The ggplot object with theme and scales applied
library(ggplot2) p <- ggplot(mtcars, aes(mpg, wt, color = factor(cyl))) + geom_point() cfg <- besthr_plot_config(theme_style = "modern", color_palette = "okabe_ito") apply_besthr_theme(p, cfg)library(ggplot2) p <- ggplot(mtcars, aes(mpg, wt, color = factor(cyl))) + geom_point() cfg <- besthr_plot_config(theme_style = "modern", color_palette = "okabe_ito") apply_besthr_theme(p, cfg)
Extracts and organizes data from an hrest object for plotting. Computes unified axis limits that ensure alignment between observation and bootstrap panels.
besthr_data_view(hrest, config = NULL)besthr_data_view(hrest, config = NULL)
hrest |
An hrest object from |
config |
A besthr_plot_config object (optional). If NULL, uses defaults. |
An object of class "besthr_data_view" containing ranked data, original data, bootstrap samples, group means, confidence intervals, group sample sizes, unified rank limits, group column symbol, column info, control group name, and quantile values.
d <- make_data() hr <- estimate(d, score, group) dv <- besthr_data_view(hr)d <- make_data() hr <- estimate(d, score, group) dv <- besthr_data_view(hr)
Returns a color palette suitable for besthr visualizations. The default palette uses Okabe-Ito colorblind-safe colors.
besthr_palette(palette = "default", n = NULL)besthr_palette(palette = "default", n = NULL)
palette |
Character string specifying the palette. Options are:
|
n |
Number of colors to return. If NULL, returns all colors in palette. |
A character vector of hex color codes
besthr_palette() besthr_palette("okabe_ito", 3)besthr_palette() besthr_palette("okabe_ito", 3)
Creates a configuration object that controls the appearance and behavior of besthr plots. All parameters have defaults that reproduce the original besthr appearance for backward compatibility.
besthr_plot_config( panel_widths = c(1, 1), panel_spacing = grid::unit(0.5, "cm"), y_limits = NULL, y_expand = 0.05, point_size_range = c(2, 8), point_alpha = 0.8, mean_line_type = 3, mean_line_width = 1, density_alpha = 0.7, density_style = "points", theme_style = "modern", color_palette = "okabe_ito" )besthr_plot_config( panel_widths = c(1, 1), panel_spacing = grid::unit(0.5, "cm"), y_limits = NULL, y_expand = 0.05, point_size_range = c(2, 8), point_alpha = 0.8, mean_line_type = 3, mean_line_width = 1, density_alpha = 0.7, density_style = "points", theme_style = "modern", color_palette = "okabe_ito" )
panel_widths |
Numeric vector of relative panel widths for patchwork layout. |
panel_spacing |
A grid unit specifying spacing between panels. |
y_limits |
Numeric vector of length 2 for y-axis limits, or NULL for auto. |
y_expand |
Numeric giving proportional expansion of y-axis limits. |
point_size_range |
Numeric vector of length 2 for min/max point sizes. |
point_alpha |
Numeric between 0 and 1 for point transparency. |
mean_line_type |
Line type for mean indicator lines. |
mean_line_width |
Line width for mean indicator lines. |
density_alpha |
Numeric between 0 and 1 for density plot transparency. |
density_style |
Character: "points" (default, jittered bootstrap points), "gradient" (density with CI shading), or "solid" (single color density). |
theme_style |
Character: "classic" or "modern". |
color_palette |
Character: "default", "okabe_ito", or "viridis". |
An object of class "besthr_plot_config" containing all plot settings.
cfg <- besthr_plot_config() cfg <- besthr_plot_config(panel_widths = c(2, 1), theme_style = "modern")cfg <- besthr_plot_config() cfg <- besthr_plot_config(panel_widths = c(2, 1), theme_style = "modern")
Returns a pre-configured besthr_plot_config object with sensible
defaults for common use cases. This is the easiest way to customize
besthr plot appearance without understanding all the configuration options.
besthr_style(style = "default")besthr_style(style = "default")
style |
Character string specifying the style preset:
|
A besthr_plot_config object
d <- make_data() hr <- estimate(d, score, group) # Quick styling with presets plot(hr, config = besthr_style("publication")) plot(hr, config = besthr_style("presentation")) plot(hr, config = besthr_style("density")) # Same as default plot(hr, config = besthr_style("default"))d <- make_data() hr <- estimate(d, score, group) # Quick styling with presets plot(hr, config = besthr_style("publication")) plot(hr, config = besthr_style("presentation")) plot(hr, config = besthr_style("density")) # Same as default plot(hr, config = besthr_style("default"))
Creates a publication-ready summary table containing group statistics, confidence intervals, and optionally effect sizes and significance.
besthr_table( hrest, format = "tibble", digits = 2, include_significance = FALSE )besthr_table( hrest, format = "tibble", digits = 2, include_significance = FALSE )
hrest |
An hrest object from |
format |
Output format: "tibble" (default), "markdown", "html", or "latex" |
digits |
Number of decimal places for rounding (default 2) |
include_significance |
Logical, whether to include significance stars (default FALSE) |
A tibble (if format = "tibble") or character string (other formats)
d <- make_data() hr <- estimate(d, score, group) besthr_table(hr) besthr_table(hr, format = "markdown")d <- make_data() hr <- estimate(d, score, group) besthr_table(hr) besthr_table(hr, format = "markdown")
Creates a ggplot showing ridge density plots of bootstrap distributions with confidence interval shading.
build_bootstrap_panel(data_view, config)build_bootstrap_panel(data_view, config)
data_view |
A besthr_data_view object |
config |
A besthr_plot_config object |
A ggplot object
d <- make_data() hr <- estimate(d, score, group) dv <- besthr_data_view(hr) cfg <- besthr_plot_config() build_bootstrap_panel(dv, cfg)d <- make_data() hr <- estimate(d, score, group) dv <- besthr_data_view(hr) cfg <- besthr_plot_config() build_bootstrap_panel(dv, cfg)
Creates a ggplot showing either ranked observations (averaged tech reps) or raw scores with technical replicates displayed.
build_observation_panel(data_view, config, which = "rank_simulation")build_observation_panel(data_view, config, which = "rank_simulation")
data_view |
A besthr_data_view object |
config |
A besthr_plot_config object |
which |
Character specifying panel type: "rank_simulation" for averaged ranked data, or "just_data" for raw scores with tech reps. |
A ggplot object
d <- make_data() hr <- estimate(d, score, group) dv <- besthr_data_view(hr) cfg <- besthr_plot_config() build_observation_panel(dv, cfg, "rank_simulation")d <- make_data() hr <- estimate(d, score, group) dv <- besthr_data_view(hr) cfg <- besthr_plot_config() build_observation_panel(dv, cfg, "rank_simulation")
Combines observation and bootstrap panels using patchwork with proper alignment and shared legends.
compose_besthr_panels(panels, config)compose_besthr_panels(panels, config)
panels |
A list of ggplot objects to compose |
config |
A besthr_plot_config object |
A patchwork object
d <- make_data() hr <- estimate(d, score, group) dv <- besthr_data_view(hr) cfg <- besthr_plot_config() p1 <- build_observation_panel(dv, cfg) p2 <- build_bootstrap_panel(dv, cfg) compose_besthr_panels(list(p1, p2), cfg)d <- make_data() hr <- estimate(d, score, group) dv <- besthr_data_view(hr) cfg <- besthr_plot_config() p1 <- build_observation_panel(dv, cfg) p2 <- build_bootstrap_panel(dv, cfg) compose_besthr_panels(list(p1, p2), cfg)
Calculates the effect size (difference from control) for each treatment group with bootstrap confidence intervals.
compute_effect_size(hrest)compute_effect_size(hrest)
hrest |
An hrest object from |
A data frame with columns: group, effect, effect_ci_low, effect_ci_high
d <- make_data() hr <- estimate(d, score, group, nits = 500) compute_effect_size(hr)d <- make_data() hr <- estimate(d, score, group, nits = 500) compute_effect_size(hr)
Determines statistical significance by checking if the bootstrap confidence interval for each treatment group overlaps with the control group's mean rank.
compute_significance(hrest)compute_significance(hrest)
hrest |
An hrest object from |
A data frame with columns: group, significant (logical), p_value, stars
d <- make_data() hr <- estimate(d, score, group, nits = 500) compute_significance(hr)d <- make_data() hr <- estimate(d, score, group, nits = 500) compute_significance(hr)
Computes confidence interval fill colors that harmonize with the selected color palette and theme style. This ensures visual consistency between the observation panel colors and the bootstrap density shading.
derive_ci_colors(palette = "default", theme_style = "classic")derive_ci_colors(palette = "default", theme_style = "classic")
palette |
Character string specifying the color palette: "default", "okabe_ito", or "viridis" |
theme_style |
Character string specifying the theme: "classic" or "modern" |
A character vector of three hex colors with alpha for low, middle, and high CI regions
derive_ci_colors("default", "classic") derive_ci_colors("okabe_ito", "modern") derive_ci_colors("viridis", "classic")derive_ci_colors("default", "classic") derive_ci_colors("okabe_ito", "modern") derive_ci_colors("viridis", "classic")
estimate carries out estimation of bootstrap confidence intervals on
ranked score data. Returns a hrest object of the result
Proceeeds by calculating score ranks, then bootstrapping ranks in non-control
groups retaining the mean for each bootstrap iteration. Calculates
low and high quantiles of bootstrap mean distributions for each group.
If technical replicates are provided in a second grouping column these will
be averaged before proceeding.
estimate(df, ..., control = "A", nits = 100, low = 0.025, high = 0.975)estimate(df, ..., control = "A", nits = 100, low = 0.025, high = 0.975)
df |
data frame of score and group data. Contains minimally a score and group column |
... |
bare names of columns to use, minimally the score column and the group column in that order. Optionally a third technical replicate column can be provided |
control |
the value of the grouping column taken to be the control group |
nits |
the number of bootstap iterations to be done |
low |
the low probability value of the quantile |
high |
the high probability value of the quantile |
a list object of class "hrest"
d1 <- make_data() estimate(d1, score, group) d2 <- make_data2() estimate(d2, score_column_name, sample_column_name, rep_column_name ) d3 <- make_data3() estimate(d3, score, sample, rep, nits = 1000)d1 <- make_data() estimate(d1, score, group) d2 <- make_data2() estimate(d2, score_column_name, sample_column_name, rep_column_name ) d3 <- make_data3() estimate(d3, score, sample, rep, nits = 1000)
Creates a ggplot2 layer showing ridge density plots of bootstrap distributions with confidence interval shading.
layer_bootstrap_density(data_view, config)layer_bootstrap_density(data_view, config)
data_view |
A besthr_data_view object |
config |
A besthr_plot_config object |
A list of ggplot2 layers
d <- make_data() hr <- estimate(d, score, group) dv <- besthr_data_view(hr) cfg <- besthr_plot_config() # layer_bootstrap_density returns layers to add to a ggplotd <- make_data() hr <- estimate(d, score, group) dv <- besthr_data_view(hr) cfg <- besthr_plot_config() # layer_bootstrap_density returns layers to add to a ggplot
Creates a ggplot2 layer showing horizontal lines at group mean ranks.
layer_group_means(data_view, config)layer_group_means(data_view, config)
data_view |
A besthr_data_view object |
config |
A besthr_plot_config object |
A ggplot2 layer
d <- make_data() hr <- estimate(d, score, group) dv <- besthr_data_view(hr) cfg <- besthr_plot_config() # layer_group_means returns a ggplot layerd <- make_data() hr <- estimate(d, score, group) dv <- besthr_data_view(hr) cfg <- besthr_plot_config() # layer_group_means returns a ggplot layer
Creates a ggplot2 layer showing ranked observations as points, where point size indicates the count of observations at each rank/group combination.
layer_ranked_dots(data_view, config)layer_ranked_dots(data_view, config)
data_view |
A besthr_data_view object |
config |
A besthr_plot_config object |
A list of ggplot2 layers
d <- make_data() hr <- estimate(d, score, group) dv <- besthr_data_view(hr) cfg <- besthr_plot_config() # layer_ranked_dots returns layers to add to a ggplotd <- make_data() hr <- estimate(d, score, group) dv <- besthr_data_view(hr) cfg <- besthr_plot_config() # layer_ranked_dots returns layers to add to a ggplot
Creates a ggplot2 layer showing raw score observations with technical replicates displayed separately. Points are sized by observation count.
layer_tech_rep_dots(data_view, config)layer_tech_rep_dots(data_view, config)
data_view |
A besthr_data_view object |
config |
A besthr_plot_config object |
A list of ggplot2 layers
Shows all available preset styles that can be used with besthr_style().
list_besthr_styles()list_besthr_styles()
A character vector of style names (invisibly)
list_besthr_styles()list_besthr_styles()
return a sample data set of random values for two groups
make_data()make_data()
tibble of random values for two groups
d1 <- make_data()d1 <- make_data()
return a sample data set of random values for two groups with three technical reps per group
make_data2()make_data2()
tibble of random values for two groups with three technical reps per group
d2 <- make_data2()d2 <- make_data2()
@examples
make_data3()make_data3()
d3 <- make_data3()
tibble of random values for three groups with three technical reps per group
Creates a raincloud plot specifically for bootstrap distributions, showing the distribution of bootstrap mean ranks with jittered points and summary statistics.
plot_bootstrap_raincloud( hrest, theme = "modern", colors = "okabe_ito", config = NULL )plot_bootstrap_raincloud( hrest, theme = "modern", colors = "okabe_ito", config = NULL )
hrest |
An hrest object from |
theme |
the visual theme to use. Either "modern" (default) or "classic" |
colors |
the color palette to use. Either "okabe_ito" (default), "default", or "viridis" |
config |
an optional besthr_plot_config object |
A ggplot object
d <- make_data() hr <- estimate(d, score, group, nits = 100) plot_bootstrap_raincloud(hr)d <- make_data() hr <- estimate(d, score, group, nits = 100) plot_bootstrap_raincloud(hr)
Creates a unified raincloud visualization combining:
Jittered raw data points
Half-violin density plots
Mean with confidence interval as pointrange
plot_raincloud( hrest, theme = "modern", colors = "okabe_ito", config = NULL, show_bootstrap = TRUE, jitter_width = 0.15, point_size = 1.5 )plot_raincloud( hrest, theme = "modern", colors = "okabe_ito", config = NULL, show_bootstrap = TRUE, jitter_width = 0.15, point_size = 1.5 )
hrest |
An hrest object from |
theme |
the visual theme to use. Either "modern" (default) or "classic" |
colors |
the color palette to use. Either "okabe_ito" (default), "default", or "viridis" |
config |
an optional besthr_plot_config object for advanced customization. If provided, theme and colors parameters are ignored. |
show_bootstrap |
Ignored (kept for backward compatibility). |
jitter_width |
Numeric width of jitter for data points. Default 0.15. |
point_size |
Numeric size for jittered points. Default 1.5. |
This provides an alternative to the standard two-panel besthr plot, combining all information in a single comprehensive visualization.
A ggplot object
d <- make_data() hr <- estimate(d, score, group) plot_raincloud(hr)d <- make_data() hr <- estimate(d, score, group) plot_raincloud(hr)
hrest objectreturns a ggplot object representing the hrest object from
estimate. The content of left panel varies according to the
value of the which parameter. If which = "rank_simulation" is
used a plot of rank score values will be plotted in the left panel. In this
case technical replicates will be averaged if provided. If
which = "just_data" a plot of scores only is created and technical
replicates are displayed as is. In each case, the right hand panel shows the
rank bootstrap distribution and confidence interval boundaries for all non-
control groups.
## S3 method for class 'hrest' plot( x, ..., which = "rank_simulation", theme = "modern", colors = "okabe_ito", config = NULL, show_significance = FALSE, show_effect_size = FALSE )## S3 method for class 'hrest' plot( x, ..., which = "rank_simulation", theme = "modern", colors = "okabe_ito", config = NULL, show_significance = FALSE, show_effect_size = FALSE )
x |
the |
... |
Other parameters (ignored) |
which |
the type of left hand panel to create. Either "rank_simulation" or "just_data" |
theme |
the visual theme to use. Either "modern" (default, cleaner contemporary style) or "classic" (original besthr appearance) |
colors |
the color palette to use. Either "okabe_ito" (default, colorblind-safe), "default" (original colors), or "viridis" |
config |
an optional besthr_plot_config object for advanced customization. If provided, theme and colors parameters are ignored. |
show_significance |
Logical, whether to show significance stars on groups where CI doesn't overlap control (default FALSE) |
show_effect_size |
Logical, whether to show effect size annotation (default FALSE) |
ggplot object
d1 <- make_data() hr_est <- estimate(d1, score, group) plot(hr_est) # Use modern theme with colorblind-safe palette plot(hr_est, theme = "modern", colors = "okabe_ito") # Advanced configuration cfg <- besthr_plot_config( panel_widths = c(2, 1), point_size_range = c(3, 10) ) plot(hr_est, config = cfg)d1 <- make_data() hr_est <- estimate(d1, score, group) plot(hr_est) # Use modern theme with colorblind-safe palette plot(hr_est, theme = "modern", colors = "okabe_ito") # Advanced configuration cfg <- besthr_plot_config( panel_widths = c(2, 1), point_size_range = c(3, 10) ) plot(hr_est, config = cfg)
Print method for besthr_data_view
## S3 method for class 'besthr_data_view' print(x, ...)## S3 method for class 'besthr_data_view' print(x, ...)
x |
A besthr_data_view object |
... |
Additional arguments (ignored) |
Invisibly returns x
Print method for besthr_plot_config
## S3 method for class 'besthr_plot_config' print(x, ...)## S3 method for class 'besthr_plot_config' print(x, ...)
x |
A besthr_plot_config object |
... |
Additional arguments (ignored) |
Invisibly returns x
print a summary of the hrest object
## S3 method for class 'hrest' print(x, ...)## S3 method for class 'hrest' print(x, ...)
x |
hrest object |
... |
other parameters |
null
d1 <- make_data() hr_est <- estimate(d1, score, group) print(hr_est)d1 <- make_data() hr_est <- estimate(d1, score, group) print(hr_est)
Saves a besthr visualization to a file with sensible publication defaults. Supports PNG, PDF, SVG, and TIFF formats.
save_besthr( hrest, filename, type = "default", width = 8, height = 6, dpi = 300, ... )save_besthr( hrest, filename, type = "default", width = 8, height = 6, dpi = 300, ... )
hrest |
An hrest object from |
filename |
Output filename. Format is detected from extension. |
type |
Plot type: "default" (two-panel) or "raincloud" |
width |
Plot width in inches (default 8) |
height |
Plot height in inches (default 6) |
dpi |
Resolution in dots per inch (default 300) |
... |
Additional arguments passed to the plot function (e.g., theme, colors) |
The filename (invisibly)
## Not run: d <- make_data() hr <- estimate(d, score, group) save_besthr(hr, "figure1.png") save_besthr(hr, "figure1.pdf", width = 10, height = 8) save_besthr(hr, "figure1.png", type = "raincloud") ## End(Not run)## Not run: d <- make_data() hr <- estimate(d, score, group) save_besthr(hr, "figure1.png") save_besthr(hr, "figure1.pdf", width = 10, height = 8) save_besthr(hr, "figure1.png", type = "raincloud") ## End(Not run)
A discrete color scale using besthr palettes.
scale_color_besthr(palette = "default", ...) scale_colour_besthr(palette = "default", ...)scale_color_besthr(palette = "default", ...) scale_colour_besthr(palette = "default", ...)
palette |
Character string specifying the palette (see |
... |
Additional arguments passed to |
A ggplot2 discrete color scale
library(ggplot2) ggplot(mtcars, aes(mpg, wt, color = factor(cyl))) + geom_point() + scale_color_besthr("okabe_ito")library(ggplot2) ggplot(mtcars, aes(mpg, wt, color = factor(cyl))) + geom_point() + scale_color_besthr("okabe_ito")
A discrete fill scale using besthr palettes.
scale_fill_besthr(palette = "default", ...)scale_fill_besthr(palette = "default", ...)
palette |
Character string specifying the palette (see |
... |
Additional arguments passed to |
A ggplot2 discrete fill scale
library(ggplot2) ggplot(mtcars, aes(factor(cyl), fill = factor(cyl))) + geom_bar() + scale_fill_besthr("okabe_ito")library(ggplot2) ggplot(mtcars, aes(factor(cyl), fill = factor(cyl))) + geom_bar() + scale_fill_besthr("okabe_ito")
A custom theme for besthr plots. The "classic" theme matches the original besthr appearance, while "modern" provides a cleaner, more contemporary look.
theme_besthr(style = "classic", base_size = 11, base_family = "")theme_besthr(style = "classic", base_size = 11, base_family = "")
style |
Character string specifying the theme style. Options are:
|
base_size |
Base font size (default 11) |
base_family |
Base font family |
A ggplot2 theme object
library(ggplot2) ggplot(mtcars, aes(mpg, wt)) + geom_point() + theme_besthr("modern")library(ggplot2) ggplot(mtcars, aes(mpg, wt)) + geom_point() + theme_besthr("modern")
Creates a new configuration by updating specific fields of an existing one.
update_config(config, ...)update_config(config, ...)
config |
An existing besthr_plot_config object |
... |
Named arguments to update |
A new besthr_plot_config object
cfg <- besthr_plot_config() cfg2 <- update_config(cfg, theme_style = "modern", panel_widths = c(2, 1))cfg <- besthr_plot_config() cfg2 <- update_config(cfg, theme_style = "modern", panel_widths = c(2, 1))