Skip to content

Instantly share code, notes, and snippets.

@dgkeyes
Created May 13, 2022 23:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dgkeyes/d8832ba32d5db9ed960992b0963c2d12 to your computer and use it in GitHub Desktop.
Save dgkeyes/d8832ba32d5db9ed960992b0963c2d12 to your computer and use it in GitHub Desktop.
library(tidyverse)
library(readxl)
library(janitor)
library(unheadr)
survey_monkey_raw <- read_excel("data/survey-monkey-data.xlsx") %>%
mash_colnames(1) %>%
clean_names()
fixed_responses <- c("Slept", "Eaten food", "Cooked food", "Gone to work", "Commuted for work", "Relaxed with a hobby (TELL US THE HOBBY BY TYPING IN THE OTHER FIELD)")
survey_monkey_long <- survey_monkey_raw %>%
pivot_longer(select_all_the_things_youve_done_in_the_past_24hours_slept:last_col()) %>%
mutate(value = str_remove(value, "- "))
survey_monkey_tidy <- survey_monkey_long %>%
mutate(response_label = case_when(
value %in% fixed_responses ~ value,
is.na(value) ~ NA_character_,
TRUE ~ "Other"
)) %>%
select(start_date, response_label) %>%
drop_na(response_label)
survey_monkey_tidy %>%
count(response_label) %>%
ggplot(aes(x = n,
y = response_label)) +
geom_col()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment