d <-
dplyr::tibble(
q1a = sample(c("y", "n"), size = 200, replace = TRUE),
q1b = sample(c("y", "n", "n", NA), size = 200, replace = TRUE),
q1c = sample(c("y", "y", "n"), size = 200, replace = TRUE),
q1d = sample("n", size = 200, replace = TRUE)
)
d |> plot_multiple_answers(q1a:q1c)
d |>
labelled::set_variable_labels(
q1a = "apple",
q1b = "banana",
q1c = "chocolate",
q1d = "Dijon mustard"
) |>
plot_multiple_answers(
value = "y",
drop_na = TRUE,
sort = "desc",
fill = "lightblue",
flip = TRUE
)
if (FALSE) { # rlang::is_installed("ggupset")
# \donttest{
d |>
plot_multiple_answers(
combine_answers = TRUE,
value = "y",
fill = "#DDCC77",
drop_na = TRUE
)
d |>
plot_multiple_answers(
combine_answers = TRUE,
value = "y",
flip = TRUE,
mapping = ggplot2::aes(fill = prop),
show.legend = FALSE
) +
ggplot2::scale_fill_distiller(palette = "Spectral")
d$group <- sample(c("group A", "group B"), size = 200, replace = TRUE)
d |>
plot_multiple_answers(
answers = q1a:q1d,
by = group,
combine_answers = TRUE,
sort = "degrees",
value = "y",
fill = "grey80"
)
d |>
plot_multiple_answers_dodge(q1a:q1d, by = group)
d |>
plot_multiple_answers_dodge(q1a:q1d, by = group, flip = TRUE)
d |>
plot_multiple_answers_dodge(q1a:q1d, by = group, combine_answers = TRUE)
# }
}
if (FALSE) { # rlang::is_installed(c("ggupset", "ggstats"))
}
Run the code above in your browser using DataLab