Created
May 20, 2022 18:31
-
-
Save charliejhadley/a9f0997c4c65ba527412a4b9e9104e7d to your computer and use it in GitHub Desktop.
where-do-you-wrap.R
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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