# ## Where to find this document # # Shortlink humans can type: # # * # # Horrible link that reveals how this is done: # # * # # How this works: # # * I code live in an R script locally. I save often. # * This file lives in a directory synced to Dropbox. # * You open the DropBox file at and refresh # as needed. # * Should allow you to see, copy, paste everything I've typed and save the # entire transcript at the end. This file is highly perishable, so save your # own copy if you want it. # * Every now and then the refresh won't work. Just re-open from from the # andhs.co link: # # (idea borrowed from Jenny Bryan: https://github.com/jennybc/2018-09_purrr-latinr) library(tidyverse) fake_survey <- read_csv("https://andhs.co/fakesurvey") survey_summarized <- fake_survey %>% count(response) %>% mutate(response = factor(response, levels = c("Strongly disagree", "Disagree", "Neither agree nor disagree", "Agree", "Strongly agree"), ordered = TRUE)) %>% arrange(response) %>% mutate(prop = n / sum(n)) # Bar plot my_super_cool_plot <- ggplot(survey_summarized, aes(x = response, y = prop, fill = response)) + geom_col() + geom_label(aes(label = n), fill = "white") + guides(fill = FALSE) + labs(x = NULL, y = "Percent", title = "Some really cool title", subtitle = "Stuff goes here", caption = "By me; source: my head") + scale_fill_manual(values = c("grey13", "blue", "#dc2178", "yellow", "orange")) + theme_minimal(base_size = 11, base_family = "Papyrus") + theme(panel.grid.major.x = element_blank(), panel.grid.minor.y = element_blank(), plot.title = element_text(family = "Comic Sans MS")) my_super_cool_plot ggsave("plot.pdf", my_super_cool_plot, width = 6, height = 3, units = "in") ggsave("plot.png", my_super_cool_plot, width = 6, height = 3, units = "in") # Pie charts ggplot(survey_summarized, aes(x = "", y = prop, fill = response)) + geom_col() + theme_void() ggplot(survey_summarized, aes(x = "", y = prop, fill = response)) + geom_col() + coord_polar(theta = "y") + theme_void() # Waffle charts library(waffle) # https://github.com/hrbrmstr/waffle # Extract just the counts data_for_waffle <- survey_summarized$n # Add response names to the counts names(data_for_waffle) <- survey_summarized$response # Plot! waffle(data_for_waffle, rows = 5, size = 1, colors = c("red", "yellow", "blue", "orange", "green"), xlab = "1 square = 1 response") # Treemaps library(treemapify) # https://github.com/wilkox/treemapify ggplot(survey_summarized, aes(area = n, fill = response)) + geom_treemap() + guides(fill = FALSE) + geom_treemap_text(aes(label = response), colour = "white", place = "center", grow = TRUE)