Skip to content

Instantly share code, notes, and snippets.

@sastoudt
Created June 29, 2020 20:27
Show Gist options
  • Save sastoudt/bf39917e4d3254649446a981287cd3ec to your computer and use it in GitHub Desktop.
Save sastoudt/bf39917e4d3254649446a981287cd3ec to your computer and use it in GitHub Desktop.
looking into Tidy Tuesday Mystery
library(dplyr)
library(ggplot2)
setwd("~/Desktop/tidytuesday/data/2020/2020-06-30")
comic_bechdel <- read.csv("comic_bechdel.csv", stringsAsFactors = F)
brks <- c(0, 0.25, 0.5, 0.75, 1)
dim(comic_bechdel) ## 308 9
comic_bechdel2 <- comic_bechdel %>%
filter(!is.na(pass_bechdel)) %>%
group_by(series) %>%
mutate(count = n()) %>%
group_by(series, pass_bechdel) %>%
summarise(count_group = n(), prop = count_group / count, percent = round(prop * 100))
dim(comic_bechdel2) ## 307 5 this doesn't seem right
ggplot(comic_bechdel2, aes(x = series, y = count_group, fill = pass_bechdel)) + geom_bar(position = "fill", stat = "identity") + scale_y_continuous(breaks = brks) + coord_flip()
comic_bechdel2b <- comic_bechdel %>%
filter(!is.na(pass_bechdel)) %>%
group_by(series) %>%
mutate(count = n()) %>%
group_by(series, pass_bechdel) %>%
summarise(count_group = n(), prop = count_group /count[1], percent = round(prop * 100))
## note count[1] all of count will be the same number within a group
dim(comic_bechdel2b) ## 13 5 this is what we expect
ggplot(comic_bechdel2b, aes(x = series, y = count_group, fill = pass_bechdel)) + geom_bar(position = "fill", stat = "identity") + scale_y_continuous(breaks = brks) + coord_flip() ## fixed!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment