Creates a ship object, which serves as a container for data and methods to generate Theseus plots for decomposing differences in rate metrics.
Usage
create_ship(
data1,
data2,
y = "y",
labels = c("Baseline", "Comparison"),
xlab = NULL,
ylab = NULL,
digits = 1L,
text_size = 1
)Arguments
- data1
data frame representing the first group (e.g., the baseline data).
- data2
data frame representing the second group (e.g., the comparison data).
- y
column name specifying the outcome variable used to compute the rate metric (default is
"y"). Typically, this is a binary indicator (e.g., 0/1) that is aggregated to form rates.- labels
character vector of length 2 giving the labels for the two groups. The first corresponds to
data1, the second todata2. Default isc("Baseline", "Comparison").- xlab
string specifying the x-axis label for plots. If
NULL(default), no label is displayed.- ylab
string specifying the y-axis label for plots. If
NULL(default), no label is displayed.- digits
integer indicating the number of decimal places to use for displaying numeric values (default is
1).- text_size
numeric value specifying the relative size of text elements in plots (default is
1.0).
Value
A ShipOfTheseus object, which can be used with plot()
to create Theseus plots.
Examples
library(dplyr)
#>
#> Attaching package: ‘dplyr’
#> The following objects are masked from ‘package:stats’:
#>
#> filter, lag
#> The following objects are masked from ‘package:base’:
#>
#> intersect, setdiff, setequal, union
library(TheseusPlot)
data <- nycflights13::flights |>
filter(!is.na(arr_delay)) |>
mutate(on_time = arr_delay <= 0)
data1 <- data |> filter(month == 1)
data2 <- data |> filter(month == 2)
create_ship(data1, data2, y = on_time)
#> <ShipOfTheseus>
#> Public:
#> clone: function (deep = FALSE)
#> initialize: function (data1, data2, outcome, labels, xlab, ylab, digits,
#> plot: function (column_name, n = 10L, main_item = NULL, bar_max_value = NULL,
#> plot_flip: function (column_name, n = 10L, main_item = NULL, bar_max_value = NULL,
#> table: function (column_name, n = Inf, continuous = continuous_config())
#> Private:
#> compute_bar_height: function (data_waterfall, data_size, max_score, main_item = NULL,
#> compute_contribution: function (column_name, continuous)
#> compute_info: function (column_name, continuous)
#> compute_scores: function (column_name)
#> compute_size: function (column_name, target, continuous)
#> digits: 1
#> labels: Baseline Comparison
#> prepare_input_data: function (data, outcome)
#> prepare_plot_data: function (column_name, n, levels, continuous, flip)
#> text_size: 1
#> to_factor: function (column_name, continuous)
#> xlab: NULL
#> ylab: NULL