Skip to contents

Generate Point Estimates Plot for Categorical/Ordinal Dependent Variables This function creates a `ggplot2` visualization of point estimates and credible intervals, typically representing "winner/loser" effects, combined with a rug plot showing the raw distribution of the dependent variable in each faceted column. It is designed for ordinal or nominbal dependent variables.

Usage

ggPoint_categories(
  plot_dat,
  raw_data_for_rug,
  dv_col_name = "burn_flag",
  facet_col_name = "presvote_trump_2020",
  color_col_name = "prepost",
  category_levels = c("1", "2", "3", "4", "5"),
  category_labels = c("Strongly Disagree", "Disagree", "Neither Agree nor Disagree",
    "Agree", "Strongly Agree"),
  facet_levels = c("0", "1"),
  facet_labels = c("Trump Voter", "Biden Voter"),
  color_levels = c("pre", "post"),
  color_values = c("grey", "black"),
  color_labels = c("Pre-Survey", "Post-Survey"),
  point_size = 3,
  dodge_width = 0.6,
  linerange_width = 1.25,
  title = "Point estimates",
  y_axis_title = "Posterior Mean Estimate",
  x_axis_title = "",
  rug_jitter_height = 0.1,
  rug_side = "b",
  rug_alpha = 0.1,
  rug_size = 0.3,
  rug_length = grid::unit(0.05, "npc"),
  rug_color = "lightgrey",
  y_axis_limits = c(0, 1),
  ...
)

Arguments

plot_dat

Dataframe containing posterior predictions with `mean`, `lower`, `upper` bounds for estimates, and columns for `.category`, `prepost`, and the faceting variable.

raw_data_for_rug

Dataframe containing the original, raw data. This is used to calculate the distribution for the rug plot. It must contain the columns specified by `dv_col_name` and `facet_col_name`. The plot shows the marginal distributionals across pre-post treatment.

dv_col_name

Character string. The name of the column in `raw_data_for_rug` that represents the raw dependent variable (e.g., `"burn_flag"`). This variable should contain numeric or factor levels (e.g., "1" to "5") that map to `.category`.

facet_col_name

Character string. The name of the column in both `plot_dat` and `raw_data_for_rug` used for faceting (e.g., `"presvote_trump_2020"`).

color_col_name

Character string. The name of the column in `plot_dat` used for coloring points and lines (e.g., `"prepost"`).

category_levels

Character vector. The underlying levels of the `.category` variable (e.g., `c("1", "2", "3", "4", "5")`). Used for factor reordering.

category_labels

Character vector. The labels corresponding to `category_levels` (e.g., `c("Strongly Disagree", ..., "Strongly Agree")`).

facet_levels

Character vector. The underlying levels of the `facet_col_name` (e.g., `c("0", "1")`). Used for factor reordering.

facet_labels

Character vector. The labels corresponding to `facet_levels` (e.g., `c("Trump Voter", "Biden Voter")`).

color_levels

Character vector. The underlying levels of the `color_col_name` (e.g., `c("pre", "post")`). Used for factor reordering.

color_values

Character vector. The hexadecimal color codes for the levels of `color_col_name` (e.g., `c("grey", "black")`).

color_labels

Character vector. The labels corresponding to `color_levels` (e.g., `c("Pre-Survey", "Post-Survey")`).

point_size

Numeric. Size of the `geom_point` markers. Defaults to `3`.

dodge_width

Numeric. Horizontal dodging width for `geom_point` and `geom_linerange` to separate overlaid groups. Defaults to `0.6`.

linerange_width

Numeric. Line width for `geom_linerange`. Defaults to `1.25`.

title

Character string. Main title of the plot. Defaults to `"Point estimates"`.

y_axis_title

Character string. Label for the Y-axis (which becomes the X-axis after `coord_flip()`). Defaults to `"Posterior Mean Estimate"`.

x_axis_title

Character string. Label for the X-axis (which becomes the Y-axis after `coord_flip()`). Defaults to `""` (empty string).

rug_jitter_height

Numeric. Amount of vertical jitter for the rug plot points. Defaults to `0.1`.

rug_side

Character string. Side for the rug plot (`"b"`, `"t"`, `"l"`, `"r"`). Defaults to `"b"` (bottom, which is left after `coord_flip()`).

rug_alpha

Numeric. Transparency (alpha) of the rug plot marks. Defaults to `0.1`.

rug_size

Numeric. Size (thickness) of the rug plot marks. Defaults to `0.3`.

rug_length

Unit object. Length of the rug plot marks. Defaults to `unit(0.05, "npc")`.

rug_color

Character string. Color of the rug plot marks. Defaults to `"lightgrey"`.

...

Additional arguments passed to `ggplot2::facet_wrap()`.

Value

A `ggplot` object.