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
g6tr_list_exp_plot(
data,
priv_p,
publ_p,
group = NULL,
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"
)Arguments
- data
A dataframe with list experiment summaries.
- priv_p
Variable containing list experiment assessment of 0-1 scaled probability to agree with the sensitive statement – private opinion. Quoted or unquoted.
- publ_p
Variable containing direct assessment of 0-1 scaled probability to agree with the sensitive statement – public opinion. Quoted or unquoted.
- group
Categorical variable which defines population subgroups. Quoted or unquoted.
- statement
Categorical variable defining statements which were studied. Quoted or unquoted.
- color_scale
Color palette for the
groupvariable.- 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.
Examples
library(ggplot2)
library(dplyr)
# list experiment summary data
data <-
tibble(
group = rep(c("Democrats", "Republicans", "Overall"), 2),
list_p = c(0.467, 0.249, 0.412, 0.676, 0.344, 0.494),
direct_p = c(0.691, 0.239, 0.493, 0.786, 0.352, 0.588),
question = rep(1:2, each = 3),
label = rep(c("Statement 1: Yellow color is better than red",
"Statement 2: It was raining yesterday"), each = 3)
)
# color palette for population groups that were studied
pal_party <- c(
"Democrats" = "#3693ef",
"Republicans" = "#de425b",
"Overall" = "#826cc4"
)
data %>%
g6tr_list_exp_plot(
list_p, direct_p, group, label,
color_scale = pal_party,
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 = "")
)
#> Warning: `aes_string()` was deprecated in ggplot2 3.0.0.
#> ℹ Please use tidy evaluation idioms with `aes()`.
#> ℹ See also `vignette("ggplot2-in-packages")` for more information.
#> ℹ The deprecated feature was likely used in the g6tr.theme package.
#> Please report the issue to the authors.