Created
June 29, 2020 20:27
-
-
Save sastoudt/bf39917e4d3254649446a981287cd3ec to your computer and use it in GitHub Desktop.
looking into Tidy Tuesday Mystery
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(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