Skip to contents

Generate plot of point estimates from BRMS object

This function generates a `ggplot2` plot of posterior point estimates and credible intervals from a `brms` model, specifically designed for cumulative or categorical outcomes. The data come from the 2020 Western States Survey.

Usage

ggMargins_categories(
  data = plot_dat,
  size_x = 10,
  size_title = 12,
  title = "Marginal Effect",
  ytitle = "Change in Probability",
  ylimits = c(-0.25, 0.25),
  mvar = "presvote_trump_2020",
  point_size = 3,
  point_opacity = 0.5,
  bar_opacity = 0.5,
  point_color_values = c("#E63946", "#457B9D"),
  point_distance = 0.5,
  ...
)

Arguments

data

Dataframe containing posterior predictions, typically from `electoralContestation::posterior_me` or similar prediction functions. It must include columns named `.category` (for the response categories), `mean`, `lower`, `upper` (for credible intervals), and the column specified by `mvar` (the moderator variable). Defaults to `plot_dat`.

size_x

Numeric value. This controls the font size for the axis text. Defaults to `10`.

size_title

Numeric value. Font size for the plot title and axis titles. Defaults to `12`.

title

Character string. Main title of the the plot. Defaults to `"Marginal Effect"`.

ytitle

Character string. Label for the Y-axis (which becomes the X-axis after `coord_flip()`). Defaults to `"Change in Probability from Pre to Post"`.

ylimits

Numeric vector of length 2. Lower and upper limits for the Y-axis (which becomes the X-axis after `coord_flip()`). Defaults to `c(-0.25, 0.25)`.

mvar

Character string. Name of the moderator variable column in the `data` dataframe, used for grouping and coloring the points. Defaults to `"presvote_trump_2020"`.

point_size

Numeric. Size of the data points in `geom_point()`. Defaults to `3`.

point_opacity

Numeric. Transparency (alpha) of the data points. Defaults to `0.5`.

bar_opacity

Numeric. Transparency (alpha) of the error bars. Defaults to `0.5`.

point_color_values

Character vector. Colors used for the levels of the moderator variable (`mvar`). Defaults to `c("#E63946", "#457B9D")`.

point_distance

Numeric. Dodge width for `geom_point()` and `geom_errorbar()` to horizontally separate points and error bars for different groups on the categorical axis. Defaults to `0.5`.

...

Additional arguments passed to `ggplot2::theme()` for further customization of plot elements.