Skip to contents

This functions produces a dumbbell plot based on a dataframe with list experiment summaries. Let's say we ran list experiments for n statements and summarized results for m population subgroups defined by a categorical variable. A summary dataframe will have n times m rows – one for each statement-group combination. For each such combination we will have average probability to agree with statement publicly and average probability to agree privately.

Usage

list_exp_plot(
  data,
  private = private_probability,
  public = public_probability,
  group = demo_value,
  statement = NULL,
  color_scale = NULL,
  point_size = 10,
  point_stroke = 0.2 * point_size,
  text = TRUE,
  text_size = 0.7 * point_size,
  text_fontface = c("plain", "bold", "italic", "bold.italic"),
  priv_label = "Private opinion",
  publ_label = "Public opinion",
  xintercept = 0.5,
  accuracy = 1,
  expand = c(0, 0.4)
)

Arguments

data

A dataframe with list experiment summaries.

private

Variable containing list experiment assessment of 0-1 scaled probability to agree with the sensitive statement – private opinion.

public

Variable containing direct assessment of 0-1 scaled probability to agree with the sensitive statement – public opinion.

group

Categorical variable which defines population subgroups.

statement

Categorical variable defining statements which were studied.

color_scale

Color palette for the group variable. Should be a named vector with names corresponding to the levels in group.

point_size

Size of points at dumbbell ends.

point_stroke

Width of outline of points at dumbbell ends.

text

Logical. Annotate public and private opinion percentages? Default is TRUE.

text_size

Size of percentage annotations.

text_fontface

Character. One of "bold"(default), "plain", "italic" or "bold.italic".

priv_label, publ_label

Labels for private/public plot legend.

xintercept

Numeric (default is 0.5 (50%)) Set intercepts on the x axis before creating plots. Can be passed in as a vector of values.

accuracy

Numeric. Passed to the accuracy argument of the selected scale function to set numeric accuracy. Default is 1.

expand

Numeric. Value to be passed the mult argument of ggplot2::expansion() default is c(0, 0.4).

Value

A ggplot object.

Examples


if (FALSE) { # \dontrun{

library("dplyr")
library("ggplot2")
data("list_experiment_toy")

# Load list experiment model
data("list_model_toy")

# Subset data
list_experiment_toy <- list_experiment_toy[1:20, ]

# We select 3 categorical variables as demographic breaks and one artificial
# numeric variable just for the purpose of demonstration.

demo_toy <- list_experiment_toy %>%
  select("response_id", "d_party", "s_gender", "s_region") %>%
  mutate(num_var = rnorm(nrow(.), 3, 0.4))

# We can run read %>% assert %>% tidy in pipe

le_tidy_data_toy <-
  list_read_data(list_experiment_toy, "response_id") %>%
  list_assert_data(demo_toy, id = "response_id", n_items = 4L) %>%
  list_tidy_data(id = response_id)

## Prepare weights
demo_weights <- list_experiment_toy %>%
  select("response_id", "weights")

## Extract list experiment results
results <- list_model_results(list_model_toy, le_tidy_data_toy, demo_weights, "weights")

## Plot results

# color palette for population groups we are interested in
pal_region <- c(
  "MIDWEST" = "#3693ef",
  "NORTHEAST" = "#de425b",
  "SOUTH" = "#826cc4",
  "WEST" = "#f43f34"
)

results$prob_by_group %>%
filter(demo_value %in% names(pal_region)) %>%
  list_exp_plot(
    color_scale = pal_region,
    point_size = 12
  ) +
  ggtitle(
    paste(c(
      "Difference in private vs. public opinions\n",
      "about the American judicial system"
    ), collapse = ""),
    subtitle = paste0(c(
      "Percentages indicate the predicted probability of agreeing ",
      "with the statement in a list\nexperiment (private) vs. a direct ",
      "question (public)"
    ), collapse = "")
  )

} # }