Skip to content

Instantly share code, notes, and snippets.

@charliejhadley
Created May 20, 2022 18:31
Show Gist options
  • Save charliejhadley/a9f0997c4c65ba527412a4b9e9104e7d to your computer and use it in GitHub Desktop.
Save charliejhadley/a9f0997c4c65ba527412a4b9e9104e7d to your computer and use it in GitHub Desktop.
where-do-you-wrap.R
library(tidyverse)
survey_data <- tribble(
~id, ~group, ~question, ~response,
1, "A", "Do you think survey questions tend to be too long?", "Strong agree",
2, "B", "Do you think survey questions tend to be too long?", "Agree",
3, "C", "Do you think survey questions tend to be too long?", "Strong agree",
4, "A", "Do you like answering surveys, in general?", "Strong disagree",
5, "B", "Do you like answering surveys, in general?", "disagree",
6, "C", "Do you like answering surveys, in general?", "Strong agree",
)
response_counts <- survey_data %>%
count(group, question, response)
gg_wrap_with_mutate <- response_counts %>%
mutate(question = str_wrap(question, 20)) %>%
ggplot(aes(x = n,
y = group,
fill = response)) +
geom_col() +
facet_grid(question ~ .) +
theme(strip.text.y = element_text(angle = 0))
gg_wrap_with_mutate
gg_wrap_with_labeller <- response_counts %>%
ggplot(aes(x = n,
y = group,
fill = response)) +
geom_col() +
facet_grid(question ~ .,
labeller = label_wrap_gen(20)) +
theme(strip.text.y = element_text(angle = 0))
gg_wrap_with_labeller
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment