Skip to content

Instantly share code, notes, and snippets.

@sneakers-the-rat
Created July 17, 2019 21:11
Show Gist options
  • Save sneakers-the-rat/234e6cfc1413a5f25fd58266ff4ade34 to your computer and use it in GitHub Desktop.
Save sneakers-the-rat/234e6cfc1413a5f25fd58266ff4ade34 to your computer and use it in GitHub Desktop.
google sheets for classroom surveys
library(googlesheets)
library(tidyverse)
# get spreadsheet key
#sheet_key <- extract_key_from_url("https://docs.google.com/spreadsheets/d/e/2PACX-1vRyiiW8T0JFOnycEhQM6WaoUgcA_5xpO5xe-x0ifhI38XfmOpAuUvbtMCw8Lg6CuX5W--wbh0XFk9KU/pubhtml")
# stash so it dont crash during class
sheet_key <- "1TbkdZ_FSdf-PBqPwNBFcEVCANVgb1xgXv70GhqjmWrk"
# download sheet
emotions_raw <- gs_key(sheet_key) %>% gs_read()
# drop timestamp and gather to long
emotions <- emotions_raw %>%
select(-c("Timestamp")) %>%
gather()
# add song labels - _# is appended to repeated labels,
# use that to assign song identity
emotions <- emotions %>%
mutate(song = case_when(
str_detect(key, '_1') ~ "Iglooghost - Super Ink Burst",
str_detect(key, '_2') ~ "Little Simz - Our Conversations",
TRUE ~ "Emily King - Distance"
)) %>%
mutate(
key = str_remove(key, "_\\d")
)
# drop na
emotions <- emotions %>%
filter(!is.na(value))
# plottet
g.emote <- ggplot(emotions, aes(y=value, x=key, color=key, fill=key))+
facet_grid(song~.)+
geom_violin(alpha=0.25, trim=FALSE)+
geom_point(position=position_jitter(width=0.1, height=0.1))+
scale_y_continuous(limits=c(1,5), name="Rating")+
theme(legend.position = "none",
axis.title.x = element_blank(),
axis.text.x = element_text(size=unit(16,"pt")),
axis.text.y = element_text(size=unit(14,"pt")),
panel.grid.minor = element_blank(),
panel.grid.major.x = element_blank(),
panel.grid.major.y = element_line(color="#A0A0A0"),
panel.background = element_rect(fill="#303030"))
ggsave('/some/path/to/save/this.pdf', g.emote, width=8, height=6, units="in", useDingbats=FALSE)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment