Skip to contents

Visualizes differences between survey and target data by zone group, with options for confidence intervals and color thresholds. Use to assess fit and highlight large discrepancies in weighting.

Usage

plot_weight_fit(
  data,
  settings,
  title = "",
  ylim = NULL,
  big_threshold = 25,
  small_color = "rosybrown",
  big_color = "#e96666",
  group_names,
  survey_ci = FALSE,
  target_ci = FALSE,
  ci_level = 0.9,
  facet_aspect = 5
)

Arguments

data

data.table. Output of calc_weight_fit with fit columns.

settings

list. Settings object with target configuration.

title

character(1). Plot title.

ylim

numeric(1), optional. Y-axis limit (default NULL).

big_threshold

numeric(1). Threshold for large differences (default 25).

small_color

character(1). Color for small differences.

big_color

character(1). Color for large differences.

group_names

character vector. Zone groups to plot.

survey_ci

logical(1). Add survey confidence interval.

target_ci

logical(1). Add target confidence interval.

ci_level

numeric(1). Confidence interval level (default 0.9).

facet_aspect

numeric(1). Aspect ratio for facets (height/width).

Value

ggplot object. Plot of fit by group.

Details

  • Plots percent difference between survey and target for each group.

  • Highlights large differences above threshold.

  • Optionally adds survey and target confidence intervals.

  • Dynamically sets y-axis limits if not provided.

  • Returns ggplot object for further customization or saving.

  • Assumes input is output of calc_weight_fit.

Settings

Used for target configuration and labeling.

See also

calc_weight_fit

Examples

## Not run:
plot_weight_fit(data, settings, group_names = c('A', 'B'))
#> Error in `:=`(big_diff, factor(1 * (abs(pct_diff) > big_threshold))): Check that is.data.table(DT) == TRUE. Otherwise, :=, `:=`(...) and let(...) are defined for use in j, once only and in particular ways. Note that namespace-qualification like data.table::`:=`(...) is not supported. See help(":=").