Skip to contents

This function creates a new column or label, merging estimates and standard errors with significant estimates represented in bold or as superscript (via label_est), and standard errors in brackets, if needed (via label_se). NAs are converted to empty strings. Main usage is for plotting tables and brace labels.

Usage

construct_label(
  dat,
  new_name = "label",
  label_est = NULL,
  label_se = NULL,
  label_sig_bold = NULL,
  label_sig_high = NULL,
  label_sig_high_extra_column = FALSE,
  round_est = 0,
  round_se = 1,
  plot_settings = plotsettings_tablebarplot()
)

Arguments

dat

Data frame with the columns that should be merged into labels.

new_name

Character string for the new column that is added to dat. Defaults to 'label'.

label_est

Character string of the column name containing the brace labels.

label_se

Character string of the column name containing the standard errors for label_est. Will be put in bracktes behind label_est.

label_sig_bold

Character string of the column name containing significance values for label_est. Significant values will be marked as bold. Defaults to "sig_Trend_noComp".

label_sig_high

Character string of the column name containing significance values for label_est. Significant values will be marked by a raised 'a'. Normally, should be the comparison of the trend vs. the trend in whole Germany, which can be found in the trendDiff_cross parameter. Defaults to NULL, as this parameter is not always provided.

label_sig_high_extra_column

Logical, if set 'FALSE' the superscript for significant values is added directly into the label (necessary for line plots), if set 'TRUE' the superscript for significant values is written into an extra column with the ending '_sig_superscript' (necessary for tables).

round_est

Rounding of label_est.

round_se

Rounding of label_se.

plot_settings

Named list constructed with plotsettings_lineplot(). Defaults to a list with all settings set to 0. There are several predefined lists with optimized settings for different plots. See plotsettings_lineplot() for an overview.

Value

The data frame with an added column for the constructed label.

Examples

# example data frame
dat <- data.frame(
  names = c("Berlin", "Hamburg", "Hessen", "Niedersachsen", "Saarland"),
  estimate = c(400, 650, 380, 500, 600),
  se = c(0.1, 0.45, 1, 0.27, 0.9),
  p_estimate = c(FALSE, FALSE, TRUE, TRUE, FALSE)
  )

# lineplots
construct_label(dat, label_est = "estimate", label_se = "se", round_se = 2)
#>           names estimate   se p_estimate      label
#> 1        Berlin      400 0.10      FALSE 400 (0.10)
#> 2       Hamburg      650 0.45      FALSE 650 (0.45)
#> 3        Hessen      380 1.00       TRUE 380 (1.00)
#> 4 Niedersachsen      500 0.27       TRUE 500 (0.27)
#> 5      Saarland      600 0.90      FALSE 600 (0.90)
construct_label(dat, new_name = "new", label_est = "estimate", label_se = "se", label_sig_bold = "p_estimate")
#>           names estimate   se p_estimate           new
#> 1        Berlin      400 0.10      FALSE     400 (0.1)
#> 2       Hamburg      650 0.45      FALSE     650 (0.4)
#> 3        Hessen      380 1.00       TRUE **380** (1.0)
#> 4 Niedersachsen      500 0.27       TRUE **500** (0.3)
#> 5      Saarland      600 0.90      FALSE     600 (0.9)

# tables
construct_label(dat, label_est = "estimate", label_se = "se", label_sig_high = "p_estimate",  label_sig_high_extra_column = TRUE)
#>           names estimate   se p_estimate label_sig_superscript     label
#> 1        Berlin      400 0.10      FALSE                       400 (0.1)
#> 2       Hamburg      650 0.45      FALSE                       650 (0.4)
#> 3        Hessen      380 1.00       TRUE          <sup>a</sup> 380 (1.0)
#> 4 Niedersachsen      500 0.27       TRUE          <sup>a</sup> 500 (0.3)
#> 5      Saarland      600 0.90      FALSE                       600 (0.9)