├── 2021 ├── week-10 │ ├── 2021-03-08 09h-54m-22s superbowl.png │ ├── week-10-extra.R │ └── week-10.R ├── week-11 │ ├── 2021-03-14 09h-52m-41s bechdel.png │ └── week-11.R ├── week-12 │ ├── images │ │ ├── bg.jpg │ │ ├── cover.jpg │ │ └── portal-man.png │ ├── plots-no-bg │ │ ├── portal.png │ │ └── tx-sales.gif │ └── week-12.R ├── week-13 │ ├── 2021-03-27 22h-01m-10s un-votes.png │ └── wee-13.R ├── week-14 │ ├── make-up.png │ └── week-14.R ├── week-15 │ └── week-15.R ├── week-24 │ ├── week-24.R │ └── week-24.png ├── week-25 │ └── week-25.R ├── week-35 │ └── week-35.R ├── week-37 │ ├── code.png │ ├── code.svg │ ├── week-37.R │ └── week-37.png ├── week-38 │ ├── bottom.png │ ├── dimebag.jpg │ ├── dimebag1.jpg │ ├── final groove metal.png │ ├── final nu metal.png │ ├── final progressive metal.png │ ├── final speed metal.png │ ├── final thrash metal.png │ ├── final.png │ ├── final.svg │ ├── footnote text.png │ ├── korn.jpg │ ├── korn1.jpg │ ├── legend.png │ ├── megadeth.jpg │ ├── megadeth1.jpg │ ├── metal.png │ ├── metal.svg │ ├── metallica.jpg │ ├── slayer.jpg │ ├── title text s.jpg │ ├── title text.png │ ├── tool.jpg │ ├── tool1.jpg │ ├── tool2.jpg │ └── week-38.R ├── week-39 │ ├── code.png │ ├── emmy.png │ ├── emmys-6.png │ ├── emmys-logo - Copy.png │ ├── emmys-logo-r.png │ ├── emmys-logo.png │ ├── emmys-text-logo.png │ ├── emmys.png │ └── week-39.R ├── week-40 │ ├── code.png │ ├── week-40.R │ ├── week-40.png │ └── week-40a.R ├── week-41 │ ├── code.png │ ├── final.png │ ├── legend.png │ ├── nurses.png │ └── week-41.R ├── week-42 │ ├── code.png │ ├── fish.R │ └── fish.png ├── week-5 │ └── week-5.R ├── week-6 │ ├── hbcu-065.png │ └── week-6.R ├── week-7 │ ├── income.png │ └── week-7.R ├── week-8 │ ├── palette.png │ ├── slave-016.png │ └── week-8.R └── week-9 │ ├── earn-20210228-141437.png │ └── week-9.R ├── 2022 ├── week02-bees │ ├── bees.R │ └── bees.png ├── week03-chocolate │ ├── chocolate.R │ └── chocolate.png ├── week08-freedom │ ├── freedom.R │ ├── freedom.png │ └── log.txt ├── week09-energy │ ├── energy.R │ ├── energy.png │ └── lightning-bolt.png ├── week10-erasmus │ ├── erasmus.R │ └── erasmus.png ├── week12-babynames │ ├── babynames.R │ └── babynames.png ├── week13-sports │ ├── sports.R │ └── sports.png ├── week14-news │ ├── log-posted.txt │ ├── log.txt │ ├── news.R │ └── news.png ├── week16-crossword │ ├── crossword.R │ ├── crossword.png │ ├── log-posted.txt │ └── log.txt ├── week17-kaggle │ ├── kaggle.R │ ├── kaggle.png │ ├── log-posted.txt │ └── log.txt ├── week18-renewables │ ├── log-posted.txt │ ├── log.txt │ ├── new.png │ ├── renewables.R │ └── renewables.png ├── week20-eurovision │ ├── eurovision.R │ ├── eurovision.png │ ├── eurovision1.png │ ├── log-posted.txt │ └── log.txt ├── week21-rugby │ ├── log-posted.txt │ ├── log.txt │ ├── rugby.R │ └── rugby.png ├── week22-polls │ ├── axios.csv │ ├── log-posted.txt │ ├── log.txt │ ├── poll.png │ ├── polls.R │ └── reputation.csv ├── week23-pride │ ├── log-posted.txt │ ├── log.txt │ ├── pride-legend.png │ ├── pride.R │ └── pride.png ├── week25-juneteenth │ ├── juneteenth.R │ ├── juneteenth.png │ ├── log-posted.txt │ └── log.txt ├── week27-san-fran-rents │ ├── CA_Counties │ │ ├── CA_Counties_TIGER2016.cpg │ │ ├── CA_Counties_TIGER2016.dbf │ │ ├── CA_Counties_TIGER2016.prj │ │ ├── CA_Counties_TIGER2016.sbn │ │ ├── CA_Counties_TIGER2016.sbx │ │ ├── CA_Counties_TIGER2016.shp │ │ ├── CA_Counties_TIGER2016.shp.xml │ │ └── CA_Counties_TIGER2016.shx │ ├── geo_export_3b286e07-2c69-479a-8452-b9acb0b14cfa.dbf │ ├── geo_export_3b286e07-2c69-479a-8452-b9acb0b14cfa.prj │ ├── geo_export_3b286e07-2c69-479a-8452-b9acb0b14cfa.shp │ ├── geo_export_3b286e07-2c69-479a-8452-b9acb0b14cfa.shx │ ├── log-posted.txt │ ├── log.txt │ ├── nhoods.shp │ ├── san-fran-rents.R │ └── sanfran.png ├── week28-flights │ ├── flights.R │ ├── flights.png │ ├── log-posted.txt │ └── log.txt ├── week29-tech │ ├── log-posted.txt │ ├── log.txt │ ├── tech.R │ └── tech.png ├── week31-frog │ ├── frog.R │ ├── frog.png │ ├── log-posted.txt │ └── log.txt ├── week32-ferriswheel │ ├── ferriswheel.R │ └── ferriswheel.png ├── week33-psychometrics │ ├── bb01.jpg │ ├── bb01d.jpg │ ├── bb02.jpg │ ├── bb02d.jpg │ ├── bb03.jpg │ ├── bb03d.jpg │ ├── bb04.jpg │ ├── bb04d.jpg │ ├── bb05.jpg │ ├── bb05d.jpg │ ├── bb06.jpg │ ├── bb06d.jpg │ ├── bb07.jpg │ ├── bb07d.jpg │ ├── bb08.jpg │ ├── bb08d.jpg │ ├── bb09.jpg │ ├── bb09d.jpg │ ├── bb10.jpg │ ├── bb10d.jpg │ ├── bb11.jpg │ ├── bb11d.jpg │ ├── bb12.jpg │ ├── bb12d.jpg │ ├── psychometrics Flynn White.png │ ├── psychometrics Gus Fring.png │ ├── psychometrics Hank Schrader.png │ ├── psychometrics Jane Margolis.png │ ├── psychometrics Jesse Pinkman.png │ ├── psychometrics Marie Schrader.png │ ├── psychometrics Mike Ehrmantraut.png │ ├── psychometrics Saul Goodman.png │ ├── psychometrics Skyler White.png │ ├── psychometrics Walter White.png │ └── psychometrics.R ├── week34-chips │ ├── chip.csv │ ├── chip.svg │ ├── chips.R │ └── chips.png ├── week36-lego │ ├── 1 lego.png │ ├── 2 lego.png │ ├── lego.R │ ├── lego.jpg │ ├── lego.png │ └── lego_cropped.png ├── week39-artists │ ├── artists-District of Columbia.png │ ├── artists-Nevada.png │ ├── artists-New York.png │ ├── artists-South Dakota.png │ ├── artists.R │ └── artists.png ├── week41-ravelry │ ├── ravelry.png │ ├── raverly.R │ ├── tute1.png │ ├── tute2.png │ └── tute3.png └── week42-stranger-things │ ├── eddie.jpg │ ├── stranger-things-title.jpg │ ├── stranger-things.R │ └── stranger-things.png ├── .gitignore ├── fonts ├── lego.zip └── lego │ └── Legothick.ttf ├── scripts └── startup.R └── tidyTuesday.Rproj /.gitignore: -------------------------------------------------------------------------------- 1 | .Rproj.user 2 | .Rhistory 3 | .RData 4 | .Ruserdata 5 | 2021/week-6/plots 6 | 2021/week-7/plots 7 | 2021/week-8/plots 8 | 2021/week-9/plots 9 | 2021/week-10/plots 10 | 2021/week-11/plots 11 | 2021/week-11/bond 12 | 2021/week-12/plots 13 | 2021/week-12/plots-no-bg 14 | 2021/week-12/for-gif 15 | 2021/week-13/plots 16 | -------------------------------------------------------------------------------- /2021/week-10/2021-03-08 09h-54m-22s superbowl.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/doehm/tidyTuesday/74fb84eee433ae1741e31857547909c6ce2c5240/2021/week-10/2021-03-08 09h-54m-22s superbowl.png -------------------------------------------------------------------------------- /2021/week-10/week-10-extra.R: -------------------------------------------------------------------------------- 1 | library(tidyverse) 2 | library(janitor) 3 | library(glue) 4 | library(survivoR) # devtools::install_github("doehm/survivoR") 5 | library(evoPalette) # devtools::install_github("doehm/evoPalette") 6 | library(rstanarm) 7 | library(snakecase) 8 | library(lubridate) 9 | library(ggtext) 10 | library(tidybayes) 11 | library(extrafont) 12 | extrafont::loadfonts(quiet = TRUE) 13 | 14 | #### helpers #### 15 | # there's probably a way better way to do this but I couldn't find it 16 | posterior_sims <- function(object, long = TRUE, ...) { 17 | nm <- names(object$coefficients) 18 | np <- length(nm) 19 | object$stanfit@sim$samples[[1]][1:np] %>% 20 | set_names(nm) %>% 21 | as_tibble() %>% 22 | clean_names() %>% 23 | mutate_at(vars(!contains("intercept")), ~.x + intercept) %>% 24 | mutate(iter = 1:n()) %>% 25 | # slice(100:1000) %>% 26 | {if(long) pivot_longer(., cols = -iter, names_to = "var", values_to = "beta") else .} 27 | } 28 | 29 | 30 | #### data #### 31 | tt <- tidytuesdayR::tt_load(2021, week = 10) 32 | df <- tt$youtube %>% 33 | mutate(likes_per_view = like_count/view_count) 34 | 35 | #### stan #### 36 | v <- c("funny", "show_product_quickly", "patriotic", "celebrity", "danger", "animals", "use_sex") 37 | dfxx <- df %>% 38 | mutate_if(is.logical, as.integer) %>% 39 | filter(likes_per_view > 0) %>% 40 | select(likes_per_view, brand, view_count, like_count, dislike_count, favorite_count, comment_count, v) %>% 41 | mutate( 42 | log_lpv = log(1000*likes_per_view), 43 | log_views = log(view_count), 44 | log_likes = log(like_count), 45 | log_dislike = log(dislike_count), 46 | log_favourite = log(favorite_count), 47 | log_comment = log(comment_count) 48 | ) 49 | 50 | mod <- stan_glm( 51 | log_lpv ~ funny + show_product_quickly + patriotic + celebrity + danger + animals + use_sex, 52 | iter = 2000, 53 | warmup = 1000, 54 | data = dfxx 55 | ) 56 | 57 | mod_views <- stan_lmer( 58 | log_views ~ funny + show_product_quickly + patriotic + celebrity + danger + animals + use_sex + (1 | brand), 59 | iter = 2000, 60 | warmup = 1000, 61 | data = dfxx 62 | ) 63 | plot(mod_views) 64 | 65 | beta_df <- posterior_sims(mod) 66 | beta_df_view <- posterior_sims(mod_views) 67 | 68 | # beta_df <- beta_df %>% 69 | # mutate(model = "lpv") %>% 70 | # bind_rows( 71 | # beta_df_view %>% 72 | # mutate(model = "views") 73 | # ) 74 | 75 | 76 | mod <- stan_lmer( 77 | log_lpv ~ funny + show_product_quickly + patriotic + celebrity + danger + animals + use_sex + (1 | brand), 78 | iter = 2000, 79 | warmup = 1000, 80 | data = dfxx 81 | ) 82 | plot(mod) 83 | 84 | recover_types(mod) 85 | 86 | mod %>% 87 | spread_draws(funny, patriotic, celebrity) %>% 88 | pivot_longer(cols = c(funny, patriotic, celebrity), names_to = "var", values_to = "draw") %>% 89 | ggplot(aes(x = draw, y = var)) + 90 | stat_dots() 91 | 92 | 93 | 94 | posterior_sims(mod) %>% 95 | filter(str_detect(var, "b_inter")) %>% 96 | group_by(var) %>% 97 | summarise(beta = median(beta)) %>% 98 | arrange(beta) 99 | 100 | dfxx %>% 101 | group_by(brand) %>% 102 | summarise(beta = mean(log_lpv) - 1.14) %>% 103 | arrange(beta) 104 | 105 | 106 | strip_vars <- mod$coefficients %>% 107 | names() %>% 108 | to_snake_case() 109 | strip_vars <- strip_vars[str_detect(strip_vars, "b_inter")] 110 | strip_titles <- c("Bud Light", "Budweiser", "Coca Cola", "Doritos", "E-Trade", "Hynudai", "Kia", "NFL", "Pepsi", "Toyota") 111 | names(strip_titles) <- strip_vars 112 | 113 | as_tibble(mod) %>% 114 | clean_names() %>% 115 | pivot_longer(everything()) %>% 116 | filter(str_detect(name, "b_inter")) %>% 117 | ggplot(aes(x = value, fill = name)) + 118 | geom_density() + 119 | facet_wrap(~ name, ncol = 10, labeller = labeller(name = strip_titles)) + 120 | coord_flip() + 121 | scale_fill_discrete(name = "name", labels = strip_titles) + 122 | theme_minimal() + 123 | theme( 124 | legend.position = "bottom" 125 | ) 126 | 127 | as_tibble(mod) %>% 128 | clean_names() %>% 129 | pivot_longer(everything()) %>% 130 | group_by(name) %>% 131 | summarise(median = median(value)) %>% 132 | filter(str_detect(name, "b_inter")) %>% 133 | ggplot(aes(x = name, y = median, fill = name)) + 134 | geom_bar(stat = "identity") + 135 | scale_fill_survivor(25) + 136 | theme_minimal() 137 | 138 | 139 | mod_views <- stan_glm( 140 | log_views ~ funny + show_product_quickly + patriotic + celebrity + danger + animals + use_sex, 141 | iter = 2000, 142 | warmup = 1000, 143 | data = dfxx 144 | ) 145 | 146 | mod_likes <- stan_glm( 147 | log_likes ~ funny + show_product_quickly + patriotic + celebrity + danger + animals + use_sex, 148 | iter = 2000, 149 | warmup = 1000, 150 | data = dfxx 151 | ) 152 | 153 | mod_dislike <- stan_glm( 154 | log_dislike ~ funny + show_product_quickly + patriotic + celebrity + danger + animals + use_sex, 155 | iter = 2000, 156 | warmup = 1000, 157 | data = filter(dfxx, is.finite(log_dislike)) 158 | ) 159 | 160 | as_tibble(mod_views) %>% 161 | mutate(model = "views") %>% 162 | bind_rows(as_tibble(mod_likes) %>% mutate(model = "likes")) %>% 163 | bind_rows(as_tibble(mod_dislike) %>% mutate(model = "dislikes")) %>% 164 | clean_names %>% 165 | select(-intercept, -sigma) %>% 166 | pivot_longer(cols = -model, names_to = "var", values_to = "beta") %>% 167 | group_by(model, var) %>% 168 | summarise(median = median(beta)) %>% 169 | ggplot(aes(x = var, y = median, fill = var)) + 170 | geom_bar(stat = "identity") + 171 | facet_wrap(~ model, ncol = 1) + 172 | scale_fill_survivor(25) + 173 | theme_minimal() + 174 | theme( 175 | axis.text.x = element_text(angle = 90) 176 | ) 177 | -------------------------------------------------------------------------------- /2021/week-11/2021-03-14 09h-52m-41s bechdel.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/doehm/tidyTuesday/74fb84eee433ae1741e31857547909c6ce2c5240/2021/week-11/2021-03-14 09h-52m-41s bechdel.png -------------------------------------------------------------------------------- /2021/week-12/images/bg.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/doehm/tidyTuesday/74fb84eee433ae1741e31857547909c6ce2c5240/2021/week-12/images/bg.jpg -------------------------------------------------------------------------------- /2021/week-12/images/cover.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/doehm/tidyTuesday/74fb84eee433ae1741e31857547909c6ce2c5240/2021/week-12/images/cover.jpg -------------------------------------------------------------------------------- /2021/week-12/images/portal-man.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/doehm/tidyTuesday/74fb84eee433ae1741e31857547909c6ce2c5240/2021/week-12/images/portal-man.png -------------------------------------------------------------------------------- /2021/week-12/plots-no-bg/ portal.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/doehm/tidyTuesday/74fb84eee433ae1741e31857547909c6ce2c5240/2021/week-12/plots-no-bg/ portal.png -------------------------------------------------------------------------------- /2021/week-12/plots-no-bg/tx-sales.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/doehm/tidyTuesday/74fb84eee433ae1741e31857547909c6ce2c5240/2021/week-12/plots-no-bg/tx-sales.gif -------------------------------------------------------------------------------- /2021/week-13/2021-03-27 22h-01m-10s un-votes.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/doehm/tidyTuesday/74fb84eee433ae1741e31857547909c6ce2c5240/2021/week-13/2021-03-27 22h-01m-10s un-votes.png -------------------------------------------------------------------------------- /2021/week-14/make-up.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/doehm/tidyTuesday/74fb84eee433ae1741e31857547909c6ce2c5240/2021/week-14/make-up.png -------------------------------------------------------------------------------- /2021/week-14/week-14.R: -------------------------------------------------------------------------------- 1 | # week 13 2 | library(tidyverse) 3 | library(janitor) 4 | library(glue) 5 | library(extrafont) 6 | library(cowplot) 7 | library(ggforce) 8 | library(patchwork) 9 | library(ggtext) 10 | extrafont::loadfonts(quiet = TRUE) 11 | 12 | font_import("") 13 | 14 | #### data #### 15 | tt <- tidytuesdayR::tt_load(2021, week = 14) 16 | tt 17 | 18 | a <- 0.9 19 | b <- 0.45 20 | df <- tt$allShades %>% 21 | filter(hue < 50) %>% 22 | group_by(brand) %>% 23 | summarise( 24 | n = n(), 25 | hue = sd(hue), 26 | sat = sd(sat), 27 | lightness = sd(lightness) 28 | ) %>% 29 | filter(n >= 30) %>% 30 | arrange(desc(hue)) %>% 31 | ungroup() %>% 32 | mutate( 33 | huec = floor(hue/max(hue)*20), 34 | lightc = floor(lightness/max(lightness)*20), 35 | huec_end = huec + a, 36 | lightc_end = lightc + a 37 | ) 38 | 39 | n <- df %>% 40 | count(huec, lightc) 41 | 42 | 43 | df1 <- df %>% 44 | distinct(huec, lightc) %>% 45 | arrange(huec, lightc) %>% 46 | mutate(id = 1:n()) 47 | 48 | df <- df %>% 49 | left_join(df1) 50 | 51 | #### colours #### 52 | bg <- "#c38e70" 53 | font <- "grey10" 54 | 55 | #### fonts #### 56 | ft <- "Amatic" 57 | ftc <- "Amatic SC" 58 | 59 | #### palettes #### 60 | make_palette <- function(.brand, n = 6, a = 0, hex = FALSE) { 61 | 62 | pal_df <- tt$allShades %>% 63 | filter(hue < 50) %>% 64 | filter(brand == .brand) 65 | 66 | fills <- colorRampPalette(sort(pal_df$hex))(n) 67 | 68 | df <- pal_df %>% 69 | mutate( 70 | x = (1:n()) + a, 71 | xend = x+1, 72 | y = 0, 73 | yend = 1, 74 | huec = 10, 75 | lightc = 10 76 | ) %>% 77 | filter(x <= n + a) 78 | # ggplot() + 79 | # geom_rect(aes(xmin = x, xmax = xend, ymin = y, ymax = yend), fill = fills) + 80 | # theme_void() 81 | 82 | list( 83 | data = df, 84 | pal = fills 85 | ) 86 | 87 | } 88 | 89 | 90 | #### plot #### 91 | main <- df %>% 92 | ggplot(aes(x = huec, y = lightc)) + 93 | geom_hline(yintercept = 13, colour = "grey10", linetype = 2) + 94 | geom_vline(xintercept = 14, colour = "grey10", linetype = 2) + 95 | geom_rect(aes(xmin = huec, xmax = huec_end, ymin = lightc, ymax = lightc_end), fill = "white", colour = font) + 96 | geom_text(data = df, mapping = aes(huec+b, lightc+b, label = id), family = ft, size = 8, colour = font) + 97 | geom_text(aes(x = 21, y = 21, label = str_wrap("High variation in hue and lightness", 20)), family = ftc, size = 5, lineheight = 0.8) + 98 | geom_text(aes(x = 21, y = 6, label = str_wrap("High variation in hue", 20)), family = ftc, size = 5, lineheight = 0.8) + 99 | geom_text(aes(x = 5, y = 21, label = str_wrap("High variation in lightness", 20)), family = ftc, size = 5, lineheight = 0.8) + 100 | geom_text(aes(x = 5, y = 6, label = str_wrap("Low variation in hue and lightness", 20)), family = ftc, size = 5, lineheight = 0.8) + 101 | # geom_rect(data = cl$data, mapping = aes(xmin = x, xmax = xend, ymin = 15, ymax = 15.9), fill = cl$pal) + 102 | # geom_text(data = n, mapping = aes(27.5, 15+b, label = "Clinique"), family = ft, size = 8, colour = font, hjust = 1) + 103 | # scale_fill_gradientn(colours = pals[[1]]) + 104 | theme_void() + 105 | theme( 106 | text = element_text(family = ft, colour = font), 107 | plot.title = element_text(family = ft, size = 36), 108 | plot.background = element_rect(fill = bg, colour = NA), 109 | # axis.text = element_text(size = 16), 110 | # axis.title = element_text(size = 22), 111 | plot.margin = margin(t = 30, b = 30, l = 30, r = 30), 112 | # axis.title.y = element_text(angle = 90) 113 | ) + 114 | labs( 115 | x = "variation in Hue", 116 | y = "variation in Lightness" 117 | ) + 118 | coord_cartesian(clip = "off") 119 | 120 | g_title <- ggplot() + 121 | geom_text(aes(x = 0, y = 1, label = str_wrap("Anastasia Beverly Hills, Morphe and Maybelline all have high variation in Lightness and hue", 20)), family = ft, size = 13, lineheight = 0.8, hjust = 0) + 122 | geom_text(aes(x = 0, y = 0, label = str_wrap("The variation in hue and lightenss was calculated for each brand with more than 30 colours. Those in the top right hand corner have high variation in both lightness and hue, therefore covering more of the spectrum", 35)), family = ftc, size = 7, lineheight = 0.8, hjust = 0) + 123 | theme_void() + 124 | theme( 125 | plot.background = element_rect(fill = bg, colour = NA), 126 | text = element_text(family = ft, colour = font), 127 | plot.margin = margin(t = 30, b = 10, l = 30, r = 10) 128 | ) + 129 | xlim(c(0, 1)) + 130 | coord_cartesian(clip = "off") + 131 | ylim(c(-0.5, 1.5)) 132 | 133 | g_legend <- df %>% 134 | arrange(id) %>% 135 | mutate( 136 | y = (1:68 - 1) %% 23 + 1, 137 | x = cumsum(y == 1) 138 | ) %>% 139 | ggplot(aes(x, -y, label = paste(id, " ", brand))) + 140 | geom_text(family = ft, size = 7, colour = font, hjust = 0) + 141 | theme_void() + 142 | theme( 143 | plot.background = element_rect(fill = bg, colour = NA), 144 | text = element_text(family = ft, colour = font), 145 | plot.margin = margin(t = 30, b = 10, l = 30, r = 10) 146 | ) + 147 | xlim(c(1, 4)) 148 | 149 | g_title + 150 | main + 151 | g_legend + 152 | plot_layout(widths = c(1, 2, 3)) + 153 | ggsave("./2021/week-14/make-up.png", height = 8, width = 21, dpi = 600) 154 | 155 | -------------------------------------------------------------------------------- /2021/week-15/week-15.R: -------------------------------------------------------------------------------- 1 | # week 13 2 | library(tidyverse) 3 | library(janitor) 4 | library(glue) 5 | library(extrafont) 6 | library(patchwork) 7 | library(ggtext) 8 | extrafont::loadfonts(quiet = TRUE) 9 | 10 | #### data #### 11 | tt <- tidytuesdayR::tt_load(2021, week = 15) 12 | tt 13 | 14 | tt$brazil_loss %>% 15 | pivot_longer(cols = c(-entity, -code, -year), names_to = "type", values_to = "loss") %>% 16 | mutate(type1 = fct_lump(type, 4, w = loss)) %>% 17 | group_by(year, type1) %>% 18 | summarise(loss = sum(loss)) %>% 19 | mutate( 20 | c_loss = cumsum(loss), 21 | max_c_loss = max(c_loss) 22 | ) %>% 23 | ggplot(aes(x = year, y = loss, fill = type1)) + 24 | # geom_bar(stat = "identity") 25 | # geom_bump() + 26 | as_reference( 27 | geom_text(aes(y = max_c_loss, label = year), hjust = 0.5, size = 12), 28 | id = "text" 29 | ) + 30 | with_blend( 31 | geom_bar(stat = "identity"), 32 | bg_layer = "text", 33 | blend_type = "xor" 34 | ) 35 | 36 | tt$forest %>% 37 | group_by(year) %>% 38 | summarise(total = sum(net_forest_conversion)) 39 | 40 | -------------------------------------------------------------------------------- /2021/week-24/week-24.R: -------------------------------------------------------------------------------- 1 | # tidy tuesday week 24 2 | 3 | library(tidyverse) 4 | library(janitor) 5 | library(glue) 6 | library(extrafont) 7 | library(ggtext) 8 | library(forcats) 9 | library(ggfx) 10 | extrafont::loadfonts(quiet = TRUE) 11 | 12 | 13 | # data load --------------------------------------------------------------- 14 | 15 | data <- tidytuesdayR::tt_load(2021, week = 24) 16 | 17 | df <- data$stocked |> 18 | clean_names() 19 | 20 | 21 | # palette ----------------------------------------------------------------- 22 | 23 | bg <- "#3d405b" 24 | tx <- "#f4f1de" 25 | pal1 <- c("#788FCE", "#e07a5f", "#f2cc8f", "#81b29a", "#f4f1de") 26 | 27 | 28 | # fonts ------------------------------------------------------------------- 29 | 30 | ft <- "Gill Sans MT" 31 | ftb <- "Gill Sans Ultra Bold" 32 | 33 | 34 | # species dot plot -------------------------------------------------------- 35 | 36 | df |> 37 | mutate( 38 | species = fct_lump(species, 7), 39 | lake = fct_lump(lake, 2), 40 | ) |> 41 | filter( 42 | !is.na(weight), 43 | !is.na(length), 44 | species != "Other", 45 | lake != "Other" 46 | ) |> 47 | mutate( 48 | weight = log(weight), 49 | length = log(length) 50 | ) |> 51 | ggplot(aes(x = species, y = length, colour = species, fill = species)) + 52 | ggdist::stat_halfeye( 53 | adjust = .5, 54 | width = 1, 55 | .width = 0, 56 | justification = -.3, 57 | point_colour = NA, 58 | alpha = 0.7 59 | ) + 60 | geom_boxplot( 61 | width = .25, 62 | outlier.shape = NA 63 | ) + 64 | geom_point( 65 | size = 1.3, 66 | alpha = .05, 67 | position = position_jitter( 68 | seed = 1, width = .1 69 | ) 70 | ) + 71 | facet_wrap(~lake, ncol = 2) + 72 | scale_colour_manual(values = colorRampPalette(pal1)(7)) + 73 | scale_fill_manual(values = colorRampPalette(pal1)(7)) + 74 | coord_flip() + 75 | theme_void() + 76 | theme( 77 | plot.background = element_rect(fill = bg), 78 | text = element_text(colour = tx) 79 | ) 80 | 81 | 82 | # wrangling --------------------------------------------------------------- 83 | 84 | text <- tibble( 85 | x = 7.5, 86 | y = 0.25, 87 | species = c("BNT", "CHS", "LAT", "RBT"), 88 | lake = NA 89 | ) 90 | 91 | df_wt <- df |> 92 | filter(lake %in% c("ER", "HU", "MI", "ON", "SU")) |> 93 | mutate(species = fct_lump(species, 4)) |> 94 | filter( 95 | !is.na(weight), 96 | !is.na(length), 97 | species != "Other", 98 | lake != "Other" 99 | ) |> 100 | mutate( 101 | weight = log(weight), 102 | length = log(length) 103 | ) 104 | 105 | df_median <- df_wt |> 106 | group_by(species, lake) |> 107 | summarise( 108 | weight = round(median(weight), 1) 109 | ) |> 110 | mutate( 111 | y = -0.1, 112 | y_text = as.numeric(as.factor(lake))/10+0.25 113 | ) 114 | 115 | 116 | # histogram --------------------------------------------------------------- 117 | 118 | df_wt |> 119 | ggplot(aes(x = weight, colour = NA, fill = lake)) + 120 | as_reference( 121 | geom_density(alpha = 0.8), 122 | id = "density" 123 | ) + 124 | with_blend( 125 | geom_text(aes(x+1, y-0.15, label = species), data = text, size = 12, colour = "white", family = ftb), 126 | bg_layer = "density", 127 | blend_type = "xor" 128 | ) + 129 | geom_point(aes(x = weight, y = y, colour = lake), data = df_median, size = 6) + 130 | # geom_text(aes(x = weight, y = y, label = as.character(round(exp(weight)))), data = df_median, size = 2, angle = 90, colour = bg) + 131 | facet_wrap(~species, ncol = 2) + 132 | scale_colour_manual(values = pal1) + 133 | scale_fill_manual(values = pal1) + 134 | theme_void() + 135 | theme( 136 | plot.background = element_rect(fill = bg), 137 | text = element_text(colour = tx, family = ftb), 138 | strip.text = element_blank(), 139 | legend.position = "none", 140 | plot.title = element_markdown(family = ft, face = "bold", hjust = 0.5, margin = margin(t = 20, l= 150, r = 100)), 141 | plot.subtitle = element_markdown(family = ft, face = "bold", hjust = 0.5, margin = margin(b = 20, l= 150, r = 100)), 142 | plot.caption = element_markdown(family = ft, face = "bold"), 143 | plot.margin = margin(r = 75, b = 10) 144 | ) + 145 | labs( 146 | fill = "Lake", 147 | title = glue("E R I E H U R O N M I C H I G A N
O N T A R I O S U P E R I O R"), 148 | subtitle = "Distribution of the weight of fish species (log scale) within the Great Lakes. Fish tend to be the largest in Lake Huron with
the exception of Brown Trout in Lake Ontario. Median value shown as the dot underneath the denisty.", 149 | caption = "Source: Great Lakes Fishery Commission / Graphic: @danoehm" 150 | ) + 151 | xlim(c(2.5, 9)) + 152 | coord_cartesian(clip = "off") + 153 | ggsave("./2021/week-24/week-24.png", width = 12, heigh = 7) 154 | 155 | -------------------------------------------------------------------------------- /2021/week-24/week-24.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/doehm/tidyTuesday/74fb84eee433ae1741e31857547909c6ce2c5240/2021/week-24/week-24.png -------------------------------------------------------------------------------- /2021/week-25/week-25.R: -------------------------------------------------------------------------------- 1 | # week 25 2 | 3 | library(tidyverse) 4 | library(janitor) 5 | library(glue) 6 | library(extrafont) 7 | library(ggtext) 8 | library(forcats) 9 | library(ggfx) 10 | extrafont::loadfonts(quiet = TRUE) 11 | 12 | 13 | # data load --------------------------------------------------------------- 14 | 15 | data <- tidytuesdayR::tt_load(2021, week = 25) 16 | 17 | df <- data$tweets 18 | 19 | summary(df) 20 | 21 | df |> 22 | count(url) 23 | -------------------------------------------------------------------------------- /2021/week-35/week-35.R: -------------------------------------------------------------------------------- 1 | library(tidyverse) 2 | library(janitor) 3 | library(glue) 4 | library(extrafont) 5 | library(patchwork) 6 | library(ggtext) 7 | extrafont::loadfonts(quiet = TRUE) 8 | 9 | #### data #### 10 | tt <- tidytuesdayR::tt_load(2021, week = 35) 11 | tt 12 | 13 | lemurs <- readr::read_csv('https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2021/2021-08-24/lemur_data.csv') 14 | -------------------------------------------------------------------------------- /2021/week-37/code.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/doehm/tidyTuesday/74fb84eee433ae1741e31857547909c6ce2c5240/2021/week-37/code.png -------------------------------------------------------------------------------- /2021/week-37/week-37.R: -------------------------------------------------------------------------------- 1 | 2 | # week 37 ----------------------------------------------------------------- 3 | 4 | library(tidyverse) 5 | library(extrafont) 6 | library(ggtext) 7 | extrafont::loadfonts(quiet = TRUE) 8 | 9 | # data -------------------------------------------------------------------- 10 | 11 | tt <- tidytuesdayR::tt_load(2021, week = 37) 12 | 13 | # wrangle ----------------------------------------------------------------- 14 | 15 | results <- tt$results |> 16 | select(raceId, driverId, positionOrder) 17 | 18 | drivers <- tt$drivers |> 19 | select(driverId, forename, surname) 20 | 21 | df <- tt$pit_stops |> 22 | left_join(results, by = c("raceId", "driverId")) |> 23 | left_join(drivers, by = "driverId") |> 24 | filter(milliseconds < 500000) |> 25 | mutate(hamilton = driverId == 1) 26 | 27 | df_hamilton_text = tibble( 28 | x = 11.25, 29 | y = c(4, 6), 30 | label = c("Hamilton", "The rest") 31 | ) 32 | 33 | x <- c(15, 20, 30, 50, 100) 34 | 35 | # palette and fonts ------------------------------------------------------- 36 | 37 | pal <- c("black", rgb(255, 35, 28, maxColorValue = 255)) 38 | 39 | ftb <- "Verdana Pro Black" 40 | ft <- "Verdana Pro Light" 41 | 42 | # the plot ---------------------------------------------------------------- 43 | 44 | df |> 45 | filter(!hamilton) |> 46 | ggplot(aes(x = log(milliseconds), y = -positionOrder)) + 47 | geom_point(pch = 92, size = 6, alpha = 0.6) + 48 | geom_point(aes(x = log(milliseconds), y = -positionOrder), filter(df, hamilton), colour = pal[2], pch = 92, size = 6) + 49 | geom_text(aes(x, -y, label = label), df_hamilton_text, colour = rev(pal), size = 10, family = ftb, fontface = "italic", hjust = 0) + 50 | theme_void() + 51 | theme( 52 | plot.title = element_markdown(family = ftb, hjust = 0.5, size = 24, face = "italic"), 53 | axis.title.x = element_text(family = ft, margin = margin(t = 10, b = 5)), 54 | axis.text = element_text(family = ft, margin = margin(l = 10)), 55 | legend.position = "none", 56 | plot.margin = margin(l = 10, r = 10, b = 10, t = 10), 57 | plot.caption = element_text(family = ft) 58 | ) + 59 | scale_colour_manual(values = pal) + 60 | scale_y_continuous(breaks = c(-1, -5, -10, -15, -20), labels = c("First", "5th", "10th", "15th", "20th")) + 61 | scale_x_continuous(breaks = log(x*1000), labels = x) + 62 | labs( 63 | title = glue("F1 Faster pit stops may convert to better positions"), 64 | x = "Pit stop duration (seconds / log scale)", 65 | caption = "@danoehm" 66 | ) + 67 | ggsave("./2021/week-37/week-37.png", height = 8, width = 16) 68 | -------------------------------------------------------------------------------- /2021/week-37/week-37.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/doehm/tidyTuesday/74fb84eee433ae1741e31857547909c6ce2c5240/2021/week-37/week-37.png -------------------------------------------------------------------------------- /2021/week-38/bottom.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/doehm/tidyTuesday/74fb84eee433ae1741e31857547909c6ce2c5240/2021/week-38/bottom.png -------------------------------------------------------------------------------- /2021/week-38/dimebag.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/doehm/tidyTuesday/74fb84eee433ae1741e31857547909c6ce2c5240/2021/week-38/dimebag.jpg -------------------------------------------------------------------------------- /2021/week-38/dimebag1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/doehm/tidyTuesday/74fb84eee433ae1741e31857547909c6ce2c5240/2021/week-38/dimebag1.jpg -------------------------------------------------------------------------------- /2021/week-38/final groove metal.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/doehm/tidyTuesday/74fb84eee433ae1741e31857547909c6ce2c5240/2021/week-38/final groove metal.png -------------------------------------------------------------------------------- /2021/week-38/final nu metal.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/doehm/tidyTuesday/74fb84eee433ae1741e31857547909c6ce2c5240/2021/week-38/final nu metal.png -------------------------------------------------------------------------------- /2021/week-38/final progressive metal.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/doehm/tidyTuesday/74fb84eee433ae1741e31857547909c6ce2c5240/2021/week-38/final progressive metal.png -------------------------------------------------------------------------------- /2021/week-38/final speed metal.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/doehm/tidyTuesday/74fb84eee433ae1741e31857547909c6ce2c5240/2021/week-38/final speed metal.png -------------------------------------------------------------------------------- /2021/week-38/final thrash metal.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/doehm/tidyTuesday/74fb84eee433ae1741e31857547909c6ce2c5240/2021/week-38/final thrash metal.png -------------------------------------------------------------------------------- /2021/week-38/final.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/doehm/tidyTuesday/74fb84eee433ae1741e31857547909c6ce2c5240/2021/week-38/final.png -------------------------------------------------------------------------------- /2021/week-38/final.svg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/doehm/tidyTuesday/74fb84eee433ae1741e31857547909c6ce2c5240/2021/week-38/final.svg -------------------------------------------------------------------------------- /2021/week-38/footnote text.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/doehm/tidyTuesday/74fb84eee433ae1741e31857547909c6ce2c5240/2021/week-38/footnote text.png -------------------------------------------------------------------------------- /2021/week-38/korn.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/doehm/tidyTuesday/74fb84eee433ae1741e31857547909c6ce2c5240/2021/week-38/korn.jpg -------------------------------------------------------------------------------- /2021/week-38/korn1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/doehm/tidyTuesday/74fb84eee433ae1741e31857547909c6ce2c5240/2021/week-38/korn1.jpg -------------------------------------------------------------------------------- /2021/week-38/legend.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/doehm/tidyTuesday/74fb84eee433ae1741e31857547909c6ce2c5240/2021/week-38/legend.png -------------------------------------------------------------------------------- /2021/week-38/megadeth.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/doehm/tidyTuesday/74fb84eee433ae1741e31857547909c6ce2c5240/2021/week-38/megadeth.jpg -------------------------------------------------------------------------------- /2021/week-38/megadeth1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/doehm/tidyTuesday/74fb84eee433ae1741e31857547909c6ce2c5240/2021/week-38/megadeth1.jpg -------------------------------------------------------------------------------- /2021/week-38/metal.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/doehm/tidyTuesday/74fb84eee433ae1741e31857547909c6ce2c5240/2021/week-38/metal.png -------------------------------------------------------------------------------- /2021/week-38/metallica.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/doehm/tidyTuesday/74fb84eee433ae1741e31857547909c6ce2c5240/2021/week-38/metallica.jpg -------------------------------------------------------------------------------- /2021/week-38/slayer.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/doehm/tidyTuesday/74fb84eee433ae1741e31857547909c6ce2c5240/2021/week-38/slayer.jpg -------------------------------------------------------------------------------- /2021/week-38/title text s.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/doehm/tidyTuesday/74fb84eee433ae1741e31857547909c6ce2c5240/2021/week-38/title text s.jpg -------------------------------------------------------------------------------- /2021/week-38/title text.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/doehm/tidyTuesday/74fb84eee433ae1741e31857547909c6ce2c5240/2021/week-38/title text.png -------------------------------------------------------------------------------- /2021/week-38/tool.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/doehm/tidyTuesday/74fb84eee433ae1741e31857547909c6ce2c5240/2021/week-38/tool.jpg -------------------------------------------------------------------------------- /2021/week-38/tool1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/doehm/tidyTuesday/74fb84eee433ae1741e31857547909c6ce2c5240/2021/week-38/tool1.jpg -------------------------------------------------------------------------------- /2021/week-38/tool2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/doehm/tidyTuesday/74fb84eee433ae1741e31857547909c6ce2c5240/2021/week-38/tool2.jpg -------------------------------------------------------------------------------- /2021/week-39/code.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/doehm/tidyTuesday/74fb84eee433ae1741e31857547909c6ce2c5240/2021/week-39/code.png -------------------------------------------------------------------------------- /2021/week-39/emmy.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/doehm/tidyTuesday/74fb84eee433ae1741e31857547909c6ce2c5240/2021/week-39/emmy.png -------------------------------------------------------------------------------- /2021/week-39/emmys-6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/doehm/tidyTuesday/74fb84eee433ae1741e31857547909c6ce2c5240/2021/week-39/emmys-6.png -------------------------------------------------------------------------------- /2021/week-39/emmys-logo - Copy.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/doehm/tidyTuesday/74fb84eee433ae1741e31857547909c6ce2c5240/2021/week-39/emmys-logo - Copy.png -------------------------------------------------------------------------------- /2021/week-39/emmys-logo-r.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/doehm/tidyTuesday/74fb84eee433ae1741e31857547909c6ce2c5240/2021/week-39/emmys-logo-r.png -------------------------------------------------------------------------------- /2021/week-39/emmys-logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/doehm/tidyTuesday/74fb84eee433ae1741e31857547909c6ce2c5240/2021/week-39/emmys-logo.png -------------------------------------------------------------------------------- /2021/week-39/emmys-text-logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/doehm/tidyTuesday/74fb84eee433ae1741e31857547909c6ce2c5240/2021/week-39/emmys-text-logo.png -------------------------------------------------------------------------------- /2021/week-39/emmys.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/doehm/tidyTuesday/74fb84eee433ae1741e31857547909c6ce2c5240/2021/week-39/emmys.png -------------------------------------------------------------------------------- /2021/week-39/week-39.R: -------------------------------------------------------------------------------- 1 | # week 37 ----------------------------------------------------------------- 2 | 3 | library(tidyverse) 4 | library(glue) 5 | library(ggtext) 6 | library(showtext) 7 | library(ggfx) 8 | 9 | # data -------------------------------------------------------------------- 10 | 11 | tt <- tidytuesdayR::tt_load(2021, week = 39) 12 | 13 | nom <- tt$nominees |> 14 | mutate(distributor = case_when( 15 | str_detect(distributor, "CBS") ~ "CBS", 16 | str_detect(distributor, "National Geo") ~ "National Geographic", 17 | str_detect(distributor, "Disney") ~ "Disney", 18 | str_detect(distributor, "NBC") ~ "NBC", 19 | str_detect(distributor, "HBO") ~ "HBO", 20 | TRUE ~ distributor) 21 | ) 22 | 23 | top_distributors <- nom |> 24 | count(distributor) |> 25 | slice_max(n, n = 48, with_ties = FALSE) |> 26 | pull(distributor) 27 | 28 | df <- expand_grid(distributor = top_distributors, type = c("Winner", "Nominee")) |> 29 | left_join(nom, by = c("distributor", "type")) |> 30 | count(distributor, type) 31 | 32 | # fonts and palettes ------------------------------------------------------ 33 | 34 | font_add_google("Bebas Neue", "bebas") 35 | showtext_auto() 36 | 37 | gold <- rgb(243, 175, 20, maxColorValue = 255) 38 | brown <- rgb(124, 95, 56, maxColorValue = 255) 39 | 40 | # text -------------------------------------------------------------------- 41 | 42 | title_text <- "N O M I N E E SW I N N E R S" 43 | 44 | subtitle_text <- "The proportion of Emmy nominees and winners are shown for the 48 largest distributors.
45 | HBO have the most nominations and winners with 4442 nominations but also the highest
proportion of winners with 30% taking the gong. They really do punch out some good stuff.
46 | Adult Swim and CNN both have their proporiton of wins being >50%." 47 | 48 | # plot -------------------------------------------------------------------- 49 | 50 | df |> 51 | group_by(distributor) |> 52 | mutate( 53 | ratio = n/sum(n), 54 | xmin = ifelse(type == "Nominee", ratio, 0), 55 | xmax = ifelse(type != "Nominee", 1-ratio, 1), 56 | ymin = 0, 57 | ymax = 1, 58 | x_text = 0.5, 59 | y_text = 0.5, 60 | distributor = str_wrap(distributor, 8) 61 | ) |> 62 | ungroup() |> 63 | mutate(distributor = fct_reorder(distributor, xmax, min)) |> View() 64 | ggplot() + 65 | geom_rect(aes(xmin = xmin, xmax = xmax, ymin = ymin, ymax = ymax, fill = type)) + 66 | geom_text(aes(x = x_text, y = y_text, label = distributor), size = 18, family = "bebas", fontface = "bold", lineheight = 0.3) + 67 | scale_fill_manual(values = c(gold, brown)) + 68 | facet_wrap(~distributor, nrow = 8) + 69 | labs( 70 | title = title_text, 71 | subtitle = subtitle_text 72 | ) + 73 | theme_void() + 74 | theme( 75 | plot.title = element_markdown(family = "bebas", face = "bold", hjust = 0.5, margin = margin(t = 50, b = 20)), 76 | plot.subtitle = element_markdown(size = 48, family = "bebas", hjust = 0.5, lineheight = 0.3, margin = margin(b = 20)), 77 | plot.background = element_rect(fill = "grey20"), 78 | plot.margin = margin(l = 20, b = 20, r = 20), 79 | legend.position = "none", 80 | strip.text = element_blank() 81 | ) + 82 | ggsave("./2021/week-39/emmys.png", height = 12, width = 8) 83 | 84 | 85 | tt$nominees |> 86 | filter(str_detect(distributor, "Adult")) |> 87 | count(title, sort = TRUE) |> 88 | View() 89 | -------------------------------------------------------------------------------- /2021/week-40/code.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/doehm/tidyTuesday/74fb84eee433ae1741e31857547909c6ce2c5240/2021/week-40/code.png -------------------------------------------------------------------------------- /2021/week-40/week-40.R: -------------------------------------------------------------------------------- 1 | 2 | # week 40 ----------------------------------------------------------------- 3 | 4 | library(tidyverse) 5 | library(ggtext) 6 | library(showtext) 7 | 8 | # data -------------------------------------------------------------------- 9 | 10 | papers <- readr::read_csv('https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2021/2021-09-28/papers.csv') 11 | authors <- readr::read_csv('https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2021/2021-09-28/authors.csv') 12 | programs <- readr::read_csv('https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2021/2021-09-28/programs.csv') 13 | paper_authors <- readr::read_csv('https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2021/2021-09-28/paper_authors.csv') 14 | paper_programs <- readr::read_csv('https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2021/2021-09-28/paper_programs.csv') 15 | 16 | # data wrangling ---------------------------------------------------------- 17 | 18 | n_authors <- paper_authors |> 19 | count(paper, sort = TRUE, name = "n_authors") 20 | 21 | programs <- paper_programs |> 22 | left_join(programs, by = "program") 23 | 24 | df <- papers |> 25 | left_join(n_authors, by = "paper") |> 26 | left_join(programs, by = "paper") |> 27 | drop_na() |> 28 | group_by(program_desc, program_category, year) |> 29 | summarise( 30 | mean_authors = mean(n_authors), 31 | sd = sd(n_authors) 32 | ) 33 | 34 | # fonts and palettes ------------------------------------------------------ 35 | 36 | col <- list( 37 | line = "white", 38 | text = "white", 39 | pal = c("#540d6e", "#ee4266", "#ffd23f"), 40 | bg = "black", 41 | strip_bg = "grey10" 42 | ) 43 | 44 | font_add_google("Inconsolata", "incon") 45 | showtext_auto() 46 | 47 | fonts <- list( 48 | text = "incon", 49 | scale = 1 50 | ) 51 | 52 | # text -------------------------------------------------------------------- 53 | 54 | subtitle <- "Collaboration has increased on NBER papers over the past 40 years. The average number of contributors on papers in the Micro program
category has been increasing at a faster rate than papers in the Finance and Macro/International program categories" 55 | 56 | # plot -------------------------------------------------------------------- 57 | 58 | df |> 59 | ggplot(aes(year, mean_authors, colour = program_category)) + 60 | geom_line(size = 1) + 61 | geom_point(size = 2) + 62 | facet_wrap(~program_desc) + 63 | labs( 64 | title = "National Bureau of Economic Research Papers (NBER)", 65 | subtitle = subtitle, 66 | y = "Average number of authors per paper", 67 | colour = "Program category" 68 | ) + 69 | scale_colour_manual(values = col$pal) + 70 | theme_void() + 71 | theme( 72 | axis.text = element_text(size = 32), 73 | axis.text.x = element_text(margin = margin(b = 15)), 74 | axis.title.y = element_text(angle = 90, margin = margin(r = 30)), 75 | legend.position = "bottom", 76 | legend.title = element_text(lineheight = 0.4), 77 | plot.background = element_rect(fill = col$bg), 78 | plot.margin = margin(30, 30, 30, 30), 79 | plot.title = element_text(face = "bold", size = 128), 80 | plot.subtitle = element_markdown(size = 64, margin = margin(b = 30, t = 15), lineheight = 0.3), 81 | strip.text = element_text(margin = margin(5, 5, 5, 5)), 82 | strip.background = element_rect(fill = col$strip_bg), 83 | text = element_text(colour = col$text, family = fonts$text, size = 48) 84 | ) + 85 | ggsave("./2021/week-40/week-40.png", height = 12, width = 24) 86 | 87 | -------------------------------------------------------------------------------- /2021/week-40/week-40.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/doehm/tidyTuesday/74fb84eee433ae1741e31857547909c6ce2c5240/2021/week-40/week-40.png -------------------------------------------------------------------------------- /2021/week-41/code.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/doehm/tidyTuesday/74fb84eee433ae1741e31857547909c6ce2c5240/2021/week-41/code.png -------------------------------------------------------------------------------- /2021/week-41/final.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/doehm/tidyTuesday/74fb84eee433ae1741e31857547909c6ce2c5240/2021/week-41/final.png -------------------------------------------------------------------------------- /2021/week-41/legend.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/doehm/tidyTuesday/74fb84eee433ae1741e31857547909c6ce2c5240/2021/week-41/legend.png -------------------------------------------------------------------------------- /2021/week-41/nurses.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/doehm/tidyTuesday/74fb84eee433ae1741e31857547909c6ce2c5240/2021/week-41/nurses.png -------------------------------------------------------------------------------- /2021/week-41/week-41.R: -------------------------------------------------------------------------------- 1 | 2 | # week 41 ----------------------------------------------------------------- 3 | 4 | library(tidyverse) 5 | library(ggtext) 6 | library(showtext) 7 | library(janitor) 8 | library(geofacet) 9 | library(magick) 10 | 11 | # data -------------------------------------------------------------------- 12 | 13 | tt <- tidytuesdayR::tt_load(2021, week = 41) 14 | 15 | nurses <- tt$nurses |> 16 | clean_names() 17 | 18 | states <- nurses |> 19 | filter(year >= 2019) |> 20 | mutate( 21 | state_lab = case_when( 22 | state == "District of Columbia" ~ "D.C.", 23 | TRUE ~ state 24 | ), 25 | salary = annual_salary_median, 26 | fte = total_employed_rn 27 | ) |> 28 | pivot_wider(id_cols = c(state, state_lab), names_from = year, values_from = c(salary, fte)) |> 29 | mutate( 30 | change_salary = round((salary_2020 - salary_2019)/1000), 31 | change_fte = round((fte_2020 - fte_2019)/1000), 32 | salary_lab = glue("{round(salary_2020/1000)}k ({ifelse(change_salary < 0, change_salary, paste0('+', change_salary))}k)"), 33 | fte_lab = glue("{round(fte_2020/1000)}k ({ifelse(change_fte < 0, change_fte, paste0('+', change_fte))}k)"), 34 | scaled_salary_2020 = scale(change_salary/salary_2019)[,1], 35 | rating = ceiling(5*pnorm(scaled_salary_2020)), 36 | rating_lab = map_chr(rating, ~paste0(rep("*", .x), collapse = "")) 37 | ) |> 38 | left_join( 39 | nurses |> 40 | filter(year == 2020) |> 41 | distinct(state, location_quotient), 42 | by = "state" 43 | ) 44 | 45 | # fonts and palettes ------------------------------------------------------ 46 | 47 | font_add_google("Inconsolata", "incon") 48 | showtext_auto() 49 | 50 | ft <- "incon" 51 | 52 | cols <- list( 53 | pal1 = c("#586ba4", "#eee2df", "#f76c5e"), 54 | pal2 = c("#240046", "#eee2df", "#ff6d00"), 55 | pal3 = c("#9d4edd", "#eee2df", "#ff9e00"), 56 | pal4 = c("#414833", "#fefae0", "#e07a5f"), 57 | ft = "black" 58 | ) 59 | 60 | # text -------------------------------------------------------------------- 61 | 62 | subtitle <- "2020 was quite the year for the healthcare sector. The pandemic dramatically increased the workloads
and demands of registered 63 | nurses across the United States. States responded differently to the challenges.

California, Washington, Wyoming, Nebraska, North Dakota and Alska 64 | all had the largest proportional increase in average annual
salaries of registered nurses compared to 2019, whereas Delaware and D.C. are the only states that saw a drop." 65 | 66 | # plot -------------------------------------------------------------------- 67 | 68 | states |> 69 | ggplot(aes(xmin = -1, xmax = 1, ymin = -1, ymax = 1, fill = location_quotient)) + 70 | geom_rect() + 71 | geom_text(aes(x = -0.9, y = 0.9, label = state_lab), family = ft, fontface = "bold", size = 10, lineheight = 0.3, vjust = 1, hjust = 0) + 72 | geom_text(aes(x = -0.7, y = 0.2, label = salary_lab), family = ft, size = 12, hjust = 0) + 73 | geom_text(aes(x = -0.7, y = -0.2, label = fte_lab), family = ft, size = 12, hjust = 0) + 74 | geom_text(aes(x = 0, y = -0.6, label = rating_lab), family = ft, fontface = "bold", size = 12) + 75 | facet_geo(~state, grid = us_state_grid1) + 76 | scale_fill_gradientn(colours = cols$pal1) + 77 | labs( 78 | title = "Change in Average Annual Salaries of Registered Nurses from 2019 to 2020", 79 | subtitle = subtitle, 80 | fill = "Location\nquotient", 81 | caption = "Note: not all of the changes would be attributable to the pandemic but there was likely some influence\nData: Data.World / Graphic: @danoehm " 82 | ) + 83 | theme_void() + 84 | theme( 85 | text = element_text(family = ft), 86 | plot.title = element_text(size = 64, face = "bold"), 87 | plot.subtitle = element_markdown(size = 32, lineheight = 0.35, margin = margin(b = 20, t= 10)), 88 | plot.caption = element_text(family = ft, lineheight = 0.25, size = 20), 89 | plot.margin = margin(50, 50, 20, 50), 90 | legend.title = element_text(lineheight = 0.25, size = 32, vjust = 1), 91 | legend.text = element_text(size = 24, vjust = 1, hjust = 1), 92 | legend.position = "bottom", 93 | strip.text = element_blank() 94 | ) + 95 | ggsave("./2021/week-41/nurses.png", height = 10, width = 14) 96 | 97 | # legend ------------------------------------------------------------------ 98 | 99 | a <- 0.9 100 | ggplot() + 101 | geom_rect(aes(xmin = -1, xmax = 1, ymin = -1, ymax = 1), fill = NA, colour = "black") + 102 | annotate("text", x = -0.9, y = 0.8, label = "State", family = ft, fontface = "bold", size = 24, vjust = 1, hjust = 0) + 103 | annotate("text", x = -0.5, y = 0.3, label = "Median annual\nsalary\nfor 2020", family = ft, size = 14, lineheight = 0.25) + 104 | annotate("text", x = 0.5, y = 0.3, label = "(change from 2019)", family = ft, size = 14) + 105 | annotate("text", x = -0.5, y = -0.2, label = "Total employed\nregistered nurses\nfor 2020", family = ft, size = 14, lineheight = 0.25) + 106 | annotate("text", x = 0.5, y = -0.2, label = "(Change from 2019)", family = ft, size = 14) + 107 | annotate("text", x = 0, y = -0.7, label = "Rating based on the\nproportional change in\nannual salary from 2019", family = ft, fontface = "bold", size = 14, lineheight = 0.25) + 108 | theme_void() + 109 | ggsave("./2021/week-41/legend.png", height = 3.5*a, width = 4.5*a) 110 | 111 | # combine plots ----------------------------------------------------------- 112 | 113 | nurses <- image_read("./2021/week-41/nurses.png") 114 | legend <- image_read("./2021/week-41/legend.png") 115 | final <- image_composite(nurses, image_scale(legend, "700x700"), offset = "+3400-2195") 116 | image_write(final, "./2021/week-41/final.png") 117 | -------------------------------------------------------------------------------- /2021/week-42/code.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/doehm/tidyTuesday/74fb84eee433ae1741e31857547909c6ce2c5240/2021/week-42/code.png -------------------------------------------------------------------------------- /2021/week-42/fish.R: -------------------------------------------------------------------------------- 1 | 2 | # week 42 ----------------------------------------------------------------- 3 | 4 | library(tidyverse) 5 | library(ggtext) 6 | library(showtext) 7 | library(janitor) 8 | library(magick) 9 | library(scales) 10 | library(glue) 11 | 12 | # data -------------------------------------------------------------------- 13 | 14 | tt <- tidytuesdayR::tt_load(2021, week = 42) 15 | 16 | df <- tt$`capture-fisheries-vs-aquaculture` |> 17 | clean_names() |> 18 | set_names("entity", "code", "year", "aqua", "capture") |> 19 | inner_join( 20 | countrycode::codelist %>% 21 | select(code = genc3c, continent) %>% 22 | distinct() %>% 23 | filter( 24 | !is.na(code), 25 | !is.na(continent) 26 | ), 27 | by = "code") 28 | 29 | dat <- df |> 30 | group_by(entity) |> 31 | mutate(first_aqua = aqua > capture) |> 32 | group_by(year) |> 33 | summarise(p = mean(first_aqua, na.rm = TRUE)) |> 34 | mutate(year_max = year + 1) 35 | 36 | increase_df <- df |> 37 | filter(year %in% c(1960, 2018)) |> 38 | group_by(year) |> 39 | summarise( 40 | aqua = sum(aqua, na.rm = TRUE), 41 | capture = sum(capture, na.rm = TRUE) 42 | ) |> 43 | mutate_all(~paste0(round(.x/lag(.x))*100, "%")) |> 44 | slice(2) 45 | 46 | sustainability <- tt$`fish-stocks-within-sustainable-levels` |> 47 | clean_names() |> 48 | set_names("entity", "code", "year", "sustainable", "overfished") |> 49 | filter(entity == "World") |> 50 | mutate( 51 | p = 0, 52 | label = paste0(round(sustainable), "%"), 53 | sustainable = sustainable/100 54 | ) 55 | 56 | year_labs <- tibble( 57 | year = c(1974, 2017), 58 | y = 0.95, 59 | p = 0 60 | ) 61 | 62 | legend_text <- glue("More green, more countries where aquaculture production exceeds capture. Each band represents a year.") 63 | title_text <- glue("Aquaculture and Sustainability") 64 | subtitle_text <- glue("Even though more and more countries adopt aquaculture the percentage of
sustainably sourced 65 | fish stock is decreasing.

From 1960 to 2018 capture stock production 66 | increased {increase_df$capture} while aquaculture
production increased {increase_df$aqua}. 67 | Meanwhile the percentage of sustainably sourced
stock has dropped from 91% in 1978 to 66% in 2017 across the globe. The demand
68 | for seafood is so great, farming can't keep up.") 69 | 70 | # fontsa nd palettes ------------------------------------------------------ 71 | 72 | download.file("https://github.com/doehm/evoPalette/raw/master/inst/extdata/palettes.rds", destfile = "./2021/week-42/palettes.rds") 73 | palettes <- readRDS("./2021/week-42/palettes.rds") 74 | 75 | pal <- palettes$palette[[4]] 76 | show_col(pal) 77 | 78 | font_add_google("Mukta", "muk") 79 | showtext_auto() 80 | 81 | # plots ------------------------------------------------------------------- 82 | 83 | dat |> 84 | ggplot(aes(year, 1, fill = p)) + 85 | geom_rect(aes(xmin = year, xmax = year_max, ymin = 0, ymax = 1, fill = p)) + 86 | geom_line(aes(year, sustainable), sustainability, size = 2) + 87 | geom_segment(aes(x = 2017, xend = 2017, y = 0.66, yend = 0.92), size = 0.5, linetype = 2) + 88 | geom_point(aes(year, sustainable), sustainability, size = 14) + 89 | geom_text(aes(year, sustainable, label = label), sustainability, size = 14, colour = pal[5], fontface = "bold", family = "muk") + 90 | geom_text(aes(year, y, label = year), year_labs, size = 20, fontface = "bold", family = "muk") + 91 | geom_text(aes(year, 0.03, label = round(p, 2)), slice(dat, 3, 15, 30, 45, 57), family = "muk", fontface = "bold", size = 16) + 92 | geom_richtext(aes(x = 1970, y = 0.08, label = legend_text), family = "muk", fill = NA, size = 16, label.color = NA, hjust = 0) + 93 | geom_richtext(aes(x = 1967, y = 0.52, label = title_text), family = "muk", fill = NA, size = 48, label.color = NA, hjust = 0) + 94 | geom_richtext(aes(x = 1967, y = 0.35, label = subtitle_text), family = "muk", fill = NA, size = 16, label.color = NA, hjust = 0, lineheight = 0.4) + 95 | scale_fill_gradientn(colours = rev(pal)) + 96 | labs(caption = "#TidyTuesday week 41 2021 / Data: OurWorldinData.org / Graphic: @danoehm") + 97 | theme_void() + 98 | theme( 99 | legend.position = "none", 100 | plot.background = element_rect(fill = "black"), 101 | plot.caption = element_text(family = "muk", colour = "white", size = 24, margin = margin(b = 7), hjust = 0.95) 102 | ) + 103 | coord_cartesian(clip = "off") + 104 | ggsave("./2021/week-42/fish.png", height = 8, width = 16) 105 | -------------------------------------------------------------------------------- /2021/week-42/fish.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/doehm/tidyTuesday/74fb84eee433ae1741e31857547909c6ce2c5240/2021/week-42/fish.png -------------------------------------------------------------------------------- /2021/week-5/week-5.R: -------------------------------------------------------------------------------- 1 | library(magick) 2 | library(imager) 3 | library(tidyverse) 4 | library(scales) 5 | library(grid) 6 | library(crayon) 7 | library(glue) 8 | library(cowplot) 9 | library(ggforce) 10 | library(survivoR) 11 | library(extrafont) 12 | library(showtext) 13 | 14 | font_add("coke", "C:/Users/Dan/Downloads/Fonts/loki_cola/LOKICOLA.ttf") 15 | showtext_auto() 16 | 17 | coke_bottle <- load.image("C:/Users/Dan/Pictures/R/coke.jpeg") 18 | plot(coke_bottle) 19 | 20 | font_import("C:/Users/Dan/Downloads/Fonts/loki_cola") 21 | 22 | # plastics data 23 | # Get the data 24 | tuesdata <- tidytuesdayR::tt_load(2021, week = 5) 25 | 26 | plastics <- tuesdata$plastics 27 | 28 | plastics %>% 29 | mutate_if(is.character, tolower) %>% 30 | filter( 31 | !parent_company %in% c("null", "unbranded", "grand total"), 32 | !country %in% c("empty") 33 | ) %>% 34 | group_by(country) %>% 35 | mutate(n_brands = n()) %>% 36 | arrange(desc(n_brands)) %>% 37 | group_b 38 | 39 | 40 | 41 | bottle <- record_coords("bottle") 42 | cap <- record_coords("cap") 43 | label <- record_coords("label") 44 | 45 | df <- bottle %>% 46 | bind_rows(cap) %>% 47 | bind_rows(label) %>% 48 | mutate( 49 | x = scale_coords(x), 50 | y = scale_coords(y) 51 | ) 52 | 53 | coke_dark <- rgb(9, 16, 12, maxColorValue = 255) 54 | coke_light <- rgb(140, 30, 13, maxColorValue = 255) 55 | 56 | coke_ramp <- colorRampPalette(c(coke_light, coke_dark))(100) 57 | 58 | coke %>% 59 | ggplot(aes(x = x, y = y)) + 60 | geom_bspline_closed0( 61 | data = dplyr::filter(coke, name == "bottle"), 62 | mapping = aes(x = x, y = y), 63 | alpha = 1, fill = coke_ramp[50] 64 | ) + 65 | geom_bspline_closed(data = filter(coke, name == "cap"), mapping = aes(x = x, y = y), colour = "black", fill = "red") + 66 | geom_polygon(data = filter(coke, name == "label"), mapping = aes(x = x, y = y), colour = "black", fill = "red") + 67 | geom_text(x = 0.5, y = 0.54, label = "America", family = "Loki Cola", size = 18, colour = "white") + 68 | theme_void() 69 | 70 | n <- 2e4 71 | shape <- 100 72 | alpha <- runif(n, 0, 3) 73 | x <- runif(n) 74 | y <- alpha 75 | bubble_colour <- c(rev(coke_ramp), coke_ramp) 76 | 77 | bubbles <- tibble( 78 | alpha = alpha, 79 | x = x, 80 | y = y 81 | ) 82 | 83 | ggplot() + 84 | geom_point(data = bubbles, mapping = aes(x, y, colour = x), size = 5, alpha = 0.6) + 85 | geom_rect(aes(xmin = 0-wd/2, xmax = 1+wd/2, ymin = 0, ymax = 3.2), fill = "grey50", alpha = 0.2, colour = "black") + 86 | geom_shape( 87 | data = glass, aes(x = x, y = y), colour = "grey20", fill = "grey90", 88 | expand = unit(0, 'mm'), radius = unit(3, 'mm') 89 | ) + 90 | scale_colour_gradientn(colours = bubble_colour) + 91 | theme_void() + 92 | theme( 93 | legend.position = "none" 94 | ) 95 | 96 | wd <- 0.07 97 | base_wd <- 0.1 98 | glass <- tribble( 99 | ~x, ~y, 100 | 0.1, 0.1+base_wd, 101 | 0, 0.2+base_wd, 102 | 0, 3.2, 103 | -wd, 3.2, 104 | -wd, -wd, 105 | 1+wd, -wd, 106 | 1+wd, 3.2, 107 | 1, 3.2, 108 | 1, 0.2+base_wd, 109 | 0.9, 0.1+base_wd 110 | ) 111 | 112 | ggplot() + 113 | geom_shape( 114 | data = glass, aes(x = x, y = y), colour = "#8ecae6", fill = "#8ecae6", alpha = 0.05, 115 | expand = unit(0, 'mm'), radius = unit(3.2, 'mm'), size = 1 116 | ) + 117 | theme_void() 118 | 119 | -------------------------------------------------------------------------------- /2021/week-6/hbcu-065.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/doehm/tidyTuesday/74fb84eee433ae1741e31857547909c6ce2c5240/2021/week-6/hbcu-065.png -------------------------------------------------------------------------------- /2021/week-6/week-6.R: -------------------------------------------------------------------------------- 1 | library(tidyverse) 2 | library(tidytuesdayR) 3 | library(extrafont) 4 | library(janitor) 5 | library(glue) 6 | library(cowplot) 7 | library(ggforce) 8 | library(purrr) 9 | library(png) 10 | 11 | df <- tt_load(2021, week = 6) 12 | 13 | #### helpers #### 14 | placement <- function(r, d, p) { 15 | expand_grid(x = seq(0, r, d), y = seq(0, r, d)) %>% 16 | sample_n(p*n()) 17 | } 18 | 19 | save_k <- function(loc, filename, format = "png") { 20 | k <- max(as.numeric(str_extract(list.files(loc), "[:digit:]+")) + 1) 21 | if(is.infinite(k)) k <- "001" 22 | glue("{loc}/{filename}-{str_pad(k, 3, 'left', '0')}.{format}") 23 | } 24 | 25 | #### colours #### 26 | bg <- "black" 27 | tiles <- "white" 28 | font <- "white" 29 | 30 | #### fonts #### 31 | loadfonts() 32 | # font_import("C:/Users/danie/Downloads/Fonts/amatic", prompt = FALSE) 33 | # font_import("C:/Users/danie/Downloads/Fonts/Sarabun", prompt = FALSE) 34 | ft <- "Sarabun ExtraLight" 35 | ftb <- "Sarabun ExtraBold" 36 | 37 | #### titles #### 38 | subtitle <- 39 | "The total number of enrollments has steadily increased from 222k students in 1976 to reaching a maximum number of 40 | 323k students in 2010. The proportion of female students ranges from 53% in 1976 to a 41 | maximum of 61.8% in 2004. The proportion of females has remained 42 | above 60% since 1997. The area and alpha of the square represents the total number of enrollments and the density represents 43 | the proportion of female students." 44 | 45 | #### plot #### 46 | sc <- 1 47 | df$hbcu_all %>% 48 | clean_names() %>% 49 | select(year, males, females) %>% 50 | pivot_longer(-year, names_to = "gender", values_to = "enrolled") %>% 51 | group_by(year) %>% 52 | mutate( 53 | p = enrolled/sum(enrolled), 54 | total = sum(enrolled) 55 | ) %>% 56 | filter(gender == "females") %>% 57 | ungroup() %>% 58 | mutate( 59 | r = sqrt(total), 60 | r = r/min(r), 61 | coords = map2(r, p, ~placement(.x, 0.1, .y)), 62 | tile_fill = case_when( 63 | year == 2004 ~ "indianred3", # "#CD5555" 64 | year == 2010 ~ "palegreen3", # "#7CCD7C" 65 | TRUE ~ "white" 66 | ), 67 | label = paste(round(p, 3)*100, "%") 68 | ) %>% 69 | unnest(coords) %>% 70 | mutate(x = x - r/2) %>% 71 | right_join(tibble(year = 1976:2015)) %>% 72 | mutate(year = paste(year, "/", ifelse(is.na(p), "-", paste(round(p, 3)*100, "%")))) %>% { 73 | ggplot(., aes(x, y, alpha = r)) + 74 | geom_tile(width = 0.07, height = 0.07, fill = .$tile_fill) + 75 | # geom_text(data = distinct(., year, label, r), mapping = aes(x = 0, y = -0.15, label = label), colour = tiles, size = 2) + 76 | facet_wrap(~year, ncol = 5) + 77 | labs( 78 | title = "HBCU Enrollments", 79 | subtitle = subtitle, 80 | caption = "Source: Data.World / Graphic: @danoehm" 81 | ) + 82 | coord_cartesian(clip = "off") + 83 | theme_void() + 84 | theme( 85 | plot.background = element_rect(fill = bg), 86 | legend.position = "none", 87 | plot.margin = margin(t = 0, b = 30, l = 60, r = 60), 88 | text = element_text(colour = font, family = ft), 89 | plot.title = element_text(family = ftb, margin = margin(t = 20, b = 0), size = 36, lineheight = 0.8), 90 | plot.subtitle = element_textbox_simple(family = ft, margin = margin(t = 10, b = 30), size = 12, lineheight = 1), 91 | plot.caption = element_text(family = ft, margin = margin(t = 10)), 92 | strip.text = element_text(family = ft, margin = margin(t = 10)), 93 | ) + 94 | ggsave(save_k("./2021-week-6/plots", "hbcu"), height = 13.5, width = 7.5) 95 | } 96 | 97 | 98 | -------------------------------------------------------------------------------- /2021/week-7/income.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/doehm/tidyTuesday/74fb84eee433ae1741e31857547909c6ce2c5240/2021/week-7/income.png -------------------------------------------------------------------------------- /2021/week-7/week-7.R: -------------------------------------------------------------------------------- 1 | library(tidyverse) 2 | library(tidytuesdayR) 3 | library(extrafont) 4 | library(janitor) 5 | library(glue) 6 | library(cowplot) 7 | library(ggforce) 8 | library(purrr) 9 | library(png) 10 | 11 | df <- tt_load(2021, week = 7) 12 | 13 | #### helpers #### 14 | save_k <- function(loc, filename, format = "png") { 15 | k <- max(as.numeric(str_extract(list.files(loc), "[:digit:]+")) + 1) 16 | if(is.infinite(k)) k <- "001" 17 | glue("{loc}/{filename}-{str_pad(k, 3, 'left', '0')}.{format}") 18 | } 19 | 20 | #### fonts #### 21 | # ft <- "Verdana Pro Light" 22 | # ftb <- "Verdana Pro Black" 23 | ft <- "Sarabun ExtraLight" 24 | ftb <- "Sarabun ExtraBold" 25 | 26 | #### palette #### 27 | col1 <- "#ccd5ae" # neutral colour faedcd ccd5ae 28 | col2 <- "white" 29 | bg <- "black" 30 | 31 | #### titles #### 32 | wd <- 40 33 | title <- "Income \nInequality" 34 | subtitle0 <- str_wrap( 35 | "The income gap between White and Black American middle income earners between 36 | 1967 and 2019", 37 | wd) 38 | subtitle1 <- str_wrap( 39 | '"Income is money coming into a family, while wealth is a family’s assets—things like savings, 40 | real estate, businesses—minus debt. Both are important sides of families’ financial security, 41 | but wealth cushions families against emergencies and gives them the means to move up the economic 42 | ladder. Also, wealth disparities are much greater than income disparities: three times as much by 43 | one measure."', 44 | wd) 45 | subtitle2 <- str_wrap( 46 | '"Income inequality can worsen wealth inequality because the income people have available to save and 47 | invest matters. Focusing on private income, such as earnings and dividends, plus cash government 48 | benefits, we see that the income of families near the top increased roughly 90 percent from 1963 to 49 | 2016, while the income of families at the bottom increased less than 10 percent."', 50 | wd) 51 | subtitle <- paste(subtitle0, "\n\n", subtitle1) 52 | 53 | #### plot #### 54 | ann_df <- tibble( 55 | x = 2022, 56 | y = c(72471, 45356), 57 | label = c("White - $72k", "Black - $45k"), 58 | race = c("Black Alone", "White Alone"), 59 | difference = 1 60 | ) 61 | 62 | main <- df$income_mean %>% 63 | filter( 64 | dollar_type == "Current Dollars", 65 | income_quintile == "Middle", 66 | race %in% c("White Alone", "Black Alone") 67 | ) %>% 68 | mutate(race = factor(race, levels = c("White Alone", "Black Alone"))) %>% 69 | arrange(year, race) %>% 70 | select(year, race, income_dollars) %>% 71 | # pivot_wider(names_from = race, values_from = income_dollars) %>% 72 | # clean_names() %>% 73 | # mutate(d = 100*round(white_alone/black_alone, 2)) %>% 74 | group_by(race) %>% 75 | mutate(difference = ifelse(race == "Black Alone", 1, income_dollars/max(income_dollars))) %>% 76 | ggplot(aes(x = year, y = income_dollars, fill = race, alpha = difference, colour = NULL)) + 77 | geom_bar(stat = "identity", position = "identity") + 78 | # geom_text(data = ann_df, mapping = aes(x = x, y = y, label = label), colour = col1, family = ft, size = 5) + 79 | theme_void() + 80 | theme( 81 | plot.background = element_rect(fill = bg), 82 | plot.margin = margin(l = 80, t = 40, r = 40), 83 | legend.position = "none", 84 | plot.caption = element_text(family = ft, colour = col1, margin = margin(b = 20), size = 6, hjust = 0.5) 85 | ) + 86 | labs( 87 | caption = "Source: Urban Institute and US Census / Graphic: @danoehm" 88 | ) + 89 | # coord_cartesian(clip = "off") + 90 | coord_polar("y", clip = "off") + 91 | scale_fill_manual(values = c(col1, "black")) 92 | 93 | # text <- ggplot() + 94 | # geom_text(aes(x = 0.1, y = 0.57), label = title, family = ftb, colour = col1, size = 20, hjust = 0) + 95 | # geom_text(aes(x = 0.1, y = 0.35), label = subtitle, family = ft, colour = col1, size = 5, hjust = 0) + 96 | # theme_void() + 97 | # theme( 98 | # plot.background = element_rect(fill = bg) 99 | # ) + 100 | # coord_cartesian(clip = "off", xlim = c(0, 1), ylim = c(0, 1)) 101 | 102 | text <- ggplot() + 103 | geom_text(aes(x = 0.1, y = 0.5), label = title, family = ftb, colour = col1, size = 8, hjust = 0) + 104 | geom_text(aes(x = 0.1, y = 0.35), label = subtitle, family = ft, colour = col1, size = 2, hjust = 0) + 105 | theme_void() + 106 | theme( 107 | plot.background = element_rect(fill = bg) 108 | ) + 109 | coord_cartesian(clip = "off", xlim = c(0, 1), ylim = c(0.35, 0.52)) 110 | 111 | ggdraw() + 112 | draw_plot(main) + 113 | draw_plot(text, 0.33, 0.5, 0.1, 0.2) + 114 | ggsave(save_k("2021/week-7/plots", "income"), height = 10, width = 10.66) 115 | 116 | -------------------------------------------------------------------------------- /2021/week-8/palette.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/doehm/tidyTuesday/74fb84eee433ae1741e31857547909c6ce2c5240/2021/week-8/palette.png -------------------------------------------------------------------------------- /2021/week-8/slave-016.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/doehm/tidyTuesday/74fb84eee433ae1741e31857547909c6ce2c5240/2021/week-8/slave-016.png -------------------------------------------------------------------------------- /2021/week-8/week-8.R: -------------------------------------------------------------------------------- 1 | 2 | library(tidyverse) 3 | library(janitor) 4 | library(magick) 5 | library(evoPalette) # devtools::install_github("doehm/evoPalette") 6 | extrafont::loadfonts(device = "win", quiet = TRUE) 7 | 8 | #### helpers #### 9 | save_k <- function(loc, filename, format = "png") { 10 | k <- max(as.numeric(str_extract(list.files(loc), "[:digit:]+")) + 1) 11 | if(is.infinite(k)) k <- "001" 12 | glue("{loc}/{filename}-{str_pad(k, 3, 'left', '0')}.{format}") 13 | } 14 | 15 | #### data load #### 16 | 17 | df <- tidytuesdayR::tt_load(2021, week = 8) 18 | freed_slaves <- df$freed_slaves %>% 19 | clean_names() 20 | 21 | #### fonts #### 22 | 23 | ftc <- "Gill Sans Nova Cond" 24 | ft <- "Gill Sans Nova" 25 | 26 | update_geom_defaults("text", list( family = ftc, color = black)) 27 | 28 | #### palette #### 29 | 30 | pal <- extract_palette("C:/Users/Dan/Pictures/tidy-tuesday/free-libre-sm.png", n_cols = 4) 31 | show_palette(pal) + ggsave("./2021/week-8/palette.png", height = 4, width = 8) 32 | col1 <- pal[2] 33 | col2 <- pal[3] 34 | ft_col <- pal[4] 35 | bg <- pal[1] 36 | 37 | #### label data #### 38 | 39 | labels <- freed_slaves %>% 40 | mutate( 41 | y = 101.5, 42 | label = paste0(free, "%") 43 | ) 44 | 45 | lines_df <- labels %>% 46 | mutate( 47 | y1 = 100, 48 | yend = ifelse(slave == 0, slave, slave + 3), 49 | name = NA 50 | ) 51 | 52 | title1 <- "PROPORTION OF FREEMEN AND SLAVES AMONG AMERICAN NEGROES ." 53 | title2 <- "PROPORTION DES NÈGRES LIBRES ET DES ESCLAVES EN AMÉRIQUE ." 54 | subtitle <- "DONE BY ATLANTA UNIVERSITY ." 55 | 56 | #### plots #### 57 | 58 | wd <- 10 59 | freed_slaves %>% 60 | mutate(free = 100 - slave) %>% 61 | pivot_longer(cols = -year, names_to = "name", values_to = "y") %>% 62 | ggplot(aes(x = year, y = y, fill = name)) + 63 | geom_area() + 64 | geom_segment(data = lines_df, mapping = aes(x = year, xend = year, y = y1, yend = yend)) + 65 | annotate("text", x = 1830, y = 55, label = "SLAVES\nESCLAVES", family = ftc, col = bg, fontface = "bold", size = 12, lineheight = 0.8) + 66 | annotate("text", x = labels$year, y = labels$y, label = labels$year, family = ftc, col = ft_col, fontface = "bold", size = 8, alpha = 0.9) + 67 | annotate("text", x = 1830, y = 95, label = "FREE - LIBRE", family = ftc, col = ft_col, fontface = "bold", size = 10, alpha = 0.9) + 68 | annotate("text", x = labels$year, y = ifelse(labels$slave == 0, 89, labels$slave) + 1.5, label = labels$label, family = ftc, col = ft_col, fontface = "bold", size = 7, alpha = 0.9) + 69 | annotate("text", x = 1830, y = 140, label = title1, family = ftc, col = ft_col, fontface = "bold", size = 7, alpha = 0.8) + 70 | annotate("text", x = 1830, y = 130, label = title2, family = ftc, col = ft_col, fontface = "bold", size = 7, alpha = 0.8) + 71 | annotate("text", x = 1830, y = 120, label = subtitle, family = ftc, col = ft_col, fontface = "bold", size = 5, alpha = 0.8) + 72 | annotate("text", x = 1830, y = -3, label = "#DuBoisChallenge #TidyTuesday @danoehm", family = ftc, col = ft_col, size = 4, alpha = 0.8) + 73 | theme_void() + 74 | theme( 75 | plot.background = element_rect(fill = bg), 76 | legend.position = "none" 77 | ) + 78 | scale_fill_manual(values = list(slave = col2, free = col1)) + 79 | ggsave(save_k("./2021/week-8/plots", "slave"), type = "cairo", height = 1.28*wd, width = wd) 80 | -------------------------------------------------------------------------------- /2021/week-9/earn-20210228-141437.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/doehm/tidyTuesday/74fb84eee433ae1741e31857547909c6ce2c5240/2021/week-9/earn-20210228-141437.png -------------------------------------------------------------------------------- /2021/week-9/week-9.R: -------------------------------------------------------------------------------- 1 | library(tidyverse) 2 | library(janitor) 3 | library(glue) 4 | library(survivoR) # devtools::install_github("doehm/survivoR") 5 | library(extrafont) 6 | library(lubridate) 7 | extrafont::loadfonts(quiet = TRUE) 8 | 9 | #### data #### 10 | df <- tidytuesdayR::tt_load(2021, week = 9) 11 | earn <- df$earn 12 | 13 | #### fonts #### 14 | # ftc <- "Gill Sans Nova Cond" 15 | # ft <- "Gill Sans Nova" 16 | # ftc <- "Verdana Pro Cond Black" 17 | # ft <- "Verdana Pro Cond Light" 18 | ftc <- "Sarabun ExtraBold" 19 | ft <- "Sarabun ExtraLight" 20 | 21 | #### palette #### 22 | season <- 13 23 | sp <- season_palettes$palette[[season]] 24 | col2 <- sp[1] 25 | bg <- colorRampPalette(c("black", sp[2]))(8) 26 | 27 | #### titles #### 28 | wd <- 80 29 | title <- str_wrap("Median Weekly Earnings", wd/3) 30 | subtitle0 <- str_wrap( 31 | '"Asian women and men earned more than their White, Black, and Hispanic counterparts in 2019. Among women, 32 | Whites ($840) earned 82 percent as much as Asians ($1,025); Blacks ($704) earned 69 percent; and Hispanics 33 | ($642) earned 63 percent. Among men, these earnings differences were even larger: White men ($1,036) earned 34 | 78 percent as much as Asian men ($1,336); Black men ($769) earned 58 percent as much; and Hispanic men ($747) 35 | earned 56 percent" - US Bureau of Labor Statistics', 36 | wd) 37 | subtitle <- paste(subtitle0) 38 | 39 | 40 | #### plot #### 41 | earn %>% 42 | filter( 43 | age %in% c("16 years and over", "25 years and over", "55 years and over"), 44 | !str_detect(sex, "Both"), 45 | !str_detect(race, "All"), 46 | year %% 2 == 0 47 | ) %>% 48 | group_by(age, year, race, sex) %>% 49 | summarise( 50 | n_persons = mean(n_persons), 51 | median_weekly_earn = mean(median_weekly_earn) 52 | ) %>% 53 | ungroup() %>% 54 | mutate( 55 | race = str_wrap(race, 10), 56 | year = as.numeric(year) 57 | ) %>% 58 | bind_rows(expand_grid(sex = letters[1:2], race = unique(.$race), year = seq(2010, 2020, 2))) %>% 59 | ggplot() + 60 | geom_bar(mapping = aes(x = sex, y = median_weekly_earn, fill = age), stat = "identity") + 61 | facet_grid(year ~ race) + 62 | scale_x_discrete(labels = c("Men" = "Men", "Women" = "Women", "a" = " ", "b" = " ")) + 63 | labs( 64 | title = title, 65 | subtitle = subtitle0, 66 | caption = "Source: US Bureau of Labor Statistics / Graphic: @danoehm", 67 | fill = "Age Group" 68 | ) + 69 | theme_void() + 70 | coord_polar("y", clip = "off") + 71 | scale_fill_survivor(season) + 72 | theme( 73 | text = element_text(colour = col2, family = ft), 74 | strip.text = element_text(family = ft, size = 10), 75 | plot.background = element_rect(fill = bg[1], colour = NA), 76 | plot.margin = margin(t = 20, b = 50, l = 20, r = 20), 77 | plot.title = element_text(family = ftc, face = "bold", hjust = 0.5, margin = margin(b = 20), size = 36), 78 | plot.subtitle = element_text(family = ft, hjust = 0, margin = margin(b = 20), size = 16), 79 | plot.caption = element_text(margin = margin(t = 20), size = 12), 80 | legend.position = "bottom", 81 | legend.margin = margin(t = 20), 82 | legend.text = element_text(size = 10), 83 | axis.text.y = element_text(family = ft, hjust = 1) 84 | ) + 85 | ggsave(glue("./2021/week-9/plots/earn-{format(now(), '%Y%m%d-%H%M%S')}.png"), type = "cairo", height = 20, width = 8.72) 86 | 87 | 88 | -------------------------------------------------------------------------------- /2022/week02-bees/bees.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/doehm/tidyTuesday/74fb84eee433ae1741e31857547909c6ce2c5240/2022/week02-bees/bees.png -------------------------------------------------------------------------------- /2022/week03-chocolate/chocolate.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/doehm/tidyTuesday/74fb84eee433ae1741e31857547909c6ce2c5240/2022/week03-chocolate/chocolate.png -------------------------------------------------------------------------------- /2022/week08-freedom/freedom.R: -------------------------------------------------------------------------------- 1 | # https://github.com/rfordatascience/tidytuesday 2 | 3 | source("scripts/startup.R") 4 | 5 | log_file <<- "2022/week08-freedom/log.txt" 6 | 7 | # load data --------------------------------------------------------------- 8 | 9 | freedom <- readr::read_csv('https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2022/2022-02-22/freedom.csv') |> 10 | clean_names() |> 11 | mutate( 12 | status = factor(status, levels = c("F", "PF", "NF")), 13 | region_name = factor(region_name, levels = c("Asia", "Africa", "Americas", "Europe", "Oceania")) 14 | ) 15 | 16 | # fonts and palettes ------------------------------------------------------ 17 | 18 | pal <- c(good_pal[3:4], dark) 19 | 20 | ft_text <- "barlow" 21 | ft_title <- ft_text 22 | 23 | # wrangle ----------------------------------------------------------------- 24 | 25 | df_base <- freedom |> 26 | time_log() |> 27 | group_by(year, region_name) |> 28 | count(status) |> 29 | group_by(year, region_name) |> 30 | mutate(p = n/sum(n)) 31 | 32 | df_p <- freedom |> 33 | time_log() |> 34 | group_by(country, region_name) |> 35 | count(status) |> 36 | filter(status == "NF") |> 37 | group_by(country, region_name) |> 38 | summarise(n = sum(n)) |> 39 | filter( 40 | n == 26, 41 | country != "Côte d’Ivoire" 42 | ) |> 43 | group_by(region_name) |> 44 | summarise(country = paste(country, collapse = "\n")) 45 | 46 | # titles ------------------------------------------------------------------ 47 | 48 | title <- "Freedom in the World" 49 | subtitle <- str_rich_wrap(glue(" 50 | ~40%-50% of countries in the Asia and African regions are considered to be not free. Europe 51 | and Oceania have the highest proportion of free countries. The countries in text are those 52 | which have been considered not free every year for the past 25 years (1995-2020). 53 | "), 150) 54 | caption <- "Graphic: @danoehm / Source: Freedom House and the United Nations by way of Arthur Cheib / #rstats #tidytuesday week 8" 55 | fill <- "Freedom Status" 56 | colour <- "Colour" 57 | 58 | # plot -------------------------------------------------------------------- 59 | 60 | df_base |> 61 | time_log() |> 62 | ggplot() + 63 | geom_area(aes(x = year, y = p, fill = status)) + 64 | geom_text( 65 | aes(x = 1997, y = 0.02, label = country), df_p, 66 | family = ft_text, size = 14.5, colour = light, vjust = 0, 67 | lineheight = 0.28, hjust = 0, fontface = "bold" 68 | ) + 69 | facet_wrap(~region_name, nrow = 1) + 70 | 71 | # theme and scales and labs 72 | scale_fill_manual(values = pal[1:3], breaks = c("F", "PF", "NF"), labels = c("Free", "Partially free", "Not free")) + 73 | scale_x_continuous(breaks = c(1995, 2020), labels = c(1995, 2020)) + 74 | scale_y_continuous(breaks = c(0.5, 1), labels = c("50%", "100%")) + 75 | labs( 76 | title = title, 77 | subtitle = subtitle, 78 | caption = caption, 79 | fill = fill, 80 | colour = colour 81 | ) + 82 | theme_void() + 83 | theme( 84 | text = element_text(colour = light), 85 | plot.background = element_rect(fill = dark, colour = NA), 86 | plot.title = element_text(hjust = 0.5, family = ft_title, size = 250, face = "bold"), 87 | plot.subtitle = element_markdown(hjust = 0.5, family = ft_text, size = 64, lineheight = 0.35, margin = margin(b = 15), halign = 0), 88 | plot.caption = element_text(hjust = 0, family = ft_text, size = 36, lineheight = 0.35, margin = margin(t = 20)), 89 | plot.margin = margin(t = 20, r = 20, b = 20, l = 20), 90 | axis.text.y = element_text(family = ft_text, size = 36), 91 | axis.text.x = element_text(family = ft_text, size = 36, margin = margin(t = -20)), 92 | strip.text = element_text(family = ft_text, size = 96, face = "bold"), 93 | legend.title = element_text(family = ft_text, size = 36, lineheight = 0.25, face = "bold"), 94 | legend.text = element_text(family = ft_text, size = 36, face = "bold"), 95 | legend.box.margin = margin(t = 10), 96 | legend.position = "bottom" 97 | ) + 98 | ggsave("2022/week08-freedom/freedom.png", height = 12.25, width = 18) 99 | -------------------------------------------------------------------------------- /2022/week08-freedom/freedom.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/doehm/tidyTuesday/74fb84eee433ae1741e31857547909c6ce2c5240/2022/week08-freedom/freedom.png -------------------------------------------------------------------------------- /2022/week08-freedom/log.txt: -------------------------------------------------------------------------------- 1 | 2022-02-22 14:20:52 2 | 2022-02-22 14:21:29 3 | 2022-02-22 14:21:36 4 | 2022-02-22 14:22:31 5 | 2022-02-22 14:22:35 6 | 2022-02-22 14:23:08 7 | 2022-02-22 14:28:44 8 | 2022-02-22 14:29:42 9 | 2022-02-22 15:31:17 10 | 2022-02-22 15:31:27 11 | 2022-02-22 15:41:07 12 | 2022-02-22 15:41:32 13 | 2022-02-22 15:41:48 14 | 2022-02-22 15:43:20 15 | 2022-02-22 15:43:37 16 | 2022-02-22 15:44:33 17 | 2022-02-22 15:44:48 18 | 2022-02-22 15:45:08 19 | 2022-02-22 15:46:15 20 | 2022-02-22 15:47:47 21 | 2022-02-22 15:49:06 22 | 2022-02-22 15:49:08 23 | 2022-02-22 15:53:14 24 | 2022-02-22 15:53:45 25 | 2022-02-22 15:54:44 26 | 2022-02-22 15:54:51 27 | 2022-02-22 15:56:25 28 | 2022-02-22 15:56:56 29 | 2022-02-22 15:59:39 30 | 2022-02-22 16:01:11 31 | 2022-02-22 16:03:40 32 | 2022-02-22 16:05:28 33 | 2022-02-22 16:05:56 34 | 2022-02-22 16:06:20 35 | 2022-02-22 16:06:52 36 | 2022-02-22 16:07:57 37 | 2022-02-22 16:08:43 38 | 2022-02-22 16:08:52 39 | 2022-02-22 16:09:47 40 | 2022-02-22 16:12:47 41 | 2022-02-22 16:16:07 42 | 2022-02-22 16:16:10 43 | 2022-02-22 16:17:08 44 | 2022-02-22 16:17:42 45 | 2022-02-22 16:18:49 46 | 2022-02-22 16:19:58 47 | 2022-02-22 16:20:39 48 | 2022-02-22 16:20:56 49 | 2022-02-22 16:21:26 50 | 2022-02-22 16:22:44 51 | 2022-02-22 16:22:56 52 | 2022-02-22 16:24:58 53 | 2022-02-22 16:25:19 54 | 2022-02-22 16:31:42 55 | 2022-02-22 16:33:28 56 | 2022-02-22 16:35:06 57 | 2022-02-22 16:35:23 58 | 2022-02-22 16:35:46 59 | 2022-02-22 16:37:50 60 | 2022-02-22 16:37:52 61 | 2022-02-22 16:38:57 62 | 2022-02-22 16:48:51 63 | 2022-02-22 16:49:12 64 | 2022-02-22 16:54:14 65 | 2022-02-22 16:56:59 66 | 2022-02-22 16:57:40 67 | 2022-02-22 16:57:49 68 | 2022-02-22 16:57:56 69 | 2022-02-22 16:59:37 70 | 2022-02-22 16:59:45 71 | 2022-02-22 17:00:43 72 | 2022-02-22 17:01:05 73 | 2022-02-22 17:03:01 74 | 2022-02-22 17:03:14 75 | 2022-02-22 17:03:20 76 | 2022-02-22 17:03:36 77 | 2022-02-22 17:04:08 78 | 2022-02-22 17:05:21 79 | 2022-02-22 17:05:56 80 | 2022-02-22 17:06:21 81 | 2022-02-22 17:07:10 82 | 2022-02-22 17:07:22 83 | 2022-02-22 17:07:45 84 | 2022-02-22 17:17:17 85 | 2022-02-22 17:17:43 86 | 2022-02-22 17:18:29 87 | 2022-02-22 17:18:57 88 | 2022-02-22 17:20:00 89 | 2022-02-22 17:21:11 90 | 2022-02-22 17:21:55 91 | 2022-02-22 17:27:56 92 | 2022-02-22 17:31:29 93 | 2022-02-22 17:32:16 94 | 2022-02-22 17:32:21 95 | 2022-02-22 17:39:13 96 | 2022-02-22 17:40:37 97 | 2022-02-22 17:41:03 98 | 2022-02-22 17:41:58 99 | 2022-02-22 17:42:40 100 | 2022-02-22 17:43:52 101 | 2022-02-22 17:44:45 102 | 2022-02-22 17:44:45 103 | 2022-02-22 17:44:45 104 | 2022-02-22 17:45:03 105 | 2022-02-22 17:45:03 106 | 2022-02-22 17:45:03 107 | 2022-02-22 17:45:18 108 | 2022-02-22 17:45:48 109 | 2022-02-22 17:46:31 110 | 2022-02-22 17:47:09 111 | 2022-02-22 17:47:34 112 | 2022-02-22 17:51:29 113 | 2022-02-22 17:52:07 114 | 2022-02-22 17:53:10 115 | 2022-02-22 18:22:50 116 | 2022-02-22 18:23:44 117 | 2022-02-22 18:25:26 118 | 2022-02-22 18:25:58 119 | 2022-02-22 18:28:05 120 | 2022-02-22 18:29:54 121 | 2022-02-22 18:30:22 122 | 2022-02-22 18:34:13 123 | 2022-02-22 18:38:32 124 | -------------------------------------------------------------------------------- /2022/week09-energy/energy.R: -------------------------------------------------------------------------------- 1 | # https://github.com/rfordatascience/tidytuesday 2 | 3 | # for libraries and custom functions 4 | source("scripts/startup.R") 5 | 6 | log_file <<- "2022/week09-energy/log.txt" 7 | 8 | # load data --------------------------------------------------------------- 9 | 10 | stations <- readr::read_csv('https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2022/2022-03-01/stations.csv') |> 11 | clean_names() 12 | 13 | # fonts and palettes ------------------------------------------------------ 14 | 15 | bg <- "white" 16 | 17 | ft_text <- "barlow" 18 | ft_title <- ft_text 19 | 20 | # wrangle ----------------------------------------------------------------- 21 | 22 | df_base <- stations |> 23 | time_log() |> 24 | group_by(state) |> 25 | summarise(p = sum(fuel_type_code == "ELEC")/n()) |> 26 | mutate( 27 | code = state, 28 | info_graph = glue("") 29 | ) 30 | 31 | # create the fill charts and merge with the bolts 32 | for(k in 1:nrow(df_base)) { 33 | tibble(x = 0, y = df_base$p[k]) |> 34 | ggplot(aes(x, y)) + 35 | geom_col(fill = "#219ebc") + 36 | ylim(c(0, 1)) + 37 | theme_void() + 38 | theme( 39 | plot.background = element_rect(fill = "black"), 40 | plot.margin = margin(0, -100, -50, -100) 41 | ) + 42 | ggsave(glue("2022/week09-energy/bolts/{df_base$state[k]}.png"), height = 4, width = 3) 43 | 44 | base <- image_read('2022/week09-energy/lightning-bolt.png') |> 45 | image_resize("220x180") 46 | 47 | measure <- image_read(glue("2022/week09-energy/bolts/{df_base$state[k]}.png")) |> 48 | image_resize("220x180") 49 | 50 | image_composite(base, measure, "plus") |> 51 | image_write(glue("2022/week09-energy/bolts/{df_base$state[k]}.png")) 52 | } 53 | 54 | # titles ------------------------------------------------------------------ 55 | 56 | title <- "Alternative Fuel Stations" 57 | subtitle <- str_rich_wrap(" 58 | The proportion of fuel stations offering electric charging facilities is 59 | very high in the East and West of the US but lacking in the central states. 60 | ", 100) 61 | caption <- glue("Graphic: {get_icon('twitter', 10)} @danoehm / Source: US DOT / Code: {get_icon('github', 10)} doehm/tidytuesday #rstats #tidytuesday") 62 | 63 | # plot -------------------------------------------------------------------- 64 | 65 | df_base |> 66 | time_log() |> 67 | ggplot() + 68 | geom_richtext(aes(0, 0, label = info_graph), label.colour = NA, fill = NA) + 69 | facet_geo(~code, grid = us_state_grid1) + 70 | 71 | # theme and scales and labs 72 | labs( 73 | title = title, 74 | subtitle = subtitle, 75 | caption = caption 76 | ) + 77 | theme_void() + 78 | theme( 79 | text = element_text(colour = dark), 80 | plot.background = element_rect(fill = bg, colour = NA), 81 | plot.title = element_text(hjust = 0.5, family = ft_title, size = 200, face = "bold"), 82 | plot.subtitle = element_markdown(hjust = 0.5, family = ft_text, size = 64, lineheight = 0.35, margin = margin(b = 10), halign = 0), 83 | plot.caption = element_markdown(hjust = 0.5, family = ft_text, size = 36, lineheight = 0.35, margin = margin(t = 20)), 84 | plot.margin = margin(t = 20, r = 20, b = 20, l = 20), 85 | legend.title = element_text(family = ft_text, size = 36, lineheight = 0.25, face = "bold"), 86 | legend.text = element_text(family = ft_text, size = 36, face = "bold"), 87 | legend.position = "bottom", 88 | strip.text = element_text(family = ft_text, size = 60, margin = margin(b = 5), face = "bold") 89 | ) + 90 | ggsave("2022/week09-energy/energy.png", height = 11.5, width = 16) 91 | 92 | -------------------------------------------------------------------------------- /2022/week09-energy/energy.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/doehm/tidyTuesday/74fb84eee433ae1741e31857547909c6ce2c5240/2022/week09-energy/energy.png -------------------------------------------------------------------------------- /2022/week09-energy/lightning-bolt.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/doehm/tidyTuesday/74fb84eee433ae1741e31857547909c6ce2c5240/2022/week09-energy/lightning-bolt.png -------------------------------------------------------------------------------- /2022/week10-erasmus/erasmus.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/doehm/tidyTuesday/74fb84eee433ae1741e31857547909c6ce2c5240/2022/week10-erasmus/erasmus.png -------------------------------------------------------------------------------- /2022/week12-babynames/babynames.R: -------------------------------------------------------------------------------- 1 | # https://github.com/rfordatascience/tidytuesday 2 | 3 | source("scripts/startup.R") 4 | 5 | log_file <<- "2022/week12-babynames/log.txt" 6 | 7 | # load data --------------------------------------------------------------- 8 | 9 | babynames <- readr::read_csv('https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2022/2022-03-22/babynames.csv') 10 | 11 | # fonts and palettes ------------------------------------------------------ 12 | 13 | bg <- "white" 14 | ft_text_col <- dark 15 | 16 | ft_text <- "hand" 17 | ft_title <- "pm" 18 | 19 | # wrangle ----------------------------------------------------------------- 20 | 21 | df_female <- babynames |> 22 | time_log() |> 23 | mutate(decade = floor(year/10)*10) |> 24 | filter(decade %in% c(1980, 2010)) |> 25 | group_by(decade, name, sex) |> 26 | summarise(n = sum(n)) |> 27 | pivot_wider(names_from = sex, values_from = n, values_fill = 0) |> 28 | rename( 29 | male = M, 30 | female = `F` 31 | ) |> 32 | mutate( 33 | total = male + female, 34 | p_female = female/total 35 | ) 36 | 37 | df_int <- df_female |> 38 | group_by(name) |> 39 | filter(n() > 1) |> 40 | mutate(grand_total = sum(total)) |> 41 | group_by(decade) |> 42 | # slice_max(grand_total, n = 750, with_ties = TRUE) |> 43 | arrange(name, decade) |> 44 | group_by(name) |> 45 | mutate( 46 | lag_p_female = lag(p_female), 47 | change0 = p_female - lag_p_female, 48 | change = abs(p_female - lag_p_female) 49 | ) 50 | 51 | df_col <- df_int |> 52 | drop_na() |> 53 | select(name, change, change0, p_female_2010 = p_female) 54 | 55 | top_n <- 30 56 | df_top <- df_int |> 57 | ungroup() |> 58 | drop_na() |> 59 | slice_max(change, n = top_n) |> 60 | sample_n(top_n) 61 | 62 | df_base <- df_int |> 63 | select(-change, -change0) |> 64 | left_join(df_col, by = "name") 65 | 66 | 67 | # titles ------------------------------------------------------------------ 68 | 69 | title <- "Baby Names" 70 | subtitle <- str_rich_wrap(glue(" 71 | The popularity of baby names has changed over time, no only in absolute terms but also in terms of which sex the name is typically given to. 72 | From the 1980s to the 2010s many names have remained traditionally male 73 | and female names whereas some have 74 | been given proportionally more to males or more to females. While 75 | some names have bucked the trend there does seem to be convergence to either male or female. 76 | The top 30 largest changes are listed, however it is suspected some may be influenced by data errors or small 77 | sample sizes. 78 | "), 110) 79 | caption <- glue("Graphic: {get_icon('twitter', 10)} @danoehm / Source: babynames / Code: {get_icon('github', 10)} doehm/tidytuesday #rstats #tidytuesday") 80 | fill <- "Fill" 81 | colour <- "Colour" 82 | 83 | 84 | df_base |> 85 | time_log() |> 86 | ggplot() + 87 | geom_line(aes(decade, p_female, group = name, colour = p_female_2010, alpha = change)) + 88 | geom_point(aes(decade, p_female, colour = p_female_2010, alpha = change), size = 2) + 89 | geom_text_repel(aes(decade, p_female, label = name), df_top, colour = ft_text_col, nudge_x = 10, family = ft_text, size = 18) + 90 | 91 | # theme and scales and labs 92 | scale_x_continuous(breaks = c(1980, 2002), labels = c("1980-1990", "2010-2020"), limits = c(1980, 2025)) + 93 | scale_y_continuous(breaks = seq(0, 1, 0.25), labels = paste0(round(seq(0, 1, 0.25)*100), "%")) + 94 | scale_colour_gradientn(colors = spec[c(2, 4, 6)]) + 95 | labs( 96 | title = title, 97 | subtitle = subtitle, 98 | caption = caption, 99 | fill = fill, 100 | colour = colour, 101 | y = str_wrap("Proportion of females", 30) 102 | ) + 103 | theme_void() + 104 | theme( 105 | text = element_text(colour = ft_text_col), 106 | plot.background = element_rect(fill = bg, colour = bg), 107 | plot.title = element_text(hjust = 0.5, family = ft_title, size = 180, face = "bold"), 108 | plot.subtitle = element_markdown(hjust = 0.5, family = ft_text, size = 48, lineheight = 0.35, halign = 0), 109 | plot.caption = element_markdown(hjust = 0.5, family = ft_text, size = 36, lineheight = 0.35, margin = margin(t = 20)), 110 | plot.margin = margin(t = 20, r = 50, b = 20, l = 20), 111 | legend.title = element_text(family = ft_text, size = 36, lineheight = 0.25, face = "bold"), 112 | legend.text = element_text(family = ft_text, size = 36, face = "bold"), 113 | legend.position = "none", 114 | axis.title.y = element_text(size = 48, family = ft_text, lineheight = 0.25, angle = 90), 115 | axis.text.y = element_text(size = 36, margin = margin(l = 10)), 116 | axis.text.x = element_text(size = 64, hjust = 0) 117 | ) + 118 | ggsave("2022/week12-babynames/babynames1.png", height = 14, width = 11) 119 | -------------------------------------------------------------------------------- /2022/week12-babynames/babynames.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/doehm/tidyTuesday/74fb84eee433ae1741e31857547909c6ce2c5240/2022/week12-babynames/babynames.png -------------------------------------------------------------------------------- /2022/week13-sports/sports.R: -------------------------------------------------------------------------------- 1 | # https://github.com/rfordatascience/tidytuesday 2 | 3 | source("scripts/startup.R") 4 | 5 | log_file <<- "2022/week13-sports/log.txt" 6 | 7 | # load data --------------------------------------------------------------- 8 | 9 | sports <- readr::read_csv('https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2022/2022-03-29/sports.csv') 10 | 11 | # fonts and palettes ------------------------------------------------------ 12 | 13 | ft_text <- "oswald" 14 | ft_title <- ft_text 15 | 16 | ft_text_col <- lakes[2] 17 | 18 | scales_col <- rev(c(lakes[2], darken(lakes[1], 0.8))) 19 | ft_text_col_v <- c(rep(scales_col[1], 34), darken(scales_col[2], 0.2), rep(scales_col[2], 2)) 20 | 21 | bg <- scales_col[2] 22 | 23 | # wrangle ----------------------------------------------------------------- 24 | 25 | df_base <- sports |> 26 | time_log() |> 27 | group_by(sports, year) |> 28 | summarise( 29 | men = sum(partic_men, na.rm = TRUE), 30 | women = sum(partic_women, na.rm = TRUE) 31 | ) |> 32 | mutate( 33 | total = men + women, 34 | p_men = men/total, 35 | p_women = women/total, 36 | sports = fct_reorder(sports, p_men, min) 37 | ) |> 38 | ungroup() 39 | 40 | # titles ------------------------------------------------------------------ 41 | 42 | subtitle <- str_rich_wrap("Gender split across college sports in the US. Shaded area indicates the variation from 2015", 40) 43 | caption <- glue("Graphic: {get_icon('twitter', 15, fill = list(bg = bg, img = scales_col[1]))} @danoehm / Source: Equity in Athletics Data Analysis / Code: {get_icon('github', 15, fill = list(bg = bg, img = scales_col[1]))} doehm/tidytuesday #rstats #tidytuesday") 44 | 45 | df_text <- tibble( 46 | x = 0, 47 | y = c(0.5, 0.89), 48 | label = c("Balanced (50%)", "More women (100%)") 49 | ) 50 | 51 | # plot -------------------------------------------------------------------- 52 | 53 | df_base1 <- df_base |> 54 | filter( 55 | year == 2019, 56 | sports != "Team Handball" 57 | ) |> 58 | arrange(p_men) |> 59 | mutate(sports_num = 1:n()) |> 60 | select(sports, sports_num) 61 | 62 | df_base2 <- df_base |> 63 | left_join(df_base1, by = "sports") |> 64 | pivot_longer(c(p_men, p_women), names_to = "gender", values_to = "p") |> 65 | time_log() 66 | 67 | alpha <- 0.4 68 | 69 | df_base2 |> 70 | ggplot() + 71 | geom_col(aes(x = sports_num, y = p, fill = gender), filter(df_base2, year == 2015), alpha = alpha, width = 1) + 72 | geom_col(aes(x = sports_num, y = p, fill = gender), filter(df_base2, year == 2016), alpha = alpha, width = 1) + 73 | geom_col(aes(x = sports_num, y = p, fill = gender), filter(df_base2, year == 2017), alpha = alpha, width = 1) + 74 | geom_col(aes(x = sports_num, y = p, fill = gender), filter(df_base2, year == 2018), alpha = alpha, width = 1) + 75 | geom_col(aes(x = sports_num, y = p, fill = gender), filter(df_base2, year == 2019), alpha = alpha, width = 1) + 76 | 77 | geom_text(aes(x = sports_num, y = 0.04, label = sports), df_base1, 78 | family = ft_text, size = 20, colour = ft_text_col_v, angle = 0, hjust = 0) + 79 | 80 | geom_text(aes(x = x, y = y, label = label), df_text, family = ft_text, 81 | colour = scales_col[1], size = 20, hjust = 0.5) + 82 | 83 | annotate("text", x = 18, y = 0.35, label = "WOMEN", family = ft_text, colour = scales_col[1], size = 64, fontface = "bold") + 84 | annotate("text", x = 18, y = 0.65, label = "MEN", family = ft_text, colour = scales_col[2], size = 64, fontface = "bold") + 85 | 86 | annotate("segment", x = 1, xend = 20, y = 0.5, yend = 0.5, colour = scales_col[1], lty = 2) + 87 | annotate("segment", x = 20, xend = 38, y = 0.5, yend = 0.5, colour = scales_col[2], lty = 2) + 88 | 89 | annotate("text", x = 33, y = 0.75, label = "College\nSports", lineheight = 0.35, fontface = "bold", 90 | size = 84, colour = scales_col[2], family = ft_text) + 91 | annotate("richtext", x = 27, y = 0.75, label = subtitle, lineheight = 0.6, size = 24, 92 | colour = scales_col[2], family = ft_text, fill = NA, label.colour = NA) + 93 | annotate("richtext", x = -1, y = 0.5, label = caption, lineheight = 0.6, size = 16, 94 | colour = scales_col[1], family = ft_text, fill = NA, label.colour = NA) + 95 | 96 | # theme and scales and labs 97 | scale_fill_manual(values = scales_col) + 98 | theme_void() + 99 | theme( 100 | text = element_text(colour = scales_col[1]), 101 | plot.background = element_rect(fill = bg, colour = bg), 102 | plot.margin = margin(t = -85, r = -45, b = -30, l = -45), 103 | legend.position = "none" 104 | ) + 105 | coord_flip(clip = "off") + 106 | ggsave("2022/week13-sports/sports.png", height = 18, width = 12) 107 | -------------------------------------------------------------------------------- /2022/week13-sports/sports.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/doehm/tidyTuesday/74fb84eee433ae1741e31857547909c6ce2c5240/2022/week13-sports/sports.png -------------------------------------------------------------------------------- /2022/week14-news/log-posted.txt: -------------------------------------------------------------------------------- 1 | 2022-04-05 11:02:52 2 | -------------------------------------------------------------------------------- /2022/week14-news/log.txt: -------------------------------------------------------------------------------- 1 | 2022-04-05 21:13:42 2 | 2022-04-05 21:14:14 3 | 2022-04-05 21:15:16 4 | 2022-04-05 21:15:43 5 | 2022-04-05 21:15:51 6 | 2022-04-05 21:16:11 7 | 2022-04-05 21:20:11 8 | 2022-04-05 21:20:18 9 | 2022-04-05 21:20:37 10 | 2022-04-05 21:20:42 11 | 2022-04-05 21:22:19 12 | 2022-04-05 21:23:28 13 | 2022-04-05 21:23:56 14 | 2022-04-05 21:24:46 15 | 2022-04-05 21:24:55 16 | 2022-04-05 21:25:55 17 | 2022-04-05 21:27:07 18 | 2022-04-05 21:28:00 19 | 2022-04-05 21:32:22 20 | 2022-04-05 21:33:25 21 | 2022-04-05 21:33:55 22 | 2022-04-05 21:34:12 23 | 2022-04-05 21:34:18 24 | 2022-04-05 21:34:43 25 | 2022-04-05 21:36:09 26 | 2022-04-05 21:37:37 27 | 2022-04-05 21:37:44 28 | 2022-04-05 21:40:18 29 | 2022-04-05 21:40:19 30 | 2022-04-05 21:40:57 31 | 2022-04-05 21:40:57 32 | 2022-04-05 21:43:20 33 | 2022-04-05 21:44:35 34 | 2022-04-05 21:46:50 35 | 2022-04-05 21:50:01 36 | 2022-04-05 21:50:28 37 | 2022-04-05 21:50:29 38 | 2022-04-05 21:51:27 39 | 2022-04-05 21:51:53 40 | 2022-04-05 21:52:13 41 | 2022-04-05 21:52:34 42 | 2022-04-05 21:53:03 43 | 2022-04-05 21:54:50 44 | 2022-04-05 21:55:10 45 | 2022-04-05 21:56:27 46 | 2022-04-05 21:56:52 47 | 2022-04-05 21:57:13 48 | 2022-04-05 21:58:46 49 | 2022-04-05 21:59:11 50 | 2022-04-05 21:59:55 51 | 2022-04-05 22:00:39 52 | 2022-04-05 22:01:10 53 | 2022-04-05 22:01:42 54 | 2022-04-05 22:02:26 55 | 2022-04-05 22:02:55 56 | 2022-04-05 22:04:05 57 | 2022-04-05 22:04:34 58 | 2022-04-05 22:05:22 59 | 2022-04-05 22:05:47 60 | 2022-04-05 22:06:16 61 | 2022-04-05 22:07:53 62 | 2022-04-05 22:08:14 63 | 2022-04-05 22:09:02 64 | 2022-04-05 22:09:03 65 | 2022-04-05 22:09:28 66 | 2022-04-05 22:09:30 67 | 2022-04-05 22:10:17 68 | 2022-04-05 22:10:32 69 | 2022-04-05 22:11:00 70 | 2022-04-05 22:11:23 71 | 2022-04-05 22:12:39 72 | 2022-04-05 22:13:02 73 | 2022-04-05 22:22:13 74 | 2022-04-05 22:22:19 75 | 2022-04-05 22:23:56 76 | 2022-04-05 22:24:53 77 | 2022-04-05 22:25:17 78 | 2022-04-05 22:26:00 79 | 2022-04-05 22:30:03 80 | 2022-04-05 22:31:40 81 | 2022-04-05 22:32:21 82 | 2022-04-05 22:32:49 83 | 2022-04-05 22:33:53 84 | 2022-04-05 22:34:31 85 | 2022-04-05 22:34:52 86 | 2022-04-05 22:35:25 87 | 2022-04-05 22:36:13 88 | 2022-04-05 22:36:30 89 | 2022-04-05 22:37:07 90 | 2022-04-05 22:37:47 91 | 2022-04-05 22:39:12 92 | 2022-04-05 22:40:27 93 | 2022-04-05 22:41:54 94 | 2022-04-05 22:44:21 95 | 2022-04-05 22:56:24 96 | 2022-04-05 22:56:48 97 | 2022-04-05 22:57:18 98 | -------------------------------------------------------------------------------- /2022/week14-news/news.R: -------------------------------------------------------------------------------- 1 | # https://github.com/rfordatascience/tidytuesday 2 | 3 | source("scripts/startup.R") 4 | 5 | log_file <<- "2022/week14-news/log.txt" 6 | 7 | # load data --------------------------------------------------------------- 8 | 9 | news_orgs <- readr::read_csv('https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2022/2022-04-05/news_orgs.csv') 10 | 11 | # fonts and palettes ------------------------------------------------------ 12 | 13 | pal <- spec 14 | bg <- "white" 15 | 16 | ft_text <- "crete" 17 | ft_title <- ft_text 18 | 19 | # wrangle ----------------------------------------------------------------- 20 | 21 | df <- news_orgs |> 22 | time_log() |> 23 | select(publication_name, state, country, year_founded, coverage_topics, budget = budget_percent_revenue_generation) |> 24 | mutate(topics = map(coverage_topics, ~str_split(.x, ", ")[[1]])) |> 25 | unnest(topics) 26 | 27 | df_base <- df |> 28 | count(year_founded, topics) |> 29 | drop_na() |> 30 | mutate(topics = fct_reorder(topics, n, max)) 31 | 32 | df_n_pubs <- df |> 33 | count(year_founded, budget) 34 | 35 | # titles ------------------------------------------------------------------ 36 | 37 | title <- "Digital Publications" 38 | subtitle <- str_rich_wrap(" 39 | The number of digital publications have been increasing over time. The 3 most population topics covered are 40 | Government issues, business and, education and schools. 2010 was the biggest year with 20 publications launching 41 | with a focus on government issues. 42 | ", 60) 43 | caption <- glue("Graphic: {get_icon('twitter', 10, fill = list(bg = bg, img = 'black'))} @danoehm / Source: Project Oasis / Code: {get_icon('github', 10, fill = list(bg = bg, img = 'black'))} doehm/tidytuesday #rstats #tidytuesday") 44 | fill <- "Number of\npublications" 45 | 46 | # plot -------------------------------------------------------------------- 47 | 48 | # titles 49 | g_text <- ggplot() + 50 | annotate("text", x = -1, y = 0, label = title, family = ft_text, size = 48, hjust = 0) + 51 | annotate("richtext", x = -1, y = -1, label = subtitle, family = ft_text, size = 18, hjust = 0, label.color = NA, 52 | lineheight = 0.4) + 53 | xlim(c(-1, 2)) + 54 | ylim(c(-2, 1)) + 55 | coord_cartesian(clip = "off") + 56 | theme_void() 57 | 58 | # base plot 59 | g_base <- df_base |> 60 | time_log() |> 61 | ggplot() + 62 | geom_tile(aes(year_founded, topics, fill = n)) + 63 | 64 | # theme and scales and labs 65 | scale_y_discrete(position = "right") + 66 | scale_x_continuous(position = "top", limits = c(1980, 2020)) + 67 | scale_fill_gradientn(colors = pal) + 68 | labs( 69 | caption = caption, 70 | fill = fill, 71 | x = "Year founded" 72 | ) + 73 | theme_void() + 74 | theme( 75 | text = element_text(colour = dark, family = ft_text), 76 | plot.background = element_rect(fill = bg, colour = bg), 77 | plot.caption = element_markdown(hjust = 0.5, family = ft_text, size = 36, lineheight = 0.35, margin = margin(t = 20)), 78 | plot.margin = margin(t = 20, r = 20, b = 20, l = 20), 79 | legend.title = element_text(family = ft_text, size = 36, lineheight = 0.4, face = "bold"), 80 | legend.text = element_text(family = ft_text, size = 36, face = "bold"), 81 | legend.position = "bottom", 82 | axis.text.x = element_text(angle = 0, vjust = 0.5, size = 48, hjust = 1, margin = margin(b = 30, t = 5)), 83 | axis.text.y = element_text(vjust = 0.5, size = 48, hjust = 0), 84 | axis.title.x = element_text(size = 48) 85 | ) 86 | 87 | # put it together 88 | g_base + 89 | inset_element(g_text, 0.025, 0, 0.6, 0.4) + 90 | ggsave("2022/week14-news/news.png", height = 12, width = 16) 91 | -------------------------------------------------------------------------------- /2022/week14-news/news.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/doehm/tidyTuesday/74fb84eee433ae1741e31857547909c6ce2c5240/2022/week14-news/news.png -------------------------------------------------------------------------------- /2022/week16-crossword/crossword.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/doehm/tidyTuesday/74fb84eee433ae1741e31857547909c6ce2c5240/2022/week16-crossword/crossword.png -------------------------------------------------------------------------------- /2022/week16-crossword/log-posted.txt: -------------------------------------------------------------------------------- 1 | 2022-04-20 11:18:33 2 | -------------------------------------------------------------------------------- /2022/week16-crossword/log.txt: -------------------------------------------------------------------------------- 1 | 2022-04-19 20:48:22 2 | 2022-04-19 20:49:10 3 | 2022-04-19 20:49:23 4 | 2022-04-19 20:50:11 5 | 2022-04-19 20:50:54 6 | 2022-04-19 20:51:12 7 | 2022-04-19 20:51:21 8 | 2022-04-19 20:53:01 9 | 2022-04-19 20:53:55 10 | 2022-04-19 20:54:27 11 | 2022-04-19 20:55:32 12 | 2022-04-19 20:56:09 13 | 2022-04-19 20:56:09 14 | 2022-04-19 20:58:11 15 | 2022-04-19 20:58:13 16 | 2022-04-19 20:58:50 17 | 2022-04-19 20:59:50 18 | 2022-04-19 21:00:59 19 | 2022-04-19 21:02:59 20 | 2022-04-19 21:04:12 21 | 2022-04-19 21:04:33 22 | 2022-04-19 21:04:39 23 | 2022-04-19 21:06:02 24 | 2022-04-19 21:06:26 25 | 2022-04-19 21:07:55 26 | 2022-04-19 21:08:53 27 | 2022-04-19 21:09:18 28 | 2022-04-19 21:10:19 29 | 2022-04-19 21:10:37 30 | 2022-04-19 21:11:56 31 | 2022-04-19 21:12:27 32 | 2022-04-19 21:14:09 33 | 2022-04-19 21:14:23 34 | 2022-04-19 21:15:12 35 | 2022-04-19 21:16:14 36 | 2022-04-19 21:16:52 37 | 2022-04-19 21:18:00 38 | 2022-04-19 21:22:25 39 | 2022-04-19 21:24:08 40 | 2022-04-19 21:24:49 41 | 2022-04-19 21:30:27 42 | 2022-04-19 21:32:11 43 | 2022-04-19 21:34:31 44 | 2022-04-19 21:36:40 45 | 2022-04-19 21:38:32 46 | 2022-04-19 21:40:21 47 | 2022-04-19 21:42:08 48 | 2022-04-19 21:42:49 49 | 2022-04-19 21:44:15 50 | 2022-04-19 21:44:55 51 | 2022-04-19 21:46:26 52 | 2022-04-19 21:46:57 53 | 2022-04-19 21:48:45 54 | 2022-04-19 22:29:25 55 | 2022-04-19 22:39:23 56 | 2022-04-19 22:40:02 57 | 2022-04-19 22:44:55 58 | 2022-04-19 22:45:07 59 | 2022-04-19 22:48:44 60 | 2022-04-19 22:49:35 61 | 2022-04-19 22:50:19 62 | 2022-04-19 22:53:29 63 | 2022-04-19 22:54:08 64 | 2022-04-19 22:56:21 65 | 2022-04-19 22:58:25 66 | 2022-04-19 23:01:47 67 | 2022-04-19 23:05:44 68 | 2022-04-19 23:06:24 69 | 2022-04-19 23:14:14 70 | 2022-04-19 23:21:59 71 | 2022-04-19 23:22:28 72 | 2022-04-19 23:23:39 73 | 2022-04-19 23:24:24 74 | 2022-04-19 23:24:59 75 | 2022-04-19 23:25:20 76 | 2022-04-19 23:25:51 77 | 2022-04-19 23:26:23 78 | 2022-04-20 08:12:01 79 | 2022-04-20 08:12:29 80 | 2022-04-20 08:12:35 81 | 2022-04-20 08:13:33 82 | 2022-04-20 08:13:49 83 | 2022-04-20 08:13:49 84 | 2022-04-20 08:13:54 85 | 2022-04-20 08:14:49 86 | 2022-04-20 08:14:57 87 | 2022-04-20 08:15:28 88 | 2022-04-20 08:15:29 89 | 2022-04-20 08:15:49 90 | 2022-04-20 08:17:25 91 | 2022-04-20 08:18:58 92 | 2022-04-20 08:20:05 93 | 2022-04-20 08:22:22 94 | 2022-04-20 08:22:30 95 | 2022-04-20 08:28:54 96 | 2022-04-20 08:30:59 97 | 2022-04-20 08:32:52 98 | 2022-04-20 08:33:39 99 | 2022-04-20 08:34:26 100 | 2022-04-20 08:34:59 101 | 2022-04-20 08:57:16 102 | 2022-04-20 09:07:26 103 | 2022-04-20 09:08:01 104 | 2022-04-20 09:08:46 105 | 2022-04-20 09:10:54 106 | 2022-04-20 09:32:06 107 | 2022-04-20 09:37:24 108 | 2022-04-20 09:48:25 109 | 2022-04-20 09:48:31 110 | 2022-04-20 09:49:25 111 | 2022-04-20 09:50:31 112 | 2022-04-20 09:50:45 113 | 2022-04-20 09:51:10 114 | 2022-04-20 09:51:41 115 | 2022-04-20 09:52:52 116 | 2022-04-20 09:59:53 117 | 2022-04-20 10:03:56 118 | 2022-04-20 10:06:43 119 | 2022-04-20 10:08:11 120 | 2022-04-20 10:19:16 121 | 2022-04-20 10:19:27 122 | 2022-04-20 11:08:55 123 | -------------------------------------------------------------------------------- /2022/week17-kaggle/kaggle.R: -------------------------------------------------------------------------------- 1 | # https://github.com/rfordatascience/tidytuesday 2 | 3 | source("scripts/startup.R") 4 | 5 | log_file <<- "2022/week17-kaggle/log.txt" 6 | 7 | # load data --------------------------------------------------------------- 8 | 9 | hidden_gems <- readr::read_csv('https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2022/2022-04-26/hidden_gems.csv') 10 | 11 | # fonts and palettes ------------------------------------------------------ 12 | 13 | pal <- spec 14 | bg <- "white" 15 | txt_col <- dark 16 | col1 <- spec[8] 17 | 18 | ft_text <- "oreg" 19 | ft_title <- ft_text 20 | 21 | # wrangle ----------------------------------------------------------------- 22 | 23 | df_base <- hidden_gems |> 24 | time_log() |> 25 | arrange(title) |> 26 | mutate( 27 | ttl = title, 28 | tidy = str_detect(tolower(title), "tidy|dplyr"), 29 | x = seq(1, n()-1, length = 300), 30 | x = ifelse(x >= 150, x + 1, x), 31 | angle = c(seq(90, 0, length = 75), seq(360, 270, length = 75), seq(90, 0, length = 75), seq(360, 270, length = 75)), 32 | just = ifelse(x >= 150, 1, 0), 33 | title = ifelse(x >= 150, str_pad(title, pad = ".", width = 80, side = "right"), str_pad(title, pad = ".", width = 80, side = "left")) 34 | ) 35 | 36 | # titles ------------------------------------------------------------------ 37 | 38 | title <- glue("Kaggle Ain't
{col_generic('Tidy', col1)}") 39 | subtitle <- str_rich_wrap(glue("Out of the 300 Kaggle hidden gems only {sum(df_base$tidy)} reference the {col_generic('tidyverse', col1)}"), 30) 40 | caption <- glue("Graphic: {get_icon('twitter', 10, fill = list(bg = bg, img = txt_col))} @danoehm / Source: Kaggle / Code: {get_icon('github', 10, fill = list(bg = bg, img = txt_col))} doehm/tidytuesday #rstats #tidytuesday") 41 | 42 | # plot -------------------------------------------------------------------- 43 | 44 | df_base |> 45 | time_log() |> 46 | ggplot() + 47 | geom_text(aes(x, 0, label = title, colour = tidy, size = tidy), family = ft_text, angle = df_base$angle, hjust = df_base$just) + 48 | annotate("richtext", x = 1, y = -4, label = title, family = ft_text, size = 80, lineheight = 0.4, fill = NA, label.colour = NA, colour = txt_col) + 49 | annotate("richtext", x = 150, y = -3, label = subtitle, family = ft_text, size = 24, lineheight = 0.4, fill = NA, label.colour = NA, colour = txt_col) + 50 | scale_size_manual(values = c(10, 13)) + 51 | scale_colour_manual(values = c(txt_col, "darkred")) + 52 | labs( 53 | caption = caption 54 | ) + 55 | xlim(c(0.5, 300.5)) + 56 | ylim(c(-5, 2)) + 57 | coord_polar(clip = "off") + 58 | theme_void() + 59 | theme( 60 | text = element_text(colour = txt_col), 61 | plot.background = element_rect(fill = bg, colour = bg), 62 | plot.caption = element_markdown(hjust = 0.5, family = ft_text, size = 36, lineheight = 0.35, margin = margin(t = 70, b = 20)), 63 | plot.margin = margin(t = 50, r = 20, b = 0, l = 20), 64 | legend.position = "none" 65 | ) + 66 | ggsave("2022/week17-kaggle/kaggle.png", height = 18, width = 16.45) 67 | -------------------------------------------------------------------------------- /2022/week17-kaggle/kaggle.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/doehm/tidyTuesday/74fb84eee433ae1741e31857547909c6ce2c5240/2022/week17-kaggle/kaggle.png -------------------------------------------------------------------------------- /2022/week17-kaggle/log-posted.txt: -------------------------------------------------------------------------------- 1 | 2022-04-27 21:52:03 2 | -------------------------------------------------------------------------------- /2022/week17-kaggle/log.txt: -------------------------------------------------------------------------------- 1 | 2022-04-26 22:18:04 2 | 2022-04-26 22:18:11 3 | 2022-04-26 22:18:24 4 | 2022-04-26 22:20:33 5 | 2022-04-26 22:20:50 6 | 2022-04-26 22:20:56 7 | 2022-04-26 22:21:00 8 | 2022-04-26 22:21:09 9 | 2022-04-26 22:21:15 10 | 2022-04-26 22:21:41 11 | 2022-04-26 22:22:34 12 | 2022-04-26 22:23:38 13 | 2022-04-27 06:37:34 14 | 2022-04-27 06:37:49 15 | 2022-04-27 06:39:22 16 | 2022-04-27 06:40:43 17 | 2022-04-27 06:43:08 18 | 2022-04-27 06:43:16 19 | 2022-04-27 06:43:20 20 | 2022-04-27 06:43:22 21 | 2022-04-27 07:45:24 22 | 2022-04-27 07:46:36 23 | 2022-04-27 07:46:39 24 | 2022-04-27 07:47:41 25 | 2022-04-27 07:52:22 26 | 2022-04-27 07:52:29 27 | 2022-04-27 07:53:22 28 | 2022-04-27 07:53:24 29 | 2022-04-27 07:54:05 30 | 2022-04-27 07:54:08 31 | 2022-04-27 07:54:46 32 | 2022-04-27 07:54:53 33 | 2022-04-27 07:55:26 34 | 2022-04-27 07:56:28 35 | 2022-04-27 07:56:31 36 | 2022-04-27 07:57:18 37 | 2022-04-27 07:57:20 38 | 2022-04-27 07:58:37 39 | 2022-04-27 07:58:43 40 | 2022-04-27 07:58:45 41 | 2022-04-27 07:59:48 42 | 2022-04-27 08:00:08 43 | 2022-04-27 08:00:45 44 | 2022-04-27 12:12:46 45 | 2022-04-27 12:13:10 46 | 2022-04-27 12:13:35 47 | 2022-04-27 12:13:46 48 | 2022-04-27 12:15:37 49 | 2022-04-27 12:15:40 50 | 2022-04-27 12:17:15 51 | 2022-04-27 12:17:24 52 | 2022-04-27 12:17:49 53 | 2022-04-27 12:17:51 54 | 2022-04-27 12:18:28 55 | 2022-04-27 12:18:47 56 | 2022-04-27 12:19:04 57 | 2022-04-27 12:19:41 58 | 2022-04-27 12:20:54 59 | 2022-04-27 12:21:38 60 | 2022-04-27 12:21:47 61 | 2022-04-27 12:21:49 62 | 2022-04-27 12:22:32 63 | 2022-04-27 12:23:18 64 | 2022-04-27 12:23:25 65 | 2022-04-27 12:23:48 66 | 2022-04-27 12:24:12 67 | 2022-04-27 12:25:28 68 | 2022-04-27 13:16:45 69 | 2022-04-27 13:16:46 70 | 2022-04-27 13:17:45 71 | 2022-04-27 13:18:54 72 | 2022-04-27 13:19:33 73 | 2022-04-27 13:22:25 74 | 2022-04-27 13:22:42 75 | 2022-04-27 17:36:21 76 | 2022-04-27 17:36:33 77 | 2022-04-27 17:37:53 78 | 2022-04-27 17:38:28 79 | 2022-04-27 17:39:11 80 | 2022-04-27 17:39:50 81 | 2022-04-27 17:41:08 82 | 2022-04-27 17:43:46 83 | 2022-04-27 17:44:40 84 | 2022-04-27 17:45:30 85 | 2022-04-27 17:45:53 86 | 2022-04-27 17:46:28 87 | 2022-04-27 17:46:55 88 | 2022-04-27 17:47:22 89 | 2022-04-27 17:47:44 90 | 2022-04-27 17:48:36 91 | 2022-04-27 17:55:06 92 | 2022-04-27 17:57:04 93 | 2022-04-27 17:57:50 94 | 2022-04-27 17:59:24 95 | 2022-04-27 18:04:07 96 | 2022-04-27 18:04:56 97 | 2022-04-27 18:05:32 98 | 2022-04-27 18:06:03 99 | 2022-04-27 18:07:28 100 | 2022-04-27 18:10:23 101 | 2022-04-27 18:13:39 102 | 2022-04-27 18:14:54 103 | 2022-04-27 18:15:29 104 | 2022-04-27 18:21:03 105 | 2022-04-27 18:25:28 106 | 2022-04-27 18:25:32 107 | 2022-04-27 18:44:38 108 | 2022-04-27 18:45:04 109 | 2022-04-27 18:45:31 110 | 2022-04-27 18:46:20 111 | 2022-04-27 18:47:53 112 | 2022-04-27 18:47:55 113 | 2022-04-27 18:52:16 114 | 2022-04-27 18:52:19 115 | 2022-04-27 18:53:31 116 | 2022-04-27 18:53:33 117 | 2022-04-27 18:57:02 118 | 2022-04-27 18:57:43 119 | 2022-04-27 19:04:24 120 | 2022-04-27 19:12:03 121 | 2022-04-27 19:15:16 122 | 2022-04-27 19:16:21 123 | 2022-04-27 19:19:51 124 | 2022-04-27 19:20:27 125 | 2022-04-27 19:20:29 126 | 2022-04-27 19:21:02 127 | 2022-04-27 21:18:51 128 | 2022-04-27 21:18:54 129 | 2022-04-27 21:19:56 130 | 2022-04-27 21:19:58 131 | 2022-04-27 21:20:49 132 | 2022-04-27 21:21:38 133 | 2022-04-27 21:21:43 134 | 2022-04-27 21:22:35 135 | 2022-04-27 21:23:21 136 | 2022-04-27 21:23:56 137 | 2022-04-27 21:26:18 138 | 2022-04-27 21:26:21 139 | 2022-04-27 21:27:39 140 | 2022-04-27 21:28:51 141 | 2022-04-27 21:29:03 142 | 2022-04-27 21:29:36 143 | 2022-04-27 21:30:22 144 | 2022-04-27 21:32:18 145 | 2022-04-27 21:32:57 146 | 2022-04-27 21:33:24 147 | 2022-04-27 21:33:52 148 | 2022-04-27 21:35:41 149 | 2022-04-27 21:35:45 150 | -------------------------------------------------------------------------------- /2022/week18-renewables/log-posted.txt: -------------------------------------------------------------------------------- 1 | 2022-05-09 15:22:33 2 | -------------------------------------------------------------------------------- /2022/week18-renewables/log.txt: -------------------------------------------------------------------------------- 1 | 2022-05-08 22:20:44 2 | 2022-05-08 22:20:50 3 | 2022-05-08 22:23:08 4 | 2022-05-08 22:23:41 5 | 2022-05-08 22:24:42 6 | 2022-05-08 22:32:51 7 | 2022-05-08 22:32:59 8 | 2022-05-08 22:33:11 9 | 2022-05-08 22:34:56 10 | 2022-05-08 22:35:19 11 | 2022-05-08 22:35:36 12 | 2022-05-08 22:37:45 13 | 2022-05-08 22:37:54 14 | 2022-05-08 22:44:31 15 | 2022-05-08 22:46:45 16 | 2022-05-08 22:47:23 17 | 2022-05-08 22:48:01 18 | 2022-05-08 22:48:22 19 | 2022-05-08 22:49:41 20 | 2022-05-08 22:49:56 21 | 2022-05-08 22:51:10 22 | 2022-05-08 22:51:12 23 | 2022-05-08 22:56:05 24 | 2022-05-08 22:56:24 25 | 2022-05-08 22:56:41 26 | 2022-05-08 22:57:10 27 | 2022-05-08 22:57:47 28 | 2022-05-08 22:58:15 29 | 2022-05-08 22:58:43 30 | 2022-05-08 22:59:19 31 | 2022-05-08 22:59:56 32 | 2022-05-08 22:59:57 33 | 2022-05-08 23:00:26 34 | 2022-05-08 23:00:44 35 | 2022-05-08 23:00:45 36 | 2022-05-08 23:00:49 37 | 2022-05-08 23:11:46 38 | 2022-05-08 23:11:46 39 | 2022-05-08 23:12:48 40 | 2022-05-08 23:12:48 41 | 2022-05-08 23:13:56 42 | 2022-05-08 23:13:56 43 | 2022-05-08 23:14:29 44 | 2022-05-08 23:14:30 45 | 2022-05-09 06:54:32 46 | 2022-05-09 06:58:06 47 | 2022-05-09 06:58:06 48 | 2022-05-09 06:59:25 49 | 2022-05-09 06:59:25 50 | 2022-05-09 07:01:45 51 | 2022-05-09 07:01:45 52 | 2022-05-09 07:03:40 53 | 2022-05-09 07:03:40 54 | 2022-05-09 07:04:45 55 | 2022-05-09 07:04:45 56 | 2022-05-09 07:06:24 57 | 2022-05-09 07:06:25 58 | 2022-05-09 07:08:08 59 | 2022-05-09 07:11:24 60 | 2022-05-09 07:11:24 61 | 2022-05-09 07:13:29 62 | 2022-05-09 07:13:29 63 | 2022-05-09 07:19:39 64 | 2022-05-09 07:19:39 65 | 2022-05-09 07:26:51 66 | 2022-05-09 07:26:51 67 | 2022-05-09 07:33:00 68 | 2022-05-09 07:33:01 69 | 2022-05-09 07:37:10 70 | 2022-05-09 07:37:10 71 | -------------------------------------------------------------------------------- /2022/week18-renewables/new.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/doehm/tidyTuesday/74fb84eee433ae1741e31857547909c6ce2c5240/2022/week18-renewables/new.png -------------------------------------------------------------------------------- /2022/week18-renewables/renewables.R: -------------------------------------------------------------------------------- 1 | # https://github.com/rfordatascience/tidytuesday 2 | 3 | source("scripts/startup.R") 4 | 5 | log_file <<- "2022/week18-renewables/log.txt" 6 | 7 | # load data --------------------------------------------------------------- 8 | 9 | capacity <- readr::read_csv('https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2022/2022-05-03/capacity.csv') 10 | wind <- readr::read_csv('https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2022/2022-05-03/wind.csv') 11 | solar <- readr::read_csv('https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2022/2022-05-03/solar.csv') 12 | average_cost <- readr::read_csv('https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2022/2022-05-03/average_cost.csv') 13 | 14 | # fonts and palettes ------------------------------------------------------ 15 | 16 | pal <- spec[c(5, 2)] 17 | bg <- dark 18 | txt_col <- "white" 19 | 20 | ft_text <- "sec" 21 | ft_title <- ft_text 22 | 23 | # wrangle ----------------------------------------------------------------- 24 | 25 | df_capacity <- bind_rows( 26 | "Solar" = solar |> 27 | select(date, capacity = solar_capacity), 28 | "Wind" = wind |> 29 | select(date, capacity = wind_capacity), 30 | .id = "energy_type" 31 | ) 32 | 33 | df_cost <- bind_rows( 34 | "Solar" = solar |> 35 | select(date, mwh = solar_mwh), 36 | "Wind" = wind |> 37 | select(date, mwh = wind_mwh), 38 | .id = "energy_type" 39 | ) 40 | 41 | # titles ------------------------------------------------------------------ 42 | 43 | title <- glue("Wind and Solar Power Generation") 44 | subtitle <- glue("The cost of solar has dropped by 77% over the last 13 years and now on par with wind") 45 | subtitle_cost <- str_rich_wrap(glue("Whereas the average cost per MWh has plummeted suggesting there are other factors than just capacity influencing price."), 62) 46 | subtitle_cap <- str_rich_wrap(glue("The capacity of wind and solar power generation has steadily increased over the last 13 years, particulalry solar in the last 5"), 62) 47 | caption <- glue("Graphic: {get_icon('twitter', 10, fill = list(bg = dark, img = light))} @danoehm / Source: Berkeley Lab / Code: {get_icon('github', 10, fill = list(bg = dark, img = light))} doehm/tidytuesday #rstats #tidytuesday") 48 | colour <- "Energy type" 49 | 50 | # plot -------------------------------------------------------------------- 51 | 52 | g_base <- df_cost |> 53 | time_log() |> 54 | ggplot() + 55 | geom_point(aes(date, mwh, colour = energy_type), size = 2, alpha = 0.3) + 56 | geom_smooth(aes(date, mwh, colour = energy_type), se = FALSE, method = "gam") + 57 | 58 | # theme and scales and labs 59 | scale_fill_manual(values = pal) + 60 | scale_colour_manual(values = pal) + 61 | labs( 62 | subtitle = subtitle_cost, 63 | y = "$/MWh", 64 | fill = fill, 65 | colour = colour 66 | ) + 67 | theme_void() + 68 | theme( 69 | text = element_text(colour = txt_col, family = ft_text), 70 | plot.background = element_rect(fill = bg, colour = bg), 71 | plot.title = element_text(hjust = 0.5, family = ft_title, size = 250), 72 | plot.subtitle = element_markdown(hjust = 0.5, family = ft_text, size = 48, lineheight = 0.35, halign = 0), 73 | plot.caption = element_markdown(hjust = 0.5, family = ft_text, size = 36, lineheight = 0.35, margin = margin(t = 20)), 74 | plot.margin = margin(t = 20, r = 20, b = 20, l = 20), 75 | legend.title = element_text(family = ft_text, size = 36, lineheight = 0.25, face = "bold"), 76 | legend.text = element_text(family = ft_text, size = 36, face = "bold"), 77 | legend.position = "bottom", 78 | axis.text = element_text(size = 48), 79 | axis.title.y = element_text(size = 48) 80 | ) 81 | 82 | 83 | g_cap <- df_capacity |> 84 | mutate(year = year(date)) |> 85 | time_log() |> 86 | ggplot() + 87 | geom_point(aes(date, capacity, colour = energy_type), size = 2, alpha = 0.3) + 88 | geom_smooth(aes(date, capacity, colour = energy_type), se = FALSE, method = "gam", span = 0.9) + 89 | 90 | # theme and scales and labs 91 | scale_fill_manual(values = pal) + 92 | scale_colour_manual(values = pal) + 93 | labs( 94 | subtitle = subtitle_cap, 95 | y = "GW", 96 | colour = colour 97 | ) + 98 | theme_void() + 99 | theme( 100 | text = element_text(colour = txt_col, family = ft_text), 101 | plot.background = element_rect(fill = bg, colour = bg), 102 | plot.title = element_text(hjust = 0.5, family = ft_title, size = 250), 103 | plot.subtitle = element_markdown(hjust = 0.5, family = ft_text, size = 48, lineheight = 0.35, halign = 0), 104 | plot.caption = element_markdown(hjust = 0.5, family = ft_text, size = 36, lineheight = 0.35, margin = margin(t = 20)), 105 | plot.margin = margin(t = 20, r = 20, b = 20, l = 20), 106 | legend.title = element_text(family = ft_text, size = 36, lineheight = 0.25, face = "bold"), 107 | legend.text = element_text(family = ft_text, size = 36, face = "bold"), 108 | legend.position = "bottom", 109 | axis.text = element_text(size = 48), 110 | axis.title.y = element_text(size = 48) 111 | ) 112 | 113 | # patch it together 114 | g_cap + 115 | g_base + 116 | plot_annotation( 117 | title = title, 118 | subtitle = subtitle, 119 | caption = caption, 120 | theme = theme( 121 | text = element_text(colour = txt_col), 122 | plot.background = element_rect(fill = bg, colour = bg), 123 | plot.title = element_markdown(hjust = 0.5, family = ft_title, size = 120, margin = margin(t = 20)), 124 | plot.subtitle = element_markdown(hjust = 0.5, family = ft_text, size = 64, lineheight = 0.35, margin = margin(t = 10)), 125 | plot.caption = element_markdown(hjust = 0.5, family = ft_text, size = 36, lineheight = 0.35, margin = margin(t = 0, b =5)) 126 | ) 127 | ) + 128 | ggsave("2022/week18-renewables/renewables.png", height = 9, width = 18) 129 | 130 | -------------------------------------------------------------------------------- /2022/week18-renewables/renewables.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/doehm/tidyTuesday/74fb84eee433ae1741e31857547909c6ce2c5240/2022/week18-renewables/renewables.png -------------------------------------------------------------------------------- /2022/week20-eurovision/eurovision.R: -------------------------------------------------------------------------------- 1 | # https://github.com/rfordatascience/tidytuesday 2 | 3 | source("scripts/startup.R") 4 | 5 | log_file <<- "2022/week20-eurovision/log.txt" 6 | 7 | # load data --------------------------------------------------------------- 8 | 9 | eurovision <- readr::read_csv('https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2022/2022-05-17/eurovision.csv') 10 | 11 | # fonts and palettes ------------------------------------------------------ 12 | 13 | pal_bright <- colorRampPalette(bright)(52) 14 | pal <- c(rgb(167, 124, 107, maxColorValue = 255), rgb(124, 124, 124, maxColorValue = 255), rgb(155, 114, 30, maxColorValue = 255)) 15 | bg <- dark 16 | txt_col <- "white" 17 | 18 | ft_text <- "zen" 19 | ft_title <- ft_text 20 | 21 | ft1 <- 60 22 | 23 | # wrangle ----------------------------------------------------------------- 24 | 25 | df_points <- eurovision |> 26 | group_by(year, artist_country) |> 27 | summarise(points = sum(total_points,na.rm = TRUE)) |> 28 | arrange(year, artist_country) |> 29 | group_by(artist_country) |> 30 | mutate(cm_points = cumsum(points)) 31 | 32 | df_base <- eurovision |> 33 | filter(year == 2022) |> 34 | group_by(artist_country) |> 35 | mutate(total = sum(total_points)) |> 36 | ungroup() |> 37 | mutate( 38 | artist_country = fct_reorder(artist_country, total, min), 39 | section = factor(section, levels = c("first-semi-final", "second-semi-final", "grand-final")) 40 | ) 41 | 42 | # titles ------------------------------------------------------------------ 43 | 44 | title <- "EUROVISION" 45 | subtitle <- str_rich_wrap("Points awarded for the 2022 Eurovision Song Contest", 100) 46 | caption <- glue("Graphic: {get_icon('twitter', 10, fill = list(bg = bg, img = txt_col))} @danoehm / Source: Eurovision @tanya_shapiro / Code: {get_icon('github', 10, fill = list(bg = bg, img = txt_col))} doehm/tidytuesday #rstats #tidytuesday") 47 | fill <- "Section" 48 | 49 | # plot -------------------------------------------------------------------- 50 | 51 | df_base |> 52 | ggplot(aes(artist_country, total_points, fill = section)) + 53 | geom_chicklet(radius = grid::unit(8, "pt"), colour = NA) + 54 | coord_flip() + 55 | 56 | # theme and scales and labs 57 | scale_fill_manual(values = pal) + 58 | labs( 59 | title = title, 60 | subtitle = subtitle, 61 | caption = caption, 62 | y = "Points", 63 | fill = fill, 64 | colour = colour 65 | ) + 66 | theme_void() + 67 | theme( 68 | text = element_text(family = ft_text, colour = txt_col), 69 | plot.background = element_rect(fill = bg, colour = bg), 70 | plot.title = element_text(hjust = 0.5, family = ft_title, size = 250), 71 | plot.subtitle = element_markdown(hjust = 0.5, family = ft_text, size = 80, lineheight = 0.35), 72 | plot.caption = element_markdown(hjust = 0.5, family = ft_text, size = ft1, lineheight = 0.35, margin = margin(t = 20)), 73 | plot.margin = margin(t = 20, r = 20, b = 20, l = 20), 74 | legend.title = element_text(family = ft_text, size = ft1, lineheight = 0.25, face = "bold"), 75 | legend.text = element_text(family = ft_text, size = ft1, face = "bold"), 76 | legend.position = "bottom", 77 | axis.text = element_text(size = ft1, hjust = 1), 78 | axis.title.x = element_text(size = ft1) 79 | ) 80 | 81 | ggsave("2022/week20-eurovision/eurovision1.png", height = 12.25, width = 10) 82 | 83 | # album cover outtake ----------------------------------------------------- 84 | 85 | bg <- "white" 86 | txt_col <- dark 87 | df_points |> 88 | ggplot(aes(year, points, fill = artist_country)) + 89 | geom_stream() + 90 | 91 | # theme and scales and labs 92 | scale_fill_manual(values = pal_bright) + 93 | labs(caption = caption) + 94 | theme_void() + 95 | theme( 96 | text = element_text(colour = txt_col), 97 | plot.background = element_rect(fill = bg, colour = bg), 98 | plot.caption = element_markdown(hjust = 0.5, family = ft_text, size = 36, lineheight = 0.35, margin = margin(t = 20)), 99 | plot.margin = margin(t = 20, r = -50, b = 20, l = -50), 100 | legend.position = "none" 101 | ) 102 | 103 | ggsave("2022/week20-eurovision/eurovision.png", height = 12.25, width = 12.25) 104 | -------------------------------------------------------------------------------- /2022/week20-eurovision/eurovision.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/doehm/tidyTuesday/74fb84eee433ae1741e31857547909c6ce2c5240/2022/week20-eurovision/eurovision.png -------------------------------------------------------------------------------- /2022/week20-eurovision/eurovision1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/doehm/tidyTuesday/74fb84eee433ae1741e31857547909c6ce2c5240/2022/week20-eurovision/eurovision1.png -------------------------------------------------------------------------------- /2022/week20-eurovision/log-posted.txt: -------------------------------------------------------------------------------- 1 | 2022-05-18 06:37:08 2 | -------------------------------------------------------------------------------- /2022/week20-eurovision/log.txt: -------------------------------------------------------------------------------- 1 | 2022-05-17 16:17:02 2 | 2022-05-17 16:18:13 3 | 2022-05-17 16:21:47 4 | 2022-05-17 16:25:20 5 | 2022-05-17 16:25:28 6 | 2022-05-17 16:28:44 7 | 2022-05-17 16:28:57 8 | 2022-05-17 16:29:58 9 | 2022-05-17 16:30:12 10 | 2022-05-17 16:30:44 11 | 2022-05-17 16:33:14 12 | 2022-05-17 16:33:18 13 | 2022-05-17 16:34:49 14 | 2022-05-17 16:35:42 15 | 2022-05-17 16:37:13 16 | 2022-05-17 16:38:44 17 | 2022-05-17 16:41:04 18 | 2022-05-17 16:41:38 19 | 2022-05-17 16:43:32 20 | 2022-05-17 16:44:47 21 | 2022-05-17 16:45:13 22 | 2022-05-17 16:45:42 23 | 2022-05-17 16:51:05 24 | 2022-05-17 17:08:55 25 | 2022-05-17 17:09:32 26 | 2022-05-17 17:38:54 27 | 2022-05-17 17:40:42 28 | 2022-05-17 17:40:48 29 | 2022-05-17 17:41:01 30 | 2022-05-17 17:41:06 31 | 2022-05-17 17:42:43 32 | 2022-05-17 17:43:11 33 | 2022-05-17 17:43:14 34 | 2022-05-17 17:56:28 35 | 2022-05-17 17:57:27 36 | 2022-05-17 17:58:02 37 | 2022-05-17 17:58:24 38 | 2022-05-17 17:59:18 39 | 2022-05-17 17:59:26 40 | 2022-05-17 17:59:53 41 | 2022-05-17 18:01:08 42 | 2022-05-17 18:01:27 43 | 2022-05-17 18:04:13 44 | 2022-05-17 18:05:31 45 | 2022-05-17 18:06:54 46 | 2022-05-17 18:07:14 47 | 2022-05-17 18:07:41 48 | 2022-05-17 18:08:00 49 | 2022-05-17 18:08:56 50 | 2022-05-17 18:09:44 51 | 2022-05-17 18:11:07 52 | 2022-05-17 18:12:00 53 | 2022-05-17 18:24:13 54 | 2022-05-17 18:25:43 55 | 2022-05-17 18:27:01 56 | 2022-05-17 18:28:43 57 | 2022-05-17 19:13:18 58 | 2022-05-17 19:14:02 59 | 2022-05-17 19:15:01 60 | 2022-05-17 19:17:19 61 | 2022-05-17 19:18:28 62 | 2022-05-17 19:19:09 63 | 2022-05-17 19:21:56 64 | 2022-05-17 19:23:05 65 | 2022-05-17 19:24:20 66 | 2022-05-17 19:25:46 67 | -------------------------------------------------------------------------------- /2022/week21-rugby/log-posted.txt: -------------------------------------------------------------------------------- 1 | 2022-05-25 22:51:21 2 | -------------------------------------------------------------------------------- /2022/week21-rugby/log.txt: -------------------------------------------------------------------------------- 1 | 2022-05-24 20:09:50 2 | 2022-05-24 20:10:38 3 | 2022-05-24 20:12:17 4 | 2022-05-24 20:12:49 5 | 2022-05-24 20:17:59 6 | 2022-05-24 20:18:04 7 | 2022-05-24 20:18:29 8 | 2022-05-24 20:18:40 9 | 2022-05-24 20:18:45 10 | 2022-05-24 20:19:02 11 | 2022-05-24 20:19:22 12 | 2022-05-24 20:19:27 13 | 2022-05-24 20:20:11 14 | 2022-05-24 20:20:24 15 | 2022-05-24 20:21:37 16 | 2022-05-24 20:21:39 17 | 2022-05-24 20:22:00 18 | 2022-05-24 20:22:02 19 | 2022-05-24 20:23:14 20 | 2022-05-24 20:23:45 21 | 2022-05-24 20:23:54 22 | 2022-05-24 20:24:03 23 | 2022-05-24 20:24:31 24 | 2022-05-24 20:24:43 25 | 2022-05-24 20:24:57 26 | 2022-05-24 20:25:08 27 | 2022-05-24 20:25:16 28 | 2022-05-24 20:25:21 29 | 2022-05-24 20:25:28 30 | 2022-05-24 20:25:53 31 | 2022-05-24 20:27:28 32 | 2022-05-24 20:27:41 33 | 2022-05-24 22:32:40 34 | 2022-05-24 22:33:28 35 | 2022-05-24 22:34:23 36 | 2022-05-24 22:34:32 37 | 2022-05-24 22:35:11 38 | 2022-05-24 22:40:32 39 | 2022-05-24 22:40:41 40 | 2022-05-24 22:41:30 41 | 2022-05-24 22:41:38 42 | 2022-05-24 22:42:51 43 | 2022-05-24 22:43:02 44 | 2022-05-24 22:43:13 45 | 2022-05-24 22:43:42 46 | 2022-05-24 22:44:10 47 | 2022-05-24 22:44:29 48 | 2022-05-24 22:44:49 49 | 2022-05-24 22:46:14 50 | 2022-05-24 22:46:45 51 | 2022-05-24 22:54:38 52 | 2022-05-24 22:54:45 53 | 2022-05-24 23:10:32 54 | 2022-05-24 23:10:41 55 | 2022-05-24 23:10:58 56 | 2022-05-24 23:11:10 57 | 2022-05-24 23:11:49 58 | 2022-05-24 23:12:48 59 | 2022-05-24 23:13:54 60 | 2022-05-24 23:15:43 61 | 2022-05-25 06:56:00 62 | 2022-05-25 07:00:06 63 | 2022-05-25 07:00:14 64 | 2022-05-25 07:00:23 65 | 2022-05-25 07:00:51 66 | 2022-05-25 07:07:59 67 | 2022-05-25 07:10:01 68 | 2022-05-25 07:11:35 69 | 2022-05-25 07:11:51 70 | 2022-05-25 07:12:14 71 | 2022-05-25 07:13:59 72 | 2022-05-25 07:25:44 73 | 2022-05-25 07:25:53 74 | 2022-05-25 07:26:02 75 | 2022-05-25 07:30:15 76 | 2022-05-25 07:31:27 77 | 2022-05-25 07:31:39 78 | 2022-05-25 07:34:37 79 | 2022-05-25 07:37:07 80 | 2022-05-25 07:37:09 81 | 2022-05-25 07:37:10 82 | 2022-05-25 07:38:10 83 | 2022-05-25 07:38:11 84 | 2022-05-25 07:38:12 85 | 2022-05-25 07:39:47 86 | 2022-05-25 07:39:49 87 | 2022-05-25 07:39:51 88 | 2022-05-25 07:41:49 89 | 2022-05-25 17:40:23 90 | 2022-05-25 17:48:05 91 | 2022-05-25 17:53:45 92 | 2022-05-25 17:56:20 93 | 2022-05-25 17:58:04 94 | 2022-05-25 17:58:20 95 | 2022-05-25 17:58:33 96 | 2022-05-25 17:59:11 97 | 2022-05-25 17:59:27 98 | 2022-05-25 17:59:46 99 | 2022-05-25 18:00:01 100 | 2022-05-25 18:00:12 101 | 2022-05-25 18:00:33 102 | 2022-05-25 18:01:19 103 | 2022-05-25 18:01:48 104 | 2022-05-25 18:02:22 105 | 2022-05-25 18:02:35 106 | 2022-05-25 18:02:47 107 | 2022-05-25 18:02:57 108 | 2022-05-25 18:05:40 109 | 2022-05-25 18:06:28 110 | 2022-05-25 18:07:19 111 | 2022-05-25 18:13:58 112 | 2022-05-25 18:16:07 113 | 2022-05-25 18:16:41 114 | 2022-05-25 18:17:06 115 | 2022-05-25 18:17:39 116 | 2022-05-25 18:18:32 117 | 2022-05-25 18:18:48 118 | 2022-05-25 18:18:49 119 | 2022-05-25 18:18:51 120 | 2022-05-25 18:18:52 121 | 2022-05-25 18:20:13 122 | 2022-05-25 18:20:48 123 | 2022-05-25 18:21:02 124 | 2022-05-25 18:24:54 125 | 2022-05-25 18:26:10 126 | 2022-05-25 18:28:15 127 | 2022-05-25 18:30:45 128 | 2022-05-25 18:31:09 129 | 2022-05-25 18:39:00 130 | 2022-05-25 18:39:31 131 | 2022-05-25 18:40:08 132 | 2022-05-25 18:40:29 133 | 2022-05-25 18:41:06 134 | 2022-05-25 18:41:29 135 | 2022-05-25 18:41:54 136 | 2022-05-25 18:42:10 137 | 2022-05-25 18:42:55 138 | 2022-05-25 18:43:07 139 | 2022-05-25 18:43:44 140 | 2022-05-25 18:49:47 141 | 2022-05-25 18:49:56 142 | 2022-05-25 18:51:28 143 | 2022-05-25 19:50:47 144 | 2022-05-25 19:52:46 145 | 2022-05-25 19:53:31 146 | 2022-05-25 19:54:10 147 | 2022-05-25 19:54:50 148 | 2022-05-25 19:55:10 149 | 2022-05-25 19:59:17 150 | 2022-05-25 19:59:32 151 | 2022-05-25 20:00:17 152 | 2022-05-25 20:00:46 153 | 2022-05-25 20:01:12 154 | 2022-05-25 20:02:15 155 | 2022-05-25 20:08:31 156 | 2022-05-25 20:09:11 157 | 2022-05-25 20:12:35 158 | 2022-05-25 20:24:52 159 | 2022-05-25 20:31:46 160 | 2022-05-25 20:31:47 161 | 2022-05-25 20:31:56 162 | 2022-05-25 20:32:10 163 | 2022-05-25 20:32:11 164 | 2022-05-25 20:32:13 165 | 2022-05-25 20:38:20 166 | 2022-05-25 20:40:54 167 | 2022-05-25 20:57:48 168 | 2022-05-25 20:57:54 169 | 2022-05-25 20:58:53 170 | 2022-05-25 21:01:00 171 | 2022-05-25 21:01:28 172 | 2022-05-25 21:02:06 173 | 2022-05-25 21:02:06 174 | 2022-05-25 21:07:51 175 | 2022-05-25 21:09:58 176 | 2022-05-25 21:11:35 177 | 2022-05-25 21:35:05 178 | 2022-05-25 21:35:05 179 | 2022-05-25 21:35:05 180 | 2022-05-25 21:37:11 181 | 2022-05-25 21:39:57 182 | 2022-05-25 21:40:49 183 | 2022-05-25 22:14:14 184 | 2022-05-25 22:15:45 185 | 2022-05-25 22:16:43 186 | 2022-05-25 22:17:25 187 | 2022-05-25 22:19:33 188 | 2022-05-25 22:23:01 189 | 2022-05-25 22:23:12 190 | 2022-05-25 22:26:33 191 | 2022-05-25 22:27:38 192 | 2022-05-25 22:29:14 193 | 2022-05-25 22:31:06 194 | 2022-05-25 22:31:53 195 | 2022-05-25 22:32:48 196 | 2022-05-25 22:34:24 197 | -------------------------------------------------------------------------------- /2022/week21-rugby/rugby.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/doehm/tidyTuesday/74fb84eee433ae1741e31857547909c6ce2c5240/2022/week21-rugby/rugby.png -------------------------------------------------------------------------------- /2022/week22-polls/log-posted.txt: -------------------------------------------------------------------------------- 1 | 2022-06-02 19:17:22 2 | -------------------------------------------------------------------------------- /2022/week22-polls/log.txt: -------------------------------------------------------------------------------- 1 | 2022-05-31 19:40:30 2 | 2022-05-31 19:40:48 3 | 2022-05-31 19:40:56 4 | 2022-05-31 19:41:02 5 | 2022-05-31 21:14:49 6 | 2022-05-31 21:15:08 7 | 2022-05-31 21:15:35 8 | 2022-05-31 21:15:50 9 | 2022-05-31 21:15:57 10 | 2022-05-31 21:18:16 11 | 2022-05-31 21:23:32 12 | 2022-05-31 21:23:41 13 | 2022-05-31 21:24:51 14 | 2022-05-31 21:25:28 15 | 2022-05-31 21:26:27 16 | 2022-05-31 21:27:19 17 | 2022-05-31 21:27:48 18 | 2022-05-31 22:24:16 19 | 2022-05-31 22:26:15 20 | 2022-05-31 22:26:35 21 | 2022-05-31 22:27:42 22 | 2022-05-31 22:28:09 23 | 2022-05-31 22:28:24 24 | 2022-05-31 22:29:10 25 | 2022-05-31 22:30:03 26 | 2022-05-31 22:30:43 27 | 2022-05-31 22:33:26 28 | 2022-05-31 22:33:57 29 | 2022-05-31 22:34:08 30 | 2022-05-31 22:34:23 31 | 2022-05-31 22:35:21 32 | 2022-05-31 22:40:24 33 | 2022-05-31 22:49:30 34 | 2022-05-31 22:52:01 35 | 2022-05-31 22:53:29 36 | 2022-05-31 22:56:10 37 | 2022-05-31 22:58:08 38 | 2022-05-31 23:04:40 39 | 2022-05-31 23:06:02 40 | 2022-05-31 23:06:31 41 | 2022-05-31 23:08:09 42 | 2022-06-01 06:40:00 43 | 2022-06-01 06:43:01 44 | 2022-06-01 06:43:34 45 | 2022-06-01 06:43:39 46 | 2022-06-01 06:43:59 47 | 2022-06-01 06:44:53 48 | 2022-06-01 06:57:33 49 | 2022-06-01 06:57:40 50 | 2022-06-01 06:58:18 51 | 2022-06-01 06:58:24 52 | 2022-06-01 07:00:16 53 | 2022-06-01 07:01:27 54 | 2022-06-01 07:02:23 55 | 2022-06-01 07:02:48 56 | 2022-06-01 07:04:51 57 | 2022-06-01 07:05:11 58 | 2022-06-01 07:05:45 59 | 2022-06-01 07:06:12 60 | 2022-06-01 07:06:33 61 | 2022-06-01 07:06:54 62 | 2022-06-01 07:07:27 63 | 2022-06-01 07:09:24 64 | 2022-06-01 07:09:29 65 | 2022-06-01 07:10:38 66 | 2022-06-01 07:11:06 67 | 2022-06-01 07:11:59 68 | 2022-06-01 07:12:13 69 | 2022-06-01 07:13:41 70 | 2022-06-01 07:13:57 71 | 2022-06-01 07:15:06 72 | 2022-06-01 07:16:58 73 | 2022-06-01 07:17:36 74 | 2022-06-01 07:18:22 75 | 2022-06-01 07:18:37 76 | 2022-06-01 07:20:18 77 | 2022-06-01 07:22:19 78 | 2022-06-01 07:23:12 79 | 2022-06-01 07:23:49 80 | 2022-06-01 07:25:33 81 | 2022-06-01 07:26:11 82 | 2022-06-01 07:34:52 83 | 2022-06-01 07:35:33 84 | 2022-06-01 13:10:25 85 | 2022-06-01 13:10:55 86 | 2022-06-01 13:19:24 87 | 2022-06-01 13:19:37 88 | 2022-06-01 18:03:34 89 | 2022-06-01 18:04:51 90 | 2022-06-01 18:05:29 91 | 2022-06-01 18:05:48 92 | 2022-06-01 18:06:39 93 | 2022-06-01 18:08:02 94 | 2022-06-01 18:08:21 95 | 2022-06-01 18:10:44 96 | 2022-06-01 18:11:40 97 | 2022-06-01 18:12:31 98 | 2022-06-01 18:12:54 99 | 2022-06-01 18:14:42 100 | 2022-06-01 18:16:07 101 | 2022-06-01 18:29:44 102 | 2022-06-01 18:34:28 103 | 2022-06-01 18:41:17 104 | 2022-06-01 18:46:55 105 | 2022-06-01 19:04:35 106 | 2022-06-01 19:05:13 107 | 2022-06-01 19:05:33 108 | 2022-06-01 19:06:00 109 | 2022-06-01 19:08:44 110 | 2022-06-01 19:10:43 111 | 2022-06-01 19:11:02 112 | 2022-06-01 19:12:22 113 | 2022-06-01 19:13:16 114 | 2022-06-01 19:14:15 115 | 2022-06-01 19:15:02 116 | 2022-06-01 19:15:41 117 | -------------------------------------------------------------------------------- /2022/week22-polls/poll.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/doehm/tidyTuesday/74fb84eee433ae1741e31857547909c6ce2c5240/2022/week22-polls/poll.png -------------------------------------------------------------------------------- /2022/week22-polls/polls.R: -------------------------------------------------------------------------------- 1 | # https://github.com/rfordatascience/tidytuesday 2 | 3 | source("scripts/startup.R") 4 | 5 | log_file <<- "2022/week22-polls/log.txt" 6 | 7 | # load data --------------------------------------------------------------- 8 | 9 | poll <- readr::read_csv('https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2022/2022-05-31/poll.csv') 10 | reputation <- readr::read_csv("2022/week22-polls/reputation.csv") 11 | 12 | # fonts and palettes ------------------------------------------------------ 13 | 14 | pal <- spec 15 | bg <- "#EBF5FF" 16 | txt_col <- dark 17 | 18 | ft_text <- "kan" 19 | ft_title <- ft_text 20 | 21 | # wrangle ----------------------------------------------------------------- 22 | 23 | df_base <- reputation |> 24 | select(-rank) |> 25 | pivot_wider(names_from = name, values_from = score) |> 26 | clean_names() 27 | 28 | df_facebook <- df_bse |> 29 | filter(company == "Facebook") 30 | 31 | df_twitter <- df_base |> 32 | filter(company == "Twitter") 33 | 34 | df_tiktok <- df_base |> 35 | filter(company == "TikTok") 36 | 37 | # titles ------------------------------------------------------------------ 38 | 39 | title <- "Ethics and Trust" 40 | subtitle <- "A company that is seen to be ethical is also seen as more trustworthy. Big tech 41 |
is trying to establish ethical practices and many companies score on par with 42 |
other industries. However, Twitter, 43 | Facebook and TikTok are clearly separate 44 |
from the rest" 45 | caption <- glue("Graphic: {get_icon('twitter', 10, fill = list(bg = bg, img = txt_col))} @danoehm / Source: Axios and Harris Poll / Code: {get_icon('github', 10, fill = list(bg = bg, img = txt_col))} doehm/tidytuesday #rstats #tidytuesday") 46 | 47 | # plot -------------------------------------------------------------------- 48 | 49 | df_base |> 50 | mutate(tech = ifelse(industry == "Tech", "Tech", "Other industries")) |> 51 | ggplot() + 52 | geom_abline(slope = 1, lty = 3) + 53 | geom_point(aes(ethics, trust, colour = tech), size = 5, alpha = 0.6) + 54 | 55 | annotate("richtext", x = 65, y = 54, label = "Facebook", family = ft_text, size = 20, colour = "#4267B2", hjust = 0, fontface = "bold", label.colour = NA, fill = bg) + 56 | annotate("curve", x = 65, y = 55, xend = df_facebook$ethics+0.3, yend = df_facebook$trust+0.3, arrow = arrow(length = unit(0.02, "npc"), type = "closed"), curvature = 0.3) + 57 | 58 | annotate("richtext", x = 50, y = 60, label = "Twitter", family = ft_text, size = 20, colour = "#1DA1F2", hjust = 1, fontface = "bold", label.colour = NA, fill = bg) + 59 | annotate("curve", x = 50, y = 60, xend = df_twitter$ethics-0.3, yend = df_twitter$trust+0.3, arrow = arrow(length = unit(0.02, "npc"), type = "closed"), curvature = -0.3) + 60 | 61 | annotate("richtext", x = 70, y = 58, label = "TikTok", family = ft_text, size = 20, hjust = 0, fontface = "bold", label.colour = NA, fill = bg, vjust = 1) + 62 | annotate("curve", x = 70, y = 58, xend = df_tiktok$ethics+0.3, yend = df_tiktok$trust+0.3, arrow = arrow(length = unit(0.02, "npc"), type = "closed"), curvature = 0.3) + 63 | 64 | # theme and scales and labs 65 | scale_y_continuous( 66 | breaks = c(55, 60, 65, 70, 75, 80), 67 | labels = c("Very poor", "Poor", "Fair", "Good", "Very good", "Excellent"), 68 | position = "right", 69 | limits = c(50, max(x$trust)) 70 | ) + 71 | scale_x_continuous( 72 | breaks = c(55, 60, 65, 70, 75, 80), 73 | labels = c("Very poor", "Poor", "Fair", "Good", "Very good", "Excellent") 74 | ) + 75 | scale_colour_manual(values = c("grey50", spec[2])) + 76 | coord_cartesian(clip = "off") + 77 | labs( 78 | title = title, 79 | subtitle = subtitle, 80 | caption = caption, 81 | colour = "", 82 | x = "Ethics score", 83 | y = "Trust\nscore" 84 | ) + 85 | theme_void() + 86 | theme( 87 | text = element_text(colour = txt_col, family = ft_text), 88 | plot.background = element_rect(fill = bg, colour = bg), 89 | plot.title = element_text(hjust = 0.5, family = ft_title, size = 128, face = "bold"), 90 | plot.subtitle = element_markdown(hjust = 0.5, family = ft_text, size = 48, lineheight = 0.35, margin = margin(b = 20), halign = 0), 91 | plot.caption = element_markdown(hjust = 0.5, family = ft_text, size = 36, lineheight = 0.35, margin = margin(t = 10)), 92 | plot.margin = margin(t = 50, r = 70, b = 50, l = 100), 93 | legend.title = element_text(family = ft_text, size = 36, lineheight = 0.25, face = "bold"), 94 | legend.text = element_text(family = ft_text, size = 36, face = "bold"), 95 | legend.margin = margin(t = 10), 96 | legend.position = "bottom", 97 | axis.text = element_text(size = 24), 98 | axis.title = element_text(size = 36, lineheight = 0.3, margin = margin(l = 10, t = 20)), 99 | ) 100 | ggsave("2022/week22-polls/poll.png", height = 10, width = 10) 101 | -------------------------------------------------------------------------------- /2022/week23-pride/log-posted.txt: -------------------------------------------------------------------------------- 1 | 2022-06-10 10:41:55 2 | -------------------------------------------------------------------------------- /2022/week23-pride/log.txt: -------------------------------------------------------------------------------- 1 | 2022-06-08 22:03:48 2 | 2022-06-08 22:04:07 3 | 2022-06-08 22:05:11 4 | 2022-06-08 22:10:25 5 | 2022-06-08 22:10:40 6 | 2022-06-09 18:13:57 7 | 2022-06-09 18:17:49 8 | 2022-06-09 18:18:02 9 | 2022-06-09 18:20:15 10 | 2022-06-09 18:20:28 11 | 2022-06-09 18:20:49 12 | 2022-06-09 18:21:20 13 | 2022-06-09 18:21:50 14 | 2022-06-09 18:22:30 15 | 2022-06-09 18:27:15 16 | 2022-06-09 18:27:50 17 | 2022-06-09 18:27:52 18 | 2022-06-09 18:28:07 19 | 2022-06-09 18:28:25 20 | 2022-06-09 18:31:35 21 | 2022-06-09 18:31:56 22 | 2022-06-09 18:32:23 23 | 2022-06-09 18:32:55 24 | 2022-06-09 18:33:39 25 | 2022-06-09 18:33:39 26 | 2022-06-09 18:36:53 27 | 2022-06-09 18:37:06 28 | 2022-06-09 18:37:20 29 | 2022-06-09 22:17:14 30 | 2022-06-09 22:18:00 31 | 2022-06-09 22:19:46 32 | 2022-06-09 22:20:15 33 | 2022-06-09 22:20:48 34 | 2022-06-09 22:21:41 35 | 2022-06-09 22:21:42 36 | 2022-06-09 22:22:11 37 | 2022-06-09 22:22:12 38 | 2022-06-09 22:26:10 39 | 2022-06-09 22:27:22 40 | 2022-06-09 22:27:47 41 | 2022-06-09 22:31:17 42 | 2022-06-09 22:31:32 43 | 2022-06-09 22:33:16 44 | 2022-06-09 22:33:44 45 | 2022-06-09 22:35:47 46 | 2022-06-09 22:38:27 47 | 2022-06-09 22:40:04 48 | 2022-06-09 22:40:49 49 | 2022-06-09 22:44:13 50 | 2022-06-09 22:44:53 51 | 2022-06-09 22:46:02 52 | 2022-06-09 22:47:04 53 | 2022-06-09 22:49:10 54 | 2022-06-09 22:49:58 55 | 2022-06-09 22:51:56 56 | 2022-06-09 22:52:39 57 | 2022-06-09 22:54:21 58 | 2022-06-09 22:54:55 59 | 2022-06-09 22:55:32 60 | 2022-06-09 22:56:57 61 | 2022-06-09 22:57:14 62 | 2022-06-09 22:58:40 63 | 2022-06-09 22:58:56 64 | 2022-06-09 23:00:11 65 | 2022-06-09 23:00:26 66 | 2022-06-09 23:09:48 67 | 2022-06-09 23:12:02 68 | 2022-06-09 23:14:15 69 | 2022-06-09 23:16:02 70 | 2022-06-09 23:16:17 71 | 2022-06-09 23:18:07 72 | 2022-06-09 23:19:00 73 | 2022-06-09 23:19:13 74 | 2022-06-09 23:21:29 75 | 2022-06-09 23:24:02 76 | 2022-06-09 23:25:02 77 | 2022-06-09 23:26:11 78 | 2022-06-09 23:27:38 79 | 2022-06-09 23:33:02 80 | 2022-06-09 23:33:44 81 | 2022-06-09 23:38:04 82 | 2022-06-09 23:41:26 83 | 2022-06-09 23:42:22 84 | 2022-06-09 23:45:25 85 | 2022-06-09 23:45:39 86 | 2022-06-09 23:51:11 87 | 2022-06-09 23:53:00 88 | 2022-06-10 06:35:10 89 | 2022-06-10 06:40:12 90 | 2022-06-10 06:43:23 91 | 2022-06-10 06:44:24 92 | 2022-06-10 06:46:53 93 | 2022-06-10 07:37:43 94 | 2022-06-10 07:37:55 95 | 2022-06-10 07:39:57 96 | 2022-06-10 07:57:15 97 | 2022-06-10 08:08:46 98 | 2022-06-10 08:10:35 99 | 2022-06-10 08:10:49 100 | 2022-06-10 08:41:17 101 | 2022-06-10 08:44:17 102 | 2022-06-10 08:44:25 103 | 2022-06-10 08:52:51 104 | 2022-06-10 08:52:57 105 | 2022-06-10 08:53:29 106 | 2022-06-10 08:53:54 107 | 2022-06-10 08:54:05 108 | 2022-06-10 08:56:21 109 | 2022-06-10 09:05:11 110 | 2022-06-10 09:10:21 111 | 2022-06-10 09:10:35 112 | 2022-06-10 09:13:49 113 | 2022-06-10 09:15:04 114 | 2022-06-10 09:19:17 115 | 2022-06-10 09:19:57 116 | 2022-06-10 09:21:28 117 | 2022-06-10 09:25:34 118 | 2022-06-10 09:30:48 119 | 2022-06-10 09:32:50 120 | 2022-06-10 09:46:21 121 | 2022-06-10 09:46:35 122 | 2022-06-10 09:46:53 123 | 2022-06-10 09:47:31 124 | 2022-06-10 09:48:14 125 | 2022-06-10 09:48:34 126 | 2022-06-10 09:50:22 127 | 2022-06-10 09:51:05 128 | 2022-06-10 09:51:28 129 | 2022-06-10 09:51:54 130 | 2022-06-10 09:52:20 131 | 2022-06-10 09:52:25 132 | 2022-06-10 09:53:16 133 | 2022-06-10 09:53:26 134 | 2022-06-10 09:53:49 135 | 2022-06-10 09:55:53 136 | 2022-06-10 09:56:00 137 | 2022-06-10 09:59:18 138 | 2022-06-10 10:02:19 139 | 2022-06-12 12:55:54 140 | 2022-06-12 12:58:57 141 | 2022-06-12 13:01:17 142 | -------------------------------------------------------------------------------- /2022/week23-pride/pride-legend.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/doehm/tidyTuesday/74fb84eee433ae1741e31857547909c6ce2c5240/2022/week23-pride/pride-legend.png -------------------------------------------------------------------------------- /2022/week23-pride/pride.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/doehm/tidyTuesday/74fb84eee433ae1741e31857547909c6ce2c5240/2022/week23-pride/pride.png -------------------------------------------------------------------------------- /2022/week25-juneteenth/juneteenth.R: -------------------------------------------------------------------------------- 1 | # https://github.com/rfordatascience/tidytuesday 2 | 3 | source("scripts/startup.R") 4 | 5 | log_file <<- "2022/week25-juneteenth/log.txt" 6 | 7 | # load data --------------------------------------------------------------- 8 | 9 | slave_routes <- readr::read_csv('https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2020/2020-06-16/slave_routes.csv') 10 | 11 | # fonts and palettes ------------------------------------------------------ 12 | 13 | pal <- spec 14 | bg <- rgb(234, 225, 214, maxColorValue = 255) 15 | txt_col <- "grey20" 16 | 17 | ft_text <- "oswald" 18 | ft_title <- ft_text 19 | 20 | # wrangle ----------------------------------------------------------------- 21 | 22 | total_slaves <- scales::comma(sum(slave_routes$n_slaves_arrived, na.rm = TRUE)) 23 | a <- 1.4 24 | 25 | # titles ------------------------------------------------------------------ 26 | 27 | text1 <- glue("slaves, on record were transported
bewteen 1514 and 1866 but given
the incomplete records it is
{cg('estimated', lighten(txt_col, 0.5))} to be closer to 7.6M") 28 | caption <- glue("Graphic: {get_icon('twitter', 20, fill = list(bg = bg, img = txt_col))} @danoehm / Source: WEB DuBois style by Anthony Starks / Code: {get_icon('github', 20, fill = list(bg = bg, img = txt_col))} doehm/tidytuesday #rstats #tidytuesday") 29 | 30 | # plot -------------------------------------------------------------------- 31 | slave_routes |> 32 | time_log() |> 33 | group_by(year_arrival) |> 34 | summarise( 35 | n = sum(n_slaves_arrived, na.rm = TRUE), 36 | n_est = n*1.5 37 | ) |> 38 | ggplot(aes(year_arrival, n)) + 39 | geom_area(aes(y = n_est), fill = lighten(txt_col, 0.5)) + 40 | geom_area(fill = txt_col) + 41 | 42 | annotate("text", x = 1514, y = 70000*a, label = total_slaves, size = 64, family = ft_text, 43 | fontface = "bold", colour = txt_col, hjust = 0) + 44 | annotate("richtext", x = 1514, y = 64000*a, label = text1, size = 24, family = ft_text, 45 | colour = txt_col, hjust = 0, lineheight = 0.35, vjust = 1, 46 | fill = NA, label.colour = NA) + 47 | 48 | annotate("segment", x = 1554, xend = 1602, y = 60500*a, yend = 60500*a, colour = txt_col, size = 2) + 49 | annotate("segment", x = 1516, xend = 1568, y = 49600*a, yend = 49600*a, colour = lighten(txt_col, 0.5), size = 2) + 50 | 51 | scale_x_continuous( 52 | breaks = c(1514, 1866, 2022), 53 | labels = c(1514, 1866, 2022), 54 | limits = c(1514, 2022) 55 | ) + 56 | ylim(c(0, NA)) + 57 | labs(caption = caption) + 58 | coord_cartesian(clip = "off") + 59 | theme_void() + 60 | theme( 61 | text = element_text(family = ft_text, colour = txt_col), 62 | plot.background = element_rect(fill = bg), 63 | plot.margin = margin(t = 80, b = 0, l = 80, r = 80), 64 | plot.caption = element_markdown(size = 48, hjust = 0.5, margin = margin(b = 20, t = 100)), 65 | axis.text.x = element_text(size = 80, face = "bold") 66 | ) 67 | 68 | ggsave("2022/week25-juneteenth/juneteenth.png", height = 12, width = 14) 69 | -------------------------------------------------------------------------------- /2022/week25-juneteenth/juneteenth.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/doehm/tidyTuesday/74fb84eee433ae1741e31857547909c6ce2c5240/2022/week25-juneteenth/juneteenth.png -------------------------------------------------------------------------------- /2022/week25-juneteenth/log-posted.txt: -------------------------------------------------------------------------------- 1 | 2022-06-22 19:28:27 2 | -------------------------------------------------------------------------------- /2022/week25-juneteenth/log.txt: -------------------------------------------------------------------------------- 1 | 2022-06-21 21:15:44 2 | 2022-06-21 21:16:05 3 | 2022-06-21 21:21:47 4 | 2022-06-21 21:22:51 5 | 2022-06-21 21:23:34 6 | 2022-06-21 21:26:04 7 | 2022-06-21 21:33:42 8 | 2022-06-21 21:34:13 9 | 2022-06-21 21:34:40 10 | 2022-06-21 21:35:46 11 | 2022-06-21 21:35:54 12 | 2022-06-21 21:36:32 13 | 2022-06-21 21:37:46 14 | 2022-06-21 21:38:49 15 | 2022-06-21 21:41:00 16 | 2022-06-21 21:41:17 17 | 2022-06-21 21:41:30 18 | 2022-06-21 21:46:22 19 | 2022-06-21 21:46:45 20 | 2022-06-21 21:46:54 21 | 2022-06-21 21:46:58 22 | 2022-06-21 21:52:22 23 | 2022-06-21 21:54:11 24 | 2022-06-21 21:55:42 25 | 2022-06-21 21:58:22 26 | 2022-06-21 21:58:36 27 | 2022-06-21 21:59:17 28 | 2022-06-21 22:00:48 29 | 2022-06-21 22:02:34 30 | 2022-06-21 22:03:33 31 | 2022-06-21 22:08:00 32 | 2022-06-21 22:08:43 33 | 2022-06-21 22:09:08 34 | 2022-06-21 22:09:27 35 | 2022-06-21 22:10:51 36 | 2022-06-21 22:11:20 37 | 2022-06-21 22:11:53 38 | 2022-06-21 22:12:55 39 | 2022-06-21 22:13:15 40 | 2022-06-21 22:13:42 41 | 2022-06-21 22:14:37 42 | 2022-06-21 22:14:55 43 | 2022-06-21 22:15:19 44 | 2022-06-21 22:15:41 45 | 2022-06-21 22:16:14 46 | 2022-06-21 22:16:29 47 | 2022-06-21 22:19:28 48 | 2022-06-21 22:24:39 49 | 2022-06-21 22:25:39 50 | 2022-06-21 22:27:47 51 | 2022-06-21 22:28:21 52 | 2022-06-21 22:28:46 53 | 2022-06-21 22:31:14 54 | 2022-06-21 22:31:41 55 | 2022-06-21 22:36:20 56 | 2022-06-21 22:38:55 57 | 2022-06-21 22:39:31 58 | 2022-06-21 22:46:34 59 | 2022-06-21 22:47:55 60 | 2022-06-21 22:48:33 61 | 2022-06-21 22:49:54 62 | 2022-06-21 22:51:35 63 | 2022-06-21 22:52:41 64 | 2022-06-21 22:53:05 65 | 2022-06-22 06:55:14 66 | 2022-06-22 06:55:37 67 | 2022-06-22 06:56:16 68 | 2022-06-22 07:00:12 69 | 2022-06-22 07:23:05 70 | 2022-06-22 07:24:08 71 | 2022-06-22 07:26:02 72 | 2022-06-22 17:56:42 73 | 2022-06-22 17:57:04 74 | 2022-06-22 17:57:37 75 | 2022-06-22 17:58:17 76 | 2022-06-22 17:58:56 77 | 2022-06-22 18:00:03 78 | 2022-06-22 18:00:24 79 | 2022-06-22 18:00:51 80 | 2022-06-22 18:01:29 81 | 2022-06-22 18:02:07 82 | 2022-06-22 18:02:44 83 | 2022-06-22 18:03:03 84 | 2022-06-22 18:03:58 85 | 2022-06-22 18:04:32 86 | 2022-06-22 18:05:59 87 | 2022-06-22 18:21:58 88 | 2022-06-22 18:25:08 89 | 2022-06-22 18:27:32 90 | 2022-06-22 18:29:08 91 | 2022-06-22 18:29:33 92 | 2022-06-22 18:30:17 93 | 2022-06-22 18:31:08 94 | 2022-06-22 18:41:14 95 | 2022-06-22 18:42:13 96 | 2022-06-22 18:43:13 97 | 2022-06-22 18:43:53 98 | 2022-06-22 18:47:10 99 | 2022-06-22 18:48:00 100 | 2022-06-22 18:58:23 101 | 2022-06-22 19:00:16 102 | 2022-06-22 19:00:42 103 | 2022-06-22 19:01:39 104 | 2022-06-22 19:02:34 105 | 2022-06-22 19:03:20 106 | 2022-06-22 19:07:50 107 | 2022-06-22 19:08:29 108 | 2022-06-22 19:10:09 109 | 2022-06-22 19:10:40 110 | 2022-06-22 19:11:44 111 | 2022-06-22 19:14:43 112 | 2022-06-22 19:15:24 113 | 2022-06-22 19:16:01 114 | -------------------------------------------------------------------------------- /2022/week27-san-fran-rents/CA_Counties/CA_Counties_TIGER2016.cpg: -------------------------------------------------------------------------------- 1 | UTF-8 -------------------------------------------------------------------------------- /2022/week27-san-fran-rents/CA_Counties/CA_Counties_TIGER2016.prj: -------------------------------------------------------------------------------- 1 | PROJCS["WGS_1984_Web_Mercator_Auxiliary_Sphere",GEOGCS["GCS_WGS_1984",DATUM["D_WGS_1984",SPHEROID["WGS_1984",6378137.0,298.257223563]],PRIMEM["Greenwich",0.0],UNIT["Degree",0.0174532925199433]],PROJECTION["Mercator_Auxiliary_Sphere"],PARAMETER["False_Easting",0.0],PARAMETER["False_Northing",0.0],PARAMETER["Central_Meridian",0.0],PARAMETER["Standard_Parallel_1",0.0],PARAMETER["Auxiliary_Sphere_Type",0.0],UNIT["Meter",1.0]] -------------------------------------------------------------------------------- /2022/week27-san-fran-rents/CA_Counties/CA_Counties_TIGER2016.sbn: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/doehm/tidyTuesday/74fb84eee433ae1741e31857547909c6ce2c5240/2022/week27-san-fran-rents/CA_Counties/CA_Counties_TIGER2016.sbn -------------------------------------------------------------------------------- /2022/week27-san-fran-rents/CA_Counties/CA_Counties_TIGER2016.sbx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/doehm/tidyTuesday/74fb84eee433ae1741e31857547909c6ce2c5240/2022/week27-san-fran-rents/CA_Counties/CA_Counties_TIGER2016.sbx -------------------------------------------------------------------------------- /2022/week27-san-fran-rents/CA_Counties/CA_Counties_TIGER2016.shp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/doehm/tidyTuesday/74fb84eee433ae1741e31857547909c6ce2c5240/2022/week27-san-fran-rents/CA_Counties/CA_Counties_TIGER2016.shp -------------------------------------------------------------------------------- /2022/week27-san-fran-rents/CA_Counties/CA_Counties_TIGER2016.shx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/doehm/tidyTuesday/74fb84eee433ae1741e31857547909c6ce2c5240/2022/week27-san-fran-rents/CA_Counties/CA_Counties_TIGER2016.shx -------------------------------------------------------------------------------- /2022/week27-san-fran-rents/geo_export_3b286e07-2c69-479a-8452-b9acb0b14cfa.dbf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/doehm/tidyTuesday/74fb84eee433ae1741e31857547909c6ce2c5240/2022/week27-san-fran-rents/geo_export_3b286e07-2c69-479a-8452-b9acb0b14cfa.dbf -------------------------------------------------------------------------------- /2022/week27-san-fran-rents/geo_export_3b286e07-2c69-479a-8452-b9acb0b14cfa.prj: -------------------------------------------------------------------------------- 1 | GEOGCS["WGS84(DD)", DATUM["WGS84", SPHEROID["WGS84", 6378137.0, 298.257223563]], PRIMEM["Greenwich", 0.0], UNIT["degree", 0.017453292519943295], AXIS["Geodetic longitude", EAST], AXIS["Geodetic latitude", NORTH]] -------------------------------------------------------------------------------- /2022/week27-san-fran-rents/geo_export_3b286e07-2c69-479a-8452-b9acb0b14cfa.shp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/doehm/tidyTuesday/74fb84eee433ae1741e31857547909c6ce2c5240/2022/week27-san-fran-rents/geo_export_3b286e07-2c69-479a-8452-b9acb0b14cfa.shp -------------------------------------------------------------------------------- /2022/week27-san-fran-rents/geo_export_3b286e07-2c69-479a-8452-b9acb0b14cfa.shx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/doehm/tidyTuesday/74fb84eee433ae1741e31857547909c6ce2c5240/2022/week27-san-fran-rents/geo_export_3b286e07-2c69-479a-8452-b9acb0b14cfa.shx -------------------------------------------------------------------------------- /2022/week27-san-fran-rents/log-posted.txt: -------------------------------------------------------------------------------- 1 | 2022-07-08 07:52:02 2 | -------------------------------------------------------------------------------- /2022/week27-san-fran-rents/log.txt: -------------------------------------------------------------------------------- 1 | 2022-07-06 14:41:27 2 | 2022-07-06 14:41:33 3 | 2022-07-06 14:44:28 4 | 2022-07-06 14:45:05 5 | 2022-07-06 14:45:27 6 | 2022-07-06 14:45:38 7 | 2022-07-06 14:46:02 8 | 2022-07-06 15:02:40 9 | 2022-07-06 15:09:31 10 | -------------------------------------------------------------------------------- /2022/week27-san-fran-rents/sanfran.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/doehm/tidyTuesday/74fb84eee433ae1741e31857547909c6ce2c5240/2022/week27-san-fran-rents/sanfran.png -------------------------------------------------------------------------------- /2022/week28-flights/flights.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/doehm/tidyTuesday/74fb84eee433ae1741e31857547909c6ce2c5240/2022/week28-flights/flights.png -------------------------------------------------------------------------------- /2022/week28-flights/log-posted.txt: -------------------------------------------------------------------------------- 1 | 2022-07-13 18:40:03 2 | -------------------------------------------------------------------------------- /2022/week28-flights/log.txt: -------------------------------------------------------------------------------- 1 | 2022-07-12 21:12:32 2 | 2022-07-12 21:12:38 3 | 2022-07-12 21:13:26 4 | 2022-07-12 21:13:54 5 | 2022-07-12 21:13:59 6 | 2022-07-12 21:14:02 7 | 2022-07-12 21:14:41 8 | 2022-07-12 21:14:47 9 | 2022-07-12 21:14:50 10 | 2022-07-12 21:15:05 11 | 2022-07-12 21:15:25 12 | 2022-07-12 21:15:26 13 | 2022-07-12 21:15:45 14 | 2022-07-12 21:16:41 15 | 2022-07-12 21:18:36 16 | 2022-07-12 21:18:45 17 | 2022-07-12 21:19:02 18 | 2022-07-12 21:19:07 19 | 2022-07-12 21:19:16 20 | 2022-07-12 21:19:45 21 | 2022-07-12 21:21:19 22 | 2022-07-12 21:21:23 23 | 2022-07-12 21:25:02 24 | 2022-07-12 21:33:50 25 | 2022-07-12 21:34:01 26 | 2022-07-12 21:34:19 27 | 2022-07-12 21:35:48 28 | 2022-07-12 21:37:07 29 | 2022-07-12 21:45:07 30 | 2022-07-12 21:45:46 31 | 2022-07-12 21:54:54 32 | 2022-07-12 22:00:17 33 | 2022-07-12 22:01:30 34 | 2022-07-13 06:40:25 35 | 2022-07-13 06:42:46 36 | 2022-07-13 06:47:28 37 | 2022-07-13 06:50:34 38 | 2022-07-13 06:51:31 39 | 2022-07-13 06:52:31 40 | 2022-07-13 07:05:26 41 | 2022-07-13 07:05:50 42 | 2022-07-13 07:06:59 43 | 2022-07-13 07:07:58 44 | 2022-07-13 07:08:45 45 | 2022-07-13 07:11:24 46 | 2022-07-13 07:12:01 47 | 2022-07-13 07:12:32 48 | 2022-07-13 07:13:24 49 | 2022-07-13 07:18:11 50 | 2022-07-13 07:28:54 51 | 2022-07-13 07:30:34 52 | 2022-07-13 07:31:10 53 | 2022-07-13 07:31:24 54 | 2022-07-13 07:32:01 55 | 2022-07-13 07:46:47 56 | 2022-07-13 07:46:53 57 | 2022-07-13 07:47:48 58 | 2022-07-13 07:48:10 59 | 2022-07-13 07:59:06 60 | 2022-07-13 07:59:30 61 | 2022-07-13 08:01:31 62 | 2022-07-13 08:01:46 63 | 2022-07-13 08:02:31 64 | 2022-07-13 08:04:02 65 | 2022-07-13 08:04:48 66 | 2022-07-13 08:06:20 67 | 2022-07-13 08:11:00 68 | 2022-07-13 08:11:24 69 | 2022-07-13 08:12:03 70 | 2022-07-13 08:13:19 71 | 2022-07-13 08:13:27 72 | 2022-07-13 08:13:55 73 | 2022-07-13 08:14:46 74 | 2022-07-13 08:15:59 75 | 2022-07-13 08:16:40 76 | 2022-07-13 08:39:09 77 | 2022-07-13 08:39:57 78 | 2022-07-13 08:40:51 79 | 2022-07-13 08:54:08 80 | 2022-07-13 08:55:16 81 | 2022-07-13 08:57:17 82 | 2022-07-13 08:58:35 83 | 2022-07-13 09:06:37 84 | 2022-07-13 09:08:31 85 | 2022-07-13 09:29:50 86 | 2022-07-13 09:30:34 87 | 2022-07-13 09:31:00 88 | 2022-07-13 10:05:49 89 | 2022-07-13 10:32:29 90 | 2022-07-13 10:35:11 91 | 2022-07-13 10:36:02 92 | 2022-07-13 10:41:19 93 | 2022-07-13 10:42:36 94 | 2022-07-13 10:47:28 95 | 2022-07-13 10:49:07 96 | 2022-07-13 10:59:52 97 | 2022-07-13 18:40:31 98 | 2022-07-13 18:41:00 99 | -------------------------------------------------------------------------------- /2022/week29-tech/log-posted.txt: -------------------------------------------------------------------------------- 1 | 2022-07-22 19:32:56 2 | -------------------------------------------------------------------------------- /2022/week29-tech/log.txt: -------------------------------------------------------------------------------- 1 | 2022-07-21 06:46:51 2 | 2022-07-21 06:46:57 3 | 2022-07-21 06:47:46 4 | 2022-07-21 06:51:30 5 | 2022-07-21 06:51:46 6 | 2022-07-21 06:51:51 7 | 2022-07-21 06:53:02 8 | 2022-07-21 06:54:20 9 | 2022-07-21 06:54:22 10 | 2022-07-21 06:56:10 11 | 2022-07-21 06:56:13 12 | 2022-07-21 21:34:13 13 | 2022-07-21 21:34:21 14 | 2022-07-21 21:36:32 15 | 2022-07-21 21:36:49 16 | 2022-07-21 21:38:24 17 | 2022-07-21 21:39:32 18 | 2022-07-21 21:42:30 19 | 2022-07-21 21:42:38 20 | 2022-07-21 21:42:52 21 | 2022-07-22 07:29:03 22 | 2022-07-22 07:48:07 23 | 2022-07-22 07:49:08 24 | 2022-07-22 07:50:04 25 | 2022-07-22 07:52:39 26 | 2022-07-22 07:53:16 27 | 2022-07-22 07:53:59 28 | 2022-07-22 07:54:40 29 | 2022-07-22 07:55:44 30 | 2022-07-22 07:59:19 31 | 2022-07-22 07:59:55 32 | 2022-07-22 08:01:09 33 | 2022-07-22 08:04:17 34 | 2022-07-22 08:18:51 35 | 2022-07-22 08:20:19 36 | 2022-07-22 08:21:20 37 | 2022-07-22 08:21:44 38 | 2022-07-22 08:22:54 39 | 2022-07-22 08:23:55 40 | 2022-07-22 12:14:56 41 | 2022-07-22 12:15:29 42 | 2022-07-22 12:15:54 43 | 2022-07-22 12:19:49 44 | 2022-07-22 12:21:08 45 | 2022-07-22 12:21:25 46 | 2022-07-22 12:21:40 47 | 2022-07-22 12:21:52 48 | 2022-07-22 12:21:57 49 | 2022-07-22 12:21:59 50 | 2022-07-22 12:22:22 51 | 2022-07-22 12:23:16 52 | 2022-07-22 12:23:18 53 | 2022-07-22 12:26:06 54 | 2022-07-22 12:30:21 55 | 2022-07-22 12:30:47 56 | 2022-07-22 12:30:51 57 | 2022-07-22 12:31:17 58 | 2022-07-22 12:31:35 59 | 2022-07-22 12:32:39 60 | 2022-07-22 12:32:51 61 | 2022-07-22 12:33:52 62 | 2022-07-22 12:34:19 63 | 2022-07-22 12:36:19 64 | 2022-07-22 12:36:31 65 | 2022-07-22 12:36:41 66 | 2022-07-22 12:36:53 67 | 2022-07-22 12:45:36 68 | 2022-07-22 12:45:42 69 | 2022-07-22 12:46:43 70 | 2022-07-22 12:48:14 71 | 2022-07-22 12:48:41 72 | 2022-07-22 12:50:21 73 | 2022-07-22 12:51:18 74 | 2022-07-22 12:52:07 75 | 2022-07-22 12:52:57 76 | 2022-07-22 12:57:51 77 | 2022-07-22 12:58:22 78 | 2022-07-22 13:00:29 79 | 2022-07-22 17:31:56 80 | 2022-07-22 17:33:05 81 | 2022-07-22 17:33:32 82 | 2022-07-22 17:36:38 83 | 2022-07-22 17:37:43 84 | 2022-07-22 17:46:33 85 | 2022-07-22 17:58:43 86 | 2022-07-22 17:58:50 87 | 2022-07-22 18:00:36 88 | 2022-07-22 18:01:46 89 | 2022-07-22 18:02:28 90 | 2022-07-22 18:02:34 91 | 2022-07-22 18:02:59 92 | 2022-07-22 18:03:33 93 | 2022-07-22 18:03:50 94 | 2022-07-22 18:04:26 95 | 2022-07-22 18:04:27 96 | 2022-07-22 18:05:02 97 | 2022-07-22 18:05:30 98 | 2022-07-22 18:05:39 99 | 2022-07-22 18:06:00 100 | 2022-07-22 18:06:02 101 | 2022-07-22 18:06:45 102 | 2022-07-22 18:21:36 103 | 2022-07-22 18:22:20 104 | 2022-07-22 18:24:50 105 | 2022-07-22 18:26:19 106 | 2022-07-22 18:56:16 107 | 2022-07-22 19:26:48 108 | 2022-07-22 19:27:02 109 | 2022-07-22 19:50:17 110 | -------------------------------------------------------------------------------- /2022/week29-tech/tech.R: -------------------------------------------------------------------------------- 1 | # https://github.com/rfordatascience/tidytuesday 2 | 3 | # source("scripts/startup.R") 4 | 5 | library(ggchicklet) 6 | library(tidyverse) 7 | library(janitor) 8 | library(showtext) 9 | library(ggtext) 10 | library(glue) 11 | 12 | # functions --------------------------------------------------------------- 13 | 14 | choose_font_colour <- function(bg, dark = "#000000", light = "white") { 15 | x <- drop(c(0.299, 0.587, 0.114) %*% col2rgb(bg) > 186) 16 | if(x) { 17 | dark 18 | } else { 19 | light 20 | } 21 | } 22 | 23 | cg <- function(text, colour = NULL) { 24 | if(is.null(colour)) { 25 | colour <- pal[names(pal) == text] 26 | } 27 | glue("{text}") 28 | } 29 | 30 | # load data --------------------------------------------------------------- 31 | 32 | technology <- readr::read_csv('https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2022/2022-07-19/technology.csv') 33 | 34 | # fonts and palettes ------------------------------------------------------ 35 | 36 | pal <- c("grey10", "grey30", "#c9ecb4", "#93d3ab", "#35b0ab") 37 | names(pal) <- c("Coal", "Gas", "Hydro", "Solar", "Wind") 38 | bg <- "white" 39 | txt_col <- "grey20" 40 | 41 | font_add_google("Kanit", "kan") 42 | ft_text <- "kan" 43 | ft_title <- ft_text 44 | showtext_auto() 45 | 46 | # wrangle ----------------------------------------------------------------- 47 | 48 | df_base <- 49 | technology |> 50 | filter( 51 | str_detect(variable, "elec_[:alpha:]"), 52 | str_detect(variable, "coal|gas|hydro|wind|solar"), 53 | year %in% c(2000, 2020), 54 | iso3c == "AUS", 55 | # removing solar and wind for 2000 because you can't see it on 56 | # the chart and the chicklet leaves an annoying artifact 57 | !(str_detect(variable, "wind|solar") & year == 2000) 58 | ) |> 59 | group_by(year, variable) |> 60 | summarise(value = sum(value)) |> 61 | mutate( 62 | energy = str_to_title(str_extract(variable, "(?<=elec_)[:alpha:]+")), 63 | energy = factor(energy) 64 | ) 65 | 66 | df_point <- 67 | df_base |> 68 | arrange(year, energy) |> 69 | group_by(year) |> 70 | mutate( 71 | y = cumsum(value) - value/2, 72 | pct = scales::percent(round(value/sum(value), 3)), 73 | txt_col = map_chr(energy, ~choose_font_colour(pal[.x], dark = txt_col)) 74 | ) 75 | 76 | # titles ------------------------------------------------------------------ 77 | 78 | title <- "Australia's Electricity Production" 79 | subtitle <- glue( 80 | "Electricity production has increased by ~47TWH between 2000
81 | and 2020. In 2000 {cg('wind', pal[5])} and {cg('solar', pal[4])} contribution was negligible,
82 | in 2020 it accounts for 18%. Coal electricity production has declined
83 | by ~28TWH but (unfortunately) is still over half of Australia's
84 | electricity production in 2020." 85 | ) 86 | caption <- glue("Graphic: {get_icon('twitter', 10, fill = list(bg = bg, img = txt_col))} @danoehm / Source: data.nber.org / Code: {get_icon('github', 10, fill = list(bg = bg, img = txt_col))} doehm/tidytuesday") 87 | 88 | # plot -------------------------------------------------------------------- 89 | 90 | df_base |> 91 | ggplot(aes(year, value, fill = energy)) + 92 | 93 | # geoms 94 | geom_chicklet(colour = bg, width = 14, radius = grid::unit(9, "pt")) + 95 | geom_text(aes(year, y, label = pct), df_point, family = ft_text, size = 24, colour = df_point$txt_col, fontface = "bold") + 96 | 97 | # theme and scales and labs 98 | scale_fill_manual( 99 | breaks = c("Coal", "Gas", "Hydro", "Solar", "Wind"), 100 | values = pal 101 | ) + 102 | scale_x_continuous( 103 | breaks = c(2000, 2020), 104 | labels = c(2000, 2020) 105 | ) + 106 | labs( 107 | title = title, 108 | subtitle = subtitle, 109 | caption = caption, 110 | fill = "Electricity\nproduction\nfrom...", 111 | y = "Electricity production (TWH)" 112 | ) + 113 | theme_void() + 114 | theme( 115 | text = element_text(colour = txt_col, family = ft_text, size = 48), 116 | plot.background = element_rect(fill = bg, colour = bg), 117 | plot.title = element_text(hjust = 0.5, family = ft_title, size = 86, face = "bold", margin = margin(b = 20)), 118 | plot.subtitle = element_markdown(hjust = 0, family = ft_text, size = 48, lineheight = 0.35, margin = margin(b = 20)), 119 | plot.caption = element_markdown(hjust = 0.5, family = ft_text, lineheight = 0.35, margin = margin(t = 20)), 120 | plot.margin = margin(t = 20, r = 20, b = 20, l = 20), 121 | legend.title = element_text(family = ft_text, lineheight = 0.25), 122 | legend.text = element_text(family = ft_text), 123 | axis.text = element_text(), 124 | axis.title.y = element_text(angle = 90, margin = margin(r = 10)) 125 | ) 126 | 127 | # save -------------------------------------------------------------------- 128 | 129 | ggsave("2022/week29-tech/tech.png", height = 12, width = 8) 130 | -------------------------------------------------------------------------------- /2022/week29-tech/tech.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/doehm/tidyTuesday/74fb84eee433ae1741e31857547909c6ce2c5240/2022/week29-tech/tech.png -------------------------------------------------------------------------------- /2022/week31-frog/frog.R: -------------------------------------------------------------------------------- 1 | # https://github.com/rfordatascience/tidytuesday 2 | 3 | source("scripts/startup.R") 4 | 5 | library(tidyverse) 6 | library(ggtext) 7 | library(geomtextpath) 8 | library(patchwork) 9 | 10 | # load data --------------------------------------------------------------- 11 | 12 | frog <- readr::read_csv('https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2022/2022-08-02/frog.csv') |> 13 | clean_names() 14 | 15 | # fonts and palettes ------------------------------------------------------ 16 | 17 | forest_pal <- c("#445544", "#779977", "#99AA77", "#CCCC88", "#BBBB88") 18 | water_pal <- c("#244157", "#227F9A", "#43A4BF", "#88B2C7") 19 | sunset <- c("#ffcdb2", "#ffb4a2", "#e5989b", "#b5838d", "#6d6875") 20 | bg <- "white" 21 | txt_col <- "grey20" 22 | 23 | font_add_google("Barlow Condensed", "barlow") 24 | font_add_google("Karla", "karla") 25 | showtext_auto() 26 | 27 | ft_text <- "karla" 28 | ft_title <- "barlow" 29 | 30 | # titles ------------------------------------------------------------------ 31 | 32 | title <- "Oregon Spotted Frog" 33 | subtitle <- str_rich_wrap("Where will you find them?", 100) 34 | caption <- glue("Graphic: {get_icon('twitter', 10, fill = list(bg = bg, img = txt_col))} @danoehm / Source: USGS.gov @FGazzelloni / Code: {get_icon('github', 10, fill = list(bg = bg, img = txt_col))} doehm/tidytuesday #rstats #tidytuesday") 35 | 36 | df_annotate <- tribble( 37 | ~x, ~y, ~label, 38 | 1, 0.85, "Water depth", 39 | 1, 0.5, "Water type", 40 | 1, 0.15, "Structure" 41 | ) 42 | 43 | # plot -------------------------------------------------------------------- 44 | 45 | g_type <- frog |> 46 | time_log() |> 47 | count(type) |> 48 | arrange(desc(type)) |> 49 | mutate( 50 | x = 1, 51 | x0 = c(3, 2, 3, 2) + 0.5, 52 | x1 = c(3, NA, 3, NA), 53 | y = cumsum(n) - n/2, 54 | label = paste0(n, "\n", type), 55 | pct = paste0(round(n/sum(n)*100,0), "%") 56 | ) |> 57 | ggplot() + 58 | geom_col(aes(x, n, fill = type)) + 59 | geom_textpath(aes(x0, y, label = type), family = ft_text, colour = txt_col, text_only = TRUE, angle = 90, size = 10, lineheight = 0.25) + 60 | geom_text(aes(0, y, label = pct), family = ft_text, colour = txt_col, text_only = TRUE, size = 8, lineheight = 0.25) + 61 | geom_segment(aes(x = x, xend = x1-0.5, y = y, yend = y)) + 62 | geom_point(aes(x, y), size = 2) + 63 | scale_fill_manual(values = water_pal) + 64 | xlim(c(-2, 3.5)) + 65 | coord_polar("y") + 66 | theme_void() + 67 | theme(legend.position = "none") 68 | 69 | g_water <- frog |> 70 | time_log() |> 71 | count(water) |> 72 | arrange(desc(water)) |> 73 | mutate( 74 | x = 1, 75 | x0 = c(3, 2, 3, 2) + 0.5, 76 | x1 = c(3, NA, 3, NA), 77 | y = cumsum(n) - n/2, 78 | label = paste0(n, "\n", water), 79 | pct = paste0(round(n/sum(n)*100,0), "%") 80 | ) |> 81 | ggplot() + 82 | geom_col(aes(x, n, fill = water)) + 83 | geom_textpath(aes(x0, y, label = water), family = ft_text, colour = txt_col, text_only = TRUE, angle = 90, size = 10, lineheight = 0.25) + 84 | geom_text(aes(0, y, label = pct), family = ft_text, colour = txt_col, text_only = TRUE, size = 8, lineheight = 0.25) + 85 | geom_segment(aes(x = x, xend = x1-0.5, y = y, yend = y)) + 86 | geom_point(aes(x, y), size = 2) + 87 | scale_fill_manual(values = rev(sunset)[1:4]) + 88 | xlim(c(-2, 3.5)) + 89 | coord_polar("y") + 90 | theme_void() + 91 | theme( 92 | legend.position = "none" 93 | ) 94 | 95 | g_structure <- frog |> 96 | time_log() |> 97 | count(structure) |> 98 | arrange(desc(structure)) |> 99 | mutate( 100 | x = 1, 101 | x0 = c(2, 3, 2, 3, 3) + 0.5, 102 | x1 = c(NA, 3, NA, 3, 3), 103 | y = cumsum(n) - n/2, 104 | label = paste0(n, "\n", structure), 105 | pct = paste0(round(n/sum(n)*100,0), "%") 106 | ) |> 107 | ggplot() + 108 | geom_col(aes(x, n, fill = structure)) + 109 | geom_textpath(aes(x0, y, label = structure), family = ft_text, colour = txt_col, text_only = TRUE, angle = 90, size = 10, lineheight = 0.25) + 110 | geom_text(aes(0, y, label = pct), family = ft_text, colour = txt_col, text_only = TRUE, size = 8, lineheight = 0.25) + 111 | geom_segment(aes(x = x, xend = x1-0.5, y = y, yend = y)) + 112 | geom_point(aes(x, y), size = 2) + 113 | scale_fill_manual(values = forest[1:5]) + 114 | xlim(c(-2, 3.5)) + 115 | coord_polar("y") + 116 | theme_void() + 117 | theme( 118 | legend.position = "none" 119 | ) 120 | 121 | g_base <- ggplot() + 122 | geom_text(aes(x, y, label = label), df_annotate, family = "karla", size = 26, colour = txt_col, hjust = 1, lineheight = 0.35) + 123 | labs( 124 | title = title, 125 | subtitle = subtitle, 126 | caption = caption 127 | ) + 128 | xlim(0, 1) + 129 | ylim(0, 1) + 130 | theme_void() + 131 | theme( 132 | text = element_text(family = ft_text, size = 36, colour = txt_col), 133 | plot.title = element_text(size = 120, hjust = 0.5, face = "bold", family = ft_title), 134 | plot.subtitle = element_text(size = 48, hjust = 0.5), 135 | plot.caption = element_markdown(hjust = 0.5), 136 | plot.margin = margin(t = 20, b = 10, r = 20) 137 | ) 138 | 139 | g_base + 140 | inset_element(g_type, left = -0.05, right = 0.8, top = 0.68, bottom = 0.31) + 141 | inset_element(g_water, left = -0.05, right = 0.8, top = 1, bottom = 0.62) + 142 | inset_element(g_structure, left = -0.05, right = 0.8, top = 0.37, bottom = 0) 143 | 144 | ggsave("2022/week31-frog/frog.png", height = 12, width = 7.5) 145 | 146 | -------------------------------------------------------------------------------- /2022/week31-frog/frog.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/doehm/tidyTuesday/74fb84eee433ae1741e31857547909c6ce2c5240/2022/week31-frog/frog.png -------------------------------------------------------------------------------- /2022/week31-frog/log-posted.txt: -------------------------------------------------------------------------------- 1 | 2022-08-03 06:33:18 2 | -------------------------------------------------------------------------------- /2022/week31-frog/log.txt: -------------------------------------------------------------------------------- 1 | 2022-08-02 20:17:52 2 | 2022-08-02 20:18:25 3 | 2022-08-02 20:18:38 4 | 2022-08-02 20:18:47 5 | 2022-08-02 20:25:15 6 | 2022-08-02 20:25:58 7 | 2022-08-02 20:32:23 8 | 2022-08-02 20:34:55 9 | 2022-08-02 20:35:58 10 | 2022-08-02 20:36:04 11 | 2022-08-02 20:36:34 12 | 2022-08-02 20:37:04 13 | 2022-08-02 20:37:20 14 | 2022-08-02 20:42:40 15 | 2022-08-02 20:44:27 16 | 2022-08-02 20:44:46 17 | 2022-08-02 20:45:03 18 | 2022-08-02 20:45:44 19 | 2022-08-02 20:49:01 20 | 2022-08-02 20:50:02 21 | 2022-08-02 20:53:05 22 | 2022-08-02 20:53:08 23 | 2022-08-02 20:53:21 24 | 2022-08-02 20:54:05 25 | 2022-08-02 20:54:19 26 | 2022-08-02 20:54:24 27 | 2022-08-02 20:54:38 28 | 2022-08-02 20:55:45 29 | 2022-08-02 20:56:22 30 | 2022-08-02 20:56:51 31 | 2022-08-02 20:57:15 32 | 2022-08-02 20:57:54 33 | 2022-08-02 20:57:55 34 | 2022-08-02 20:57:55 35 | 2022-08-02 21:51:58 36 | 2022-08-02 21:52:19 37 | 2022-08-02 21:56:34 38 | 2022-08-02 21:57:09 39 | 2022-08-02 21:58:07 40 | 2022-08-02 22:03:09 41 | 2022-08-02 22:03:09 42 | 2022-08-02 22:03:10 43 | 2022-08-02 22:06:25 44 | 2022-08-02 22:06:26 45 | 2022-08-02 22:06:26 46 | 2022-08-02 22:07:09 47 | 2022-08-02 22:07:09 48 | 2022-08-02 22:07:09 49 | 2022-08-02 22:11:54 50 | 2022-08-02 22:11:55 51 | 2022-08-02 22:11:55 52 | 2022-08-02 22:15:48 53 | 2022-08-02 22:16:32 54 | 2022-08-02 22:17:02 55 | 2022-08-02 22:18:13 56 | 2022-08-02 22:18:13 57 | 2022-08-02 22:18:13 58 | 2022-08-02 22:18:37 59 | -------------------------------------------------------------------------------- /2022/week32-ferriswheel/ferriswheel.R: -------------------------------------------------------------------------------- 1 | # https://github.com/rfordatascience/tidytuesday 2 | 3 | source("scripts/startup.R") 4 | 5 | library(tidyverse) 6 | library(ggtext) 7 | library(showtext) 8 | library(countrycode) 9 | 10 | # load data --------------------------------------------------------------- 11 | 12 | wheels <- readr::read_csv('https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2022/2022-08-09/wheels.csv') 13 | 14 | # fonts and palettes ------------------------------------------------------ 15 | 16 | spec <- c("#005f73", "#0a9396", "#94d2bd", "#e9d8a6", "#ee9b00", "#ca6702", "#bb3e03", "#ae2012") 17 | blue_pink <<- c(lighten("#084B83", 0.3), "#42BFDD", "#BBE6E4", "#F0F6F6", "#FF66B3") 18 | lakes <- c("#788FCE", "#e07a5f", "#f2cc8f", "#81b29a", "#f4f1de") 19 | 20 | pal <- sunset 21 | bg <- "grey20" 22 | txt_col <- "white" 23 | 24 | font_add_google("Kanit", "kanit") 25 | font_add_google("Cinzel", "cin") 26 | showtext_auto() 27 | 28 | ft_text <- "kanit" 29 | ft_title <- "cin" 30 | 31 | # wrangle ----------------------------------------------------------------- 32 | 33 | df_base <- wheels |> 34 | filter(construction_cost != "Unknown") |> 35 | select(name, height, hourly_capacity, construction_cost, number_of_cabins, country) |> 36 | mutate( 37 | construction_cost = as.numeric(str_extract(construction_cost, "[:digit:]+\\.[:digit:]+|[:digit:]+")), 38 | continent = countrycode( 39 | sourcevar = country, 40 | origin = "country.name", 41 | destination = "continent" 42 | ), 43 | asia = ifelse(continent == "Asia", "Asia", "Other") 44 | ) 45 | 46 | 47 | 48 | # titles ------------------------------------------------------------------ 49 | 50 | caption <- "Graphic: @danoehm / Source: / Code: doehm/tidytuesday #rstats #tidytuesday" 51 | text <- glue( 52 | "Bigger doesn't necessarily mean higher
53 | hourly capacity. The biggest Ferris Wheels
54 | tend to be in Asia" 55 | ) 56 | 57 | # plot -------------------------------------------------------------------- 58 | 59 | df_base |> 60 | ggplot(aes(height, hourly_capacity, size = number_of_cabins, colour = asia)) + 61 | geom_point(alpha = 0.6) + 62 | geom_text_repel(aes(label = name), 63 | filter(df_base, asia == "Asia"), family = ft_text, colour = bright[3], size = 8) + 64 | annotate("richtext", x = 420, y = 4800, label = text, family = "cin", colour = txt_col, size = 10, lineheight = 0.5, 65 | fill = NA, label.colour = NA) + 66 | scale_colour_manual(values = c(bright[3], "grey50")) + 67 | scale_x_continuous(breaks = seq(100, 600, 100)) + 68 | scale_size(guide = "none") + 69 | labs( 70 | title = "Ferris Wheels", 71 | y = "Hourly\nCapacity", 72 | x = "Height" 73 | ) + 74 | theme_void() + 75 | theme( 76 | text = element_text(family = ft_text, colour = txt_col, size = 20), 77 | axis.text = element_text(margin = margin(t = 5, r = 5)), 78 | axis.title = element_text(margin = margin(t = 5, r = 5), lineheight = 0.35), 79 | axis.line = element_line(colour = txt_col), 80 | plot.title = element_text(family = ft_title, size = 128, hjust = 0.5), 81 | plot.background = element_rect(fill = bg), 82 | plot.margin = margin(20, 20, 20, 20), 83 | legend.position = "none" 84 | ) 85 | 86 | ggsave("2022/week32-ferriswheel/ferriswheel.png", height = 6, width = 6) 87 | -------------------------------------------------------------------------------- /2022/week32-ferriswheel/ferriswheel.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/doehm/tidyTuesday/74fb84eee433ae1741e31857547909c6ce2c5240/2022/week32-ferriswheel/ferriswheel.png -------------------------------------------------------------------------------- /2022/week33-psychometrics/bb01.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/doehm/tidyTuesday/74fb84eee433ae1741e31857547909c6ce2c5240/2022/week33-psychometrics/bb01.jpg -------------------------------------------------------------------------------- /2022/week33-psychometrics/bb01d.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/doehm/tidyTuesday/74fb84eee433ae1741e31857547909c6ce2c5240/2022/week33-psychometrics/bb01d.jpg -------------------------------------------------------------------------------- /2022/week33-psychometrics/bb02.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/doehm/tidyTuesday/74fb84eee433ae1741e31857547909c6ce2c5240/2022/week33-psychometrics/bb02.jpg -------------------------------------------------------------------------------- /2022/week33-psychometrics/bb02d.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/doehm/tidyTuesday/74fb84eee433ae1741e31857547909c6ce2c5240/2022/week33-psychometrics/bb02d.jpg -------------------------------------------------------------------------------- /2022/week33-psychometrics/bb03.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/doehm/tidyTuesday/74fb84eee433ae1741e31857547909c6ce2c5240/2022/week33-psychometrics/bb03.jpg -------------------------------------------------------------------------------- /2022/week33-psychometrics/bb03d.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/doehm/tidyTuesday/74fb84eee433ae1741e31857547909c6ce2c5240/2022/week33-psychometrics/bb03d.jpg -------------------------------------------------------------------------------- /2022/week33-psychometrics/bb04.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/doehm/tidyTuesday/74fb84eee433ae1741e31857547909c6ce2c5240/2022/week33-psychometrics/bb04.jpg -------------------------------------------------------------------------------- /2022/week33-psychometrics/bb04d.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/doehm/tidyTuesday/74fb84eee433ae1741e31857547909c6ce2c5240/2022/week33-psychometrics/bb04d.jpg -------------------------------------------------------------------------------- /2022/week33-psychometrics/bb05.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/doehm/tidyTuesday/74fb84eee433ae1741e31857547909c6ce2c5240/2022/week33-psychometrics/bb05.jpg -------------------------------------------------------------------------------- /2022/week33-psychometrics/bb05d.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/doehm/tidyTuesday/74fb84eee433ae1741e31857547909c6ce2c5240/2022/week33-psychometrics/bb05d.jpg -------------------------------------------------------------------------------- /2022/week33-psychometrics/bb06.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/doehm/tidyTuesday/74fb84eee433ae1741e31857547909c6ce2c5240/2022/week33-psychometrics/bb06.jpg -------------------------------------------------------------------------------- /2022/week33-psychometrics/bb06d.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/doehm/tidyTuesday/74fb84eee433ae1741e31857547909c6ce2c5240/2022/week33-psychometrics/bb06d.jpg -------------------------------------------------------------------------------- /2022/week33-psychometrics/bb07.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/doehm/tidyTuesday/74fb84eee433ae1741e31857547909c6ce2c5240/2022/week33-psychometrics/bb07.jpg -------------------------------------------------------------------------------- /2022/week33-psychometrics/bb07d.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/doehm/tidyTuesday/74fb84eee433ae1741e31857547909c6ce2c5240/2022/week33-psychometrics/bb07d.jpg -------------------------------------------------------------------------------- /2022/week33-psychometrics/bb08.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/doehm/tidyTuesday/74fb84eee433ae1741e31857547909c6ce2c5240/2022/week33-psychometrics/bb08.jpg -------------------------------------------------------------------------------- /2022/week33-psychometrics/bb08d.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/doehm/tidyTuesday/74fb84eee433ae1741e31857547909c6ce2c5240/2022/week33-psychometrics/bb08d.jpg -------------------------------------------------------------------------------- /2022/week33-psychometrics/bb09.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/doehm/tidyTuesday/74fb84eee433ae1741e31857547909c6ce2c5240/2022/week33-psychometrics/bb09.jpg -------------------------------------------------------------------------------- /2022/week33-psychometrics/bb09d.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/doehm/tidyTuesday/74fb84eee433ae1741e31857547909c6ce2c5240/2022/week33-psychometrics/bb09d.jpg -------------------------------------------------------------------------------- /2022/week33-psychometrics/bb10.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/doehm/tidyTuesday/74fb84eee433ae1741e31857547909c6ce2c5240/2022/week33-psychometrics/bb10.jpg -------------------------------------------------------------------------------- /2022/week33-psychometrics/bb10d.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/doehm/tidyTuesday/74fb84eee433ae1741e31857547909c6ce2c5240/2022/week33-psychometrics/bb10d.jpg -------------------------------------------------------------------------------- /2022/week33-psychometrics/bb11.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/doehm/tidyTuesday/74fb84eee433ae1741e31857547909c6ce2c5240/2022/week33-psychometrics/bb11.jpg -------------------------------------------------------------------------------- /2022/week33-psychometrics/bb11d.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/doehm/tidyTuesday/74fb84eee433ae1741e31857547909c6ce2c5240/2022/week33-psychometrics/bb11d.jpg -------------------------------------------------------------------------------- /2022/week33-psychometrics/bb12.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/doehm/tidyTuesday/74fb84eee433ae1741e31857547909c6ce2c5240/2022/week33-psychometrics/bb12.jpg -------------------------------------------------------------------------------- /2022/week33-psychometrics/bb12d.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/doehm/tidyTuesday/74fb84eee433ae1741e31857547909c6ce2c5240/2022/week33-psychometrics/bb12d.jpg -------------------------------------------------------------------------------- /2022/week33-psychometrics/psychometrics Flynn White.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/doehm/tidyTuesday/74fb84eee433ae1741e31857547909c6ce2c5240/2022/week33-psychometrics/psychometrics Flynn White.png -------------------------------------------------------------------------------- /2022/week33-psychometrics/psychometrics Gus Fring.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/doehm/tidyTuesday/74fb84eee433ae1741e31857547909c6ce2c5240/2022/week33-psychometrics/psychometrics Gus Fring.png -------------------------------------------------------------------------------- /2022/week33-psychometrics/psychometrics Hank Schrader.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/doehm/tidyTuesday/74fb84eee433ae1741e31857547909c6ce2c5240/2022/week33-psychometrics/psychometrics Hank Schrader.png -------------------------------------------------------------------------------- /2022/week33-psychometrics/psychometrics Jane Margolis.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/doehm/tidyTuesday/74fb84eee433ae1741e31857547909c6ce2c5240/2022/week33-psychometrics/psychometrics Jane Margolis.png -------------------------------------------------------------------------------- /2022/week33-psychometrics/psychometrics Jesse Pinkman.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/doehm/tidyTuesday/74fb84eee433ae1741e31857547909c6ce2c5240/2022/week33-psychometrics/psychometrics Jesse Pinkman.png -------------------------------------------------------------------------------- /2022/week33-psychometrics/psychometrics Marie Schrader.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/doehm/tidyTuesday/74fb84eee433ae1741e31857547909c6ce2c5240/2022/week33-psychometrics/psychometrics Marie Schrader.png -------------------------------------------------------------------------------- /2022/week33-psychometrics/psychometrics Mike Ehrmantraut.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/doehm/tidyTuesday/74fb84eee433ae1741e31857547909c6ce2c5240/2022/week33-psychometrics/psychometrics Mike Ehrmantraut.png -------------------------------------------------------------------------------- /2022/week33-psychometrics/psychometrics Saul Goodman.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/doehm/tidyTuesday/74fb84eee433ae1741e31857547909c6ce2c5240/2022/week33-psychometrics/psychometrics Saul Goodman.png -------------------------------------------------------------------------------- /2022/week33-psychometrics/psychometrics Skyler White.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/doehm/tidyTuesday/74fb84eee433ae1741e31857547909c6ce2c5240/2022/week33-psychometrics/psychometrics Skyler White.png -------------------------------------------------------------------------------- /2022/week33-psychometrics/psychometrics Walter White.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/doehm/tidyTuesday/74fb84eee433ae1741e31857547909c6ce2c5240/2022/week33-psychometrics/psychometrics Walter White.png -------------------------------------------------------------------------------- /2022/week33-psychometrics/psychometrics.R: -------------------------------------------------------------------------------- 1 | # https://github.com/rfordatascience/tidytuesday 2 | 3 | library(tidyverse) 4 | library(ggtext) 5 | library(showtext) 6 | library(glue) 7 | 8 | # load data --------------------------------------------------------------- 9 | 10 | tt <- tidytuesdayR::tt_load(2022, week = 33) 11 | 12 | # fonts and palettes ------------------------------------------------------ 13 | 14 | txt_col <- "white" 15 | txt_col2 <- "grey20" 16 | 17 | font_add_google("Mukta", "mukta") 18 | font_add_google("Merriweather", "mw") 19 | showtext_auto() 20 | ft_text <- "mukta" 21 | ft2 <- "mw" 22 | 23 | green <- "#0D5134" 24 | 25 | # wrangle ----------------------------------------------------------------- 26 | 27 | top10 <- tt$psych_stats |> 28 | filter(uni_id == "BB") |> 29 | group_by(question) |> 30 | summarise( 31 | n = n(), 32 | num_ratings = sum(number_ratings) 33 | ) |> 34 | arrange(desc(num_ratings)) |> 35 | slice_head(n = 10) 36 | 37 | a <- 1 38 | df_base <- 39 | tt$psych_stats |> 40 | filter(uni_id == "BB") |> 41 | semi_join(top10, by = "question") |> 42 | mutate( 43 | y = as.numeric(factor(question)) - 1, 44 | x = ifelse(str_locate(question, personality)[,1] > 1, 2, 1)+a, 45 | xmax = x+0.95, 46 | ymax = y+0.95, 47 | left_text = str_to_title(str_extract(question, "[:alpha:]+")), 48 | right_text = str_to_title(str_extract(question, "(?<=/).+")), 49 | x_text = x + 0.45, 50 | y_text = y + 0.45, 51 | x_left_text = 0.5+a, 52 | x_right_text = 3.5+a, 53 | square_text = str_to_title(str_sub(personality, 1, 2)) 54 | ) |> 55 | group_by(char_name, question) |> 56 | slice_head() |> 57 | as.data.frame() 58 | 59 | df_title <- tribble( 60 | ~x, ~xmax, ~y, ~ymax, ~x_text, ~y_text, ~label1, ~label2, 61 | 1, 2.5, 13.5, 15, 1.75, 14.25, "Br", "eaking", 62 | 2.5, 4, 12, 13.5, 3.25, 12.75, "Ba", "d" 63 | ) |> 64 | mutate( 65 | y = y + 1, 66 | ymax = ymax + 1, 67 | y_text = y_text + 1 68 | ) 69 | 70 | # Resize and make images darker ------------------------------------------- 71 | 72 | imgs <- c(paste0("0", 1:9), 10:12) 73 | walk(imgs, ~{ 74 | image_read(glue("2022/week33-psychometrics/bb{.x}.jpg")) |> 75 | image_resize("950x1689") |> 76 | image_modulate(brightness = 40, saturation = 40, hue = 100) |> 77 | image_write(glue("2022/week33-psychometrics/bb{.x}d.jpg")) 78 | }) 79 | 80 | # set vector 81 | characters <- unique(df_base$char_name) 82 | img <- c( 83 | "Walter White" = "bb05", 84 | "Jesse Pinkman" = "bb03", 85 | "Mike Ehrmantraut" = "bb11", 86 | "Saul Goodman" = "bb12", 87 | "Hank Schrader" = "bb08", 88 | "Gus Fring" = "bb10", 89 | "Jane Margolis" = "bb06", 90 | "Skyler White" = "bb09", 91 | "Flynn White" = "bb01", 92 | "Marie Schrader" = "bb07") 93 | 94 | # plot -------------------------------------------------------------------- 95 | 96 | make_plot <- function(char) { 97 | 98 | df_base |> 99 | filter(char_name == char) |> 100 | ggplot() + 101 | 102 | # background 103 | ggpubr::background_image(image_read(glue("2022/week33-psychometrics/{img[char]}d.jpg"))) + 104 | 105 | # element boxes 106 | geom_rect(aes(xmin = x, xmax = xmax, ymin = y, ymax = ymax), fill = green, colour = "white", size = 1) + 107 | geom_text(aes(x_left_text, y_text, label = left_text), family = ft_text, colour = txt_col, size = 18, hjust = 1) + 108 | geom_text(aes(x_right_text, y_text, label = right_text), family = ft_text, colour = txt_col, size = 18, hjust = 0) + 109 | geom_text(aes(x_text, y_text, label = square_text), family = ft_text, colour = txt_col, size = 42, hjust = 0.5) + 110 | 111 | geom_text(aes(x+0.85, y+0.85, label = paste0(avg_rating, "%")), family = ft_text, colour = txt_col, size = 8, hjust = 1) + 112 | geom_text(aes(x+0.85, y+0.1, label = number_ratings), family = ft_text, colour = txt_col, size = 8, hjust = 1) + 113 | geom_text(aes(x+0.1, y+0.85, label = rank), family = ft_text, colour = txt_col, size = 8, hjust = 0) + 114 | 115 | # title 116 | geom_rect(aes(xmin = x, xmax = xmax, ymin = y, ymax = ymax), df_title, fill = green, colour = "white", size = 1) + 117 | geom_text(aes(x_text, y_text, label = label1), df_title, family = ft_text, colour = txt_col, size = 78, hjust = 0.5) + 118 | geom_text(aes(xmax+0.1, y_text-0.1, label = label2), df_title, family = ft2, colour = txt_col, size = 54, hjust = 0) + 119 | annotate("text", 3.25, 12.65, label = "Psychometric Character Profiles", family = ft_text, size = 24, colour = txt_col) + 120 | 121 | geom_text(aes(x+1.36, y+1.36, label = "% votes"), df_title, family = ft_text, colour = txt_col, size = 9, hjust = 1) + 122 | geom_text(aes(x+1.36, y+0.14, label = "# ratings"), df_title, family = ft_text, colour = txt_col, size = 9, hjust = 1) + 123 | geom_text(aes(x+0.14, y+1.36, label = "Rank"), df_title, family = ft_text, colour = txt_col, size = 9, hjust = 0) + 124 | 125 | # name 126 | annotate("text", x = 3.25, y = 11.25, label = char, family = ft2, size = 54, colour = txt_col, fontface = "bold") + 127 | 128 | xlim(-1, 7.2) + 129 | ylim(0, 16) + 130 | theme_void() 131 | 132 | ggsave(glue("2022/week33-psychometrics/psychometrics {char}.png"), height = 12, width = 12*950/1689) 133 | 134 | } 135 | 136 | # make all plots 137 | walk(characters, make_plot) 138 | -------------------------------------------------------------------------------- /2022/week34-chips/chips.R: -------------------------------------------------------------------------------- 1 | # https://github.com/rfordatascience/tidytuesday 2 | 3 | library(tidyverse) 4 | library(janitor) 5 | library(ggtext) 6 | library(showtext) 7 | 8 | source("scripts/startup.R") 9 | 10 | # load data --------------------------------------------------------------- 11 | 12 | chips <- read_csv("2022/week34-chips/chip.csv") |> 13 | clean_names() 14 | 15 | # fonts and palettes ------------------------------------------------------ 16 | 17 | bright <- c("#540d6e", "#ee4266", "#ffd23f", "#3bceac") 18 | bg <- "white" 19 | txt_col <- "black" 20 | ft_text <- "incon" 21 | 22 | # wrangle ----------------------------------------------------------------- 23 | 24 | df_base <- chips |> 25 | filter( 26 | type == "GPU", 27 | vendor %in% c("AMD", "NVIDIA") 28 | ) |> 29 | mutate( 30 | transistors_million = log(transistors_million), 31 | FP16 = log(fp16_gflops), 32 | FP32 = log(fp32_gflops), 33 | FP64 = log(fp64_gflops), 34 | vendor = tolower(vendor) 35 | ) |> 36 | pivot_longer(c(FP16, FP32, FP64), names_to = "n_gflops", values_to = "gflops") 37 | 38 | # titles ------------------------------------------------------------------ 39 | 40 | # caption <- glue("Graphic: {get_icon('twitter', 10, fill = list(bg = bg, img = txt_col))} @danoehm / Source: CHIP dataset / Code: {get_icon('github', 10, fill = list(bg = bg, img = txt_col))} doehm/tidytuesday #rstats #tidytuesday") 41 | 42 | # plot -------------------------------------------------------------------- 43 | 44 | df_base |> 45 | ggplot(aes(transistors_million, gflops, size = die_size_mm_2, colour = freq_m_hz)) + 46 | geom_point(alpha = 0.5) + 47 | facet_wrap(~n_gflops, nrow = 3, strip.position = "right") + 48 | scale_colour_gradientn(colours = pal) + 49 | scale_y_continuous(breaks = seq(4, 12, 2), labels = c(50, 400, "3k", "22k", "163k")) + 50 | scale_x_continuous(breaks = seq(6, 12, 2), labels = c(400, "3k", "22k", "163k"), limits = c(5, 11)) + 51 | labs( 52 | x = "Transistors (Million)", 53 | y = "GFLOPS", 54 | size = "Die Size mm2", 55 | colour = "Freq Mhz", 56 | title = "GPU Performance", 57 | subtitle = "GPU performance improvement is a joint effect of smaller\n 58 | transistors, larger die size, and higher frequency", 59 | caption = "@danoehm / Source: CHIP dataset / Code: doehm/tidytuesday #rstats #tidytuesday" 60 | ) + 61 | theme_minimal() + 62 | theme( 63 | text = element_text(family = ft_text, size = 36, colour = "black"), 64 | strip.background = element_rect(fill = "grey20"), 65 | strip.text = element_text(colour = "white", angle = 270, margin = margin(2, 2, 2, 2), size = 36, face = "bold"), 66 | legend.position = "right", 67 | plot.margin = margin(t = 40, l = 40, r = 40, b = 5), 68 | plot.background = element_rect(fill = "white"), 69 | plot.title = element_text(size = 64, face = "bold", hjust = 0.5), 70 | plot.subtitle = element_text(size = 36, lineheight = 0.2, hjust = 0.5, margin = margin(b = 20)), 71 | plot.caption = element_markdown(size = 24, hjust = 0.5, margin = margin(t = 30)) 72 | ) 73 | 74 | ggsave("2022/week34-chips/chips.png", height = 8, width = 8) 75 | -------------------------------------------------------------------------------- /2022/week34-chips/chips.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/doehm/tidyTuesday/74fb84eee433ae1741e31857547909c6ce2c5240/2022/week34-chips/chips.png -------------------------------------------------------------------------------- /2022/week36-lego/1 lego.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/doehm/tidyTuesday/74fb84eee433ae1741e31857547909c6ce2c5240/2022/week36-lego/1 lego.png -------------------------------------------------------------------------------- /2022/week36-lego/2 lego.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/doehm/tidyTuesday/74fb84eee433ae1741e31857547909c6ce2c5240/2022/week36-lego/2 lego.png -------------------------------------------------------------------------------- /2022/week36-lego/lego.R: -------------------------------------------------------------------------------- 1 | # https://github.com/rfordatascience/tidytuesday 2 | 3 | library(tidyverse) 4 | library(showtext) 5 | library(patchwork) 6 | library(janitor) 7 | library(glue) 8 | library(ggtext) 9 | library(ggchicklet) 10 | library(magick) 11 | library(forcats) 12 | 13 | # load data --------------------------------------------------------------- 14 | 15 | sets <- readr::read_csv('https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2022/2022-09-06/sets.csv.gz') 16 | themes <- readr::read_csv('https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2022/2022-09-06/themes.csv.gz') 17 | 18 | # fonts and palettes ------------------------------------------------------ 19 | 20 | sysfonts::font_add( 21 | family = "lego", 22 | regular = "fonts/lego/Legothick.ttf" 23 | ) 24 | 25 | font_add_google("Oswald", "oswald") 26 | showtext_auto() 27 | 28 | pal_lego <- c("#FDFDFD", "#F5EE03", "#FD0000", "#060404") 29 | bg <- pal_lego[3] 30 | ft_txt <- "oswald" 31 | 32 | # wrangle ----------------------------------------------------------------- 33 | 34 | df_top_n_sets <- sets |> 35 | left_join( 36 | themes |> 37 | rename( 38 | theme_id = id, 39 | theme_name = name 40 | ), 41 | by = "theme_id") |> 42 | count(theme_name) |> 43 | slice_max(n, n = 20) |> 44 | arrange(n) |> 45 | mutate( 46 | y = 1:n(), 47 | theme_name = toupper(theme_name), 48 | theme_name = fct_reorder(theme_name, n, max) 49 | ) 50 | 51 | # titles ------------------------------------------------------------------ 52 | 53 | # get_icon: my custom function in startup.R 54 | caption <- glue("Graphic: {get_icon('twitter', 15, fill = list(bg = bg, img = txt))} @danoehm / Source: rebrickable / Code: {get_icon('github', 15, fill = list(bg = bg, img = txt))} doehm/tidytuesday #rstats #tidytuesday") 55 | subtitle <- 56 | "The top 20 57 | LEGO themes 58 | with the 59 | most sets" 60 | 61 | df_y_lab <- tibble( 62 | y = seq(0, 2000, 500), 63 | x = 21 64 | ) 65 | 66 | # plot -------------------------------------------------------------------- 67 | 68 | df_top_n_sets |> 69 | ggplot() + 70 | geom_chicklet(aes(y, n), fill = "white", colour = pal[2], size = 3, width = 0.75, radius = grid::unit(9, "pt")) + 71 | geom_chicklet(aes(y, n), fill = "white", colour = "black", size = 1, width = 0.75, radius = grid::unit(9, "pt")) + 72 | geom_text(aes(y, -100, label = theme_name), family = "lego", size = 36, hjust = 1, colour = "black", fontface = "bold") + 73 | annotate("rect", xmin = 0, xmax = 10, ymin = 500, ymax = 2150, fill = pal_lego[3]) + 74 | geom_richtext(aes(x, y, label = y), df_y_lab, size = 16, family = ft_txt, fill = pal_lego[3], label.colour = NA, colour = txt, fontface = "bold") + 75 | geom_image(aes(x = 8, y = 1500, image = "2022/week36-lego/lego_cropped.png"), asp = 1, size = 0.25) + 76 | annotate("text", x = 4, y = 1420, label = subtitle, family = ft_txt, colour = txt, lineheight = 0.3, size = 30, fontface = "bold", hjust = 0.5) + 77 | annotate("richtext", x = -1, y = 0, label = caption, size = 16, family = ft_txt, fill = pal_lego[3], label.colour = NA, colour = txt)+ 78 | scale_y_continuous(limits = c(-1800, 2150), position = "right") + 79 | labs(x = "Number of sets") + 80 | coord_flip(clip = "off") + 81 | theme_void() + 82 | theme( 83 | plot.background = element_rect(fill = "white", colour = "black", size = 10), 84 | plot.margin = margin(t = 50, b = 20, l = 20, r = 20) 85 | ) 86 | 87 | ggsave("2022/week36-lego/lego.png", height = 10, width = 10.5) 88 | 89 | image_read("2022/week36-lego/lego.png") |> 90 | image_fill(point = "+100+100", color = pal_lego[3]) |> 91 | image_write("2022/week36-lego/lego.png") 92 | -------------------------------------------------------------------------------- /2022/week36-lego/lego.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/doehm/tidyTuesday/74fb84eee433ae1741e31857547909c6ce2c5240/2022/week36-lego/lego.jpg -------------------------------------------------------------------------------- /2022/week36-lego/lego.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/doehm/tidyTuesday/74fb84eee433ae1741e31857547909c6ce2c5240/2022/week36-lego/lego.png -------------------------------------------------------------------------------- /2022/week36-lego/lego_cropped.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/doehm/tidyTuesday/74fb84eee433ae1741e31857547909c6ce2c5240/2022/week36-lego/lego_cropped.png -------------------------------------------------------------------------------- /2022/week39-artists/artists-District of Columbia.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/doehm/tidyTuesday/74fb84eee433ae1741e31857547909c6ce2c5240/2022/week39-artists/artists-District of Columbia.png -------------------------------------------------------------------------------- /2022/week39-artists/artists-Nevada.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/doehm/tidyTuesday/74fb84eee433ae1741e31857547909c6ce2c5240/2022/week39-artists/artists-Nevada.png -------------------------------------------------------------------------------- /2022/week39-artists/artists-New York.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/doehm/tidyTuesday/74fb84eee433ae1741e31857547909c6ce2c5240/2022/week39-artists/artists-New York.png -------------------------------------------------------------------------------- /2022/week39-artists/artists-South Dakota.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/doehm/tidyTuesday/74fb84eee433ae1741e31857547909c6ce2c5240/2022/week39-artists/artists-South Dakota.png -------------------------------------------------------------------------------- /2022/week39-artists/artists.R: -------------------------------------------------------------------------------- 1 | # https://github.com/rfordatascience/tidytuesday 2 | 3 | library(tidyverse) 4 | library(showtext) 5 | library(janitor) 6 | library(glue) 7 | library(ggtext) 8 | library(forcats) 9 | library(ggbeeswarm) 10 | library(emojifont) 11 | 12 | # load data --------------------------------------------------------------- 13 | 14 | artists <- tidytuesdayR::tt_load(2022, 39)$artists 15 | 16 | # fonts and palettes ------------------------------------------------------ 17 | 18 | pal <- c("#7B2CBF", "#953B98", "#AF4A72", "#CA5A4C", "#E46926", "#FF7900") 19 | bright <- c("#540d6e", "#ee4266", "#ffd23f", "#3bceac") 20 | bg <- "white" 21 | txt <- "grey20" 22 | 23 | font_add_google("Josefin Sans", "txt") 24 | font_add_google("Shrikhand", "title") 25 | showtext_auto() 26 | ft <- "txt" 27 | ft_title <- "title" 28 | 29 | fa_path <- systemfonts::font_info(family = "Font Awesome 6 Brands Regular")[["path"]] 30 | font_add(family = "fa-brands", regular = fa_path) 31 | 32 | # wrangle ----------------------------------------------------------------- 33 | 34 | df_mean <- artists |> 35 | group_by(type) |> 36 | summarise(n_artists = sum(artists_n, na.rm = TRUE)) |> 37 | ungroup() |> 38 | mutate(p_mean = n_artists/sum(n_artists)) |> 39 | select(type, p_mean) 40 | 41 | df_base <- artists |> 42 | group_by(type, state) |> 43 | summarise( 44 | n_artists = sum(artists_n, na.rm = TRUE), 45 | lq = sum(log(location_quotient)*artists_n/sum(artists_n, na.rm = TRUE), na.rm = TRUE) 46 | ) |> 47 | filter(is.finite(lq)) |> 48 | group_by(state) |> 49 | mutate(p = n_artists/sum(n_artists)) |> 50 | ungroup() |> 51 | mutate( 52 | lab = type, 53 | type = as.numeric(fct_reorder(type, lq, median)) 54 | ) 55 | 56 | # titles ------------------------------------------------------------------ 57 | 58 | twitter <- glue("{fontawesome('fa-twitter')}") 59 | github <- glue("{fontawesome('fa-github')}") 60 | caption <- str_wrap(glue( 61 | "Graphic: {twitter} @danoehm / 62 | Source: arts.gov by way of Data is Plural / 63 | Code: {github} doehm/tidytuesday #rstats #tidytuesday"), 64 | 1000) 65 | 66 | subtitle <- str_wrap( 67 | "The Location quotients (LQ) measure an artist occupation's concentration in the labor force, 68 | relative to the U.S. labor force share. For example, an LQ of 1.2 indicates that the state's 69 | labor force in an occupation is 20 percent greater than the occupation's national labor force 70 | share. An LQ of 0.8 indicates that the state's labor force in an occupation is 20 percent below 71 | the occupation's national labor force share.", 100) 72 | 73 | # California has proportionally more artists in every 74 | # category, particularly actors. 75 | 76 | # plot -------------------------------------------------------------------- 77 | 78 | make_plot <- function(.state, .x) { 79 | 80 | title <- glue("Artists in {.state}") 81 | 82 | df_state <- df_base |> 83 | filter(state == .state) 84 | 85 | df_base |> 86 | ggplot(aes(type, lq)) + 87 | geom_text(aes(type, -4, label = str_wrap(lab, 25)), df_state, family = ft, size = 20, colour = "grey20", hjust = 0, lineheight = 0.3, vjust = 0.5) + 88 | geom_beeswarm(size = 4, alpha = 0.5, colour = "grey40") + 89 | geom_point(aes(x, y), tibble(x = 1:13, y = 0), colour = "grey20", size = 3) + 90 | geom_point(aes(type, lq), df_state, size = 6, colour = .x) + 91 | annotate("text", y = -1.2, x = 14, label = "Less than the national share", family = ft, size = 12, colour = "grey20") + 92 | annotate("text", y = 1.2, x = 14, label = "More than the national share", family = ft, size = 12, colour = "grey20") + 93 | scale_y_continuous(breaks = log(c(0.1, 0.25, 0.5, 1, 2, 4, 8)), labels = round(c(0.1, 0.25, 0.5, 1, 2, 4, 8), 1)) + 94 | coord_flip(clip = "off") + 95 | theme_void() + 96 | labs( 97 | y = "Location Quotient (log scale)", 98 | title = title, 99 | subtitle = subtitle, 100 | caption = caption 101 | ) + 102 | theme( 103 | text = element_text(family = ft, colour = txt, size = 36), 104 | plot.background = element_rect(fill = bg), 105 | plot.margin = margin(t = 30, b = 10, l = 30, r = 30), 106 | plot.caption = element_markdown(hjust = 0.5, margin = margin(t = 15)), 107 | plot.title = element_markdown(size = 100, hjust = 0.5, family = ft_title), 108 | plot.subtitle = element_text(size = 36, hjust = 0.5, lineheight = 0.25), 109 | axis.text.x = element_text(), 110 | axis.title.x = element_text(margin = margin(t = 10)), 111 | ) 112 | 113 | ggsave(glue("2022/week39-artists/artists-{.state}.png"), height = 12, width = 8.5) 114 | 115 | } 116 | 117 | # generate plots ---------------------------------------------------------- 118 | 119 | make_plot("California", pal[6]) 120 | 121 | states <- c("South Dakota", "District of Columbia", "Nevada", "New York") 122 | walk2(states, bright, make_plot) 123 | -------------------------------------------------------------------------------- /2022/week39-artists/artists.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/doehm/tidyTuesday/74fb84eee433ae1741e31857547909c6ce2c5240/2022/week39-artists/artists.png -------------------------------------------------------------------------------- /2022/week41-ravelry/ravelry.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/doehm/tidyTuesday/74fb84eee433ae1741e31857547909c6ce2c5240/2022/week41-ravelry/ravelry.png -------------------------------------------------------------------------------- /2022/week41-ravelry/raverly.R: -------------------------------------------------------------------------------- 1 | # https://github.com/rfordatascience/tidytuesday 2 | 3 | library(tidyverse) 4 | library(showtext) 5 | library(janitor) 6 | library(glue) 7 | library(ggtext) 8 | library(ggforce) 9 | library(ggfx) 10 | library(emojifont) 11 | 12 | # load data --------------------------------------------------------------- 13 | 14 | yarn <- readr::read_csv('https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2022/2022-10-11/yarn.csv') 15 | 16 | # fonts and palettes ------------------------------------------------------ 17 | 18 | pal <- tribble( 19 | ~r, ~g, ~b, 20 | 198, 114, 67, 21 | 220, 166, 146, 22 | 180, 185, 163, 23 | 129, 160, 149, 24 | 30, 166, 179 25 | ) |> 26 | mutate(pal = rgb(r, g, b, maxColorValue = 255)) |> 27 | pull(pal) 28 | pal <- colorRampPalette(pal)(8) 29 | 30 | txt <- "grey20" 31 | bg <- "white" 32 | 33 | font_add_google("Fasthand", "fh") 34 | font_add_google("Karla", "karla") 35 | showtext_auto() 36 | ft <- "fh" 37 | ft1 <- "karla" 38 | 39 | # wrangle ----------------------------------------------------------------- 40 | 41 | df_base <- yarn |> 42 | group_by(yarn_company_name) |> 43 | summarise( 44 | rating = mean(rating_average, na.rm = TRUE), 45 | n = n() 46 | ) |> 47 | arrange(desc(n)) |> 48 | head(8) |> 49 | ungroup() |> 50 | mutate( 51 | p = n/sum(n), 52 | x0 = 1:n() 53 | ) 54 | 55 | # yarn 56 | df_yarn <- map_dfr(1:nrow(df_base), ~{ 57 | tibble( 58 | x = 3*df_base$p[.x]*sin(seq(0, 2*pi, length = 200)) + df_base$x0[.x], 59 | y = 3*df_base$p[.x]*cos(seq(0, 2*pi, length = 200)) + df_base$rating[.x] - 3*df_base$p[.x], 60 | id = runif(200), 61 | yarn_company_name = df_base$yarn_company_name[.x] 62 | ) 63 | }) |> 64 | mutate(y = -y) |> 65 | arrange(yarn_company_name, id) 66 | 67 | # titles ------------------------------------------------------------------ 68 | 69 | twitter <- glue("{emojifont::fontawesome('fa-twitter')}") 70 | github <- glue("{emojifont::fontawesome('fa-github')}") 71 | caption <- str_wrap(glue( 72 | "Graphic: {twitter} @danoehm / 73 | Source: ravelry / 74 | Code: {github} doehm/tidytuesday #rstats #tidytuesday"), 75 | 1000) 76 | 77 | # plot -------------------------------------------------------------------- 78 | 79 | bg <- "#fefae0" 80 | wood <- "#d4a373" 81 | 82 | df_yarn |> 83 | ggplot(aes(x, y)) + 84 | geom_rect(aes(xmin = 0.5, xmax = 8.5, ymin = -1.2, ymax = -1), fill = lighten(wood, 0.2)) + 85 | with_blur(geom_segment(aes(x = x0, xend = x0, y = -1, yend = -rating+0.2, colour = yarn_company_name), df_base, size = 0.6), sigma = 3) + 86 | with_blur(geom_bspline0(aes(colour = yarn_company_name), size = 0.6), sigma = 3) + 87 | geom_text(aes(x0, -rating-0.3, label = paste0(yarn_company_name, "\n", round(rating, 1), " | ", n)), df_base, family = ft, size = 24, colour = txt, lineheight = 0.3) + 88 | coord_cartesian(clip = "off") + 89 | scale_colour_manual( 90 | values = pal, 91 | breaks = df_base$yarn_company_name 92 | ) + 93 | scale_x_continuous( 94 | breaks = 1:8, 95 | labels = df_base$yarn_company_name 96 | ) + 97 | ylim(-5, -1) + 98 | labs( 99 | title = "Yarn Company Ratings", 100 | subtitle = "Top 8 companies with the most yarn\nRating | Number of threads", 101 | caption = caption 102 | ) + 103 | theme_void() + 104 | theme( 105 | text = element_text(family = ft, size = 64, colour = txt), 106 | plot.title = element_text(size = 240, hjust = 0.5), 107 | plot.subtitle = element_text(size = 80, hjust = 0.5, lineheight = 0.25, family = ft1), 108 | plot.background = element_rect(fill = bg, colour = bg), 109 | plot.caption = element_markdown(margin = margin(t = 20, b = 40), hjust = 0.5, family = ft1), 110 | legend.position = "none", 111 | plot.margin = margin(t = 60, b = 0, l = 60, r = 60) 112 | ) 113 | 114 | ggsave("2022/week41-ravelry/ravelry.png", height = 12, width = 16) 115 | -------------------------------------------------------------------------------- /2022/week41-ravelry/tute1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/doehm/tidyTuesday/74fb84eee433ae1741e31857547909c6ce2c5240/2022/week41-ravelry/tute1.png -------------------------------------------------------------------------------- /2022/week41-ravelry/tute2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/doehm/tidyTuesday/74fb84eee433ae1741e31857547909c6ce2c5240/2022/week41-ravelry/tute2.png -------------------------------------------------------------------------------- /2022/week41-ravelry/tute3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/doehm/tidyTuesday/74fb84eee433ae1741e31857547909c6ce2c5240/2022/week41-ravelry/tute3.png -------------------------------------------------------------------------------- /2022/week42-stranger-things/eddie.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/doehm/tidyTuesday/74fb84eee433ae1741e31857547909c6ce2c5240/2022/week42-stranger-things/eddie.jpg -------------------------------------------------------------------------------- /2022/week42-stranger-things/stranger-things-title.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/doehm/tidyTuesday/74fb84eee433ae1741e31857547909c6ce2c5240/2022/week42-stranger-things/stranger-things-title.jpg -------------------------------------------------------------------------------- /2022/week42-stranger-things/stranger-things.R: -------------------------------------------------------------------------------- 1 | # https://github.com/rfordatascience/tidytuesday 2 | 3 | library(tidyverse) 4 | library(showtext) 5 | library(glue) 6 | library(ggtext) 7 | library(tidytext) 8 | library(ggfx) 9 | library(emojifont) 10 | library(colorspace) 11 | 12 | # load data --------------------------------------------------------------- 13 | 14 | dat <- tidytuesdayR::tt_load(2022, week = 42) 15 | 16 | # fonts and palettes ------------------------------------------------------ 17 | 18 | pal <- c("#005f73", "#0a9396", "#94d2bd", "#e9d8a6", "#ee9b00", "#ca6702", "#bb3e03", "#ae2012") 19 | txt <- "white" 20 | txt1 <- "red" 21 | txt2 <- darken(txt1, 0.25) 22 | bg <- "black" 23 | 24 | font_add_google("Heebo", "heebo") 25 | font_add_google("Libre Baskerville", "lb") 26 | showtext_auto() 27 | ft <- "heebo" 28 | ft1 <- "lb" 29 | 30 | # wrangle ------------------------------------------------------------- 31 | 32 | df_base <- dat$stranger_things_all_dialogue |> 33 | filter( 34 | # season == 1, 35 | !is.na(dialogue) 36 | ) |> 37 | mutate(duration = end_time - start_time) |> 38 | unnest_tokens(word, dialogue) |> 39 | left_join(get_sentiments("afinn"), by = "word") |> 40 | group_by(season, episode) |> 41 | mutate( 42 | value = replace_na(value, 0), 43 | value = cumsum(value), 44 | x = 1:n()/n(), 45 | positive = value > 0 46 | ) 47 | 48 | df_labels <- tibble( 49 | season = 1:4, 50 | episode = 5, 51 | x = 0.5, 52 | y = 140, 53 | label = paste("Season", 1:4) 54 | ) 55 | 56 | # titles ------------------------------------------------------------------ 57 | 58 | twitter <- glue("{emojifont::fontawesome('fa-twitter')}") 59 | github <- glue("{emojifont::fontawesome('fa-github')}") 60 | caption <- str_wrap(glue( 61 | "Graphic: {twitter} @danoehm / 62 | Source: 8flix.com / 63 | Code: {github} doehm/tidytuesday #rstats #tidytuesday"), 64 | 1000) 65 | 66 | # plot -------------------------------------------------------------------- 67 | 68 | g_base <- df_base |> 69 | ggplot(aes(x, value)) + 70 | geom_hline(yintercept = 0, colour = txt1, linetype = 2) + 71 | with_blur(geom_smooth(se = FALSE, colour = txt2), sigma = 4) + 72 | geom_smooth(se = FALSE, colour = txt, size = 0.2) + 73 | geom_ribbon(aes(x = x, ymin = 0, ymax = value, fill = positive), alpha = 0.25) + 74 | geom_text(aes(x, y, label = label), df_labels, family = ft1, colour = txt2, size = 36) + 75 | facet_grid(season ~ episode, switch = "x") + 76 | scale_fill_manual(values = c(txt1, txt)) + 77 | scale_colour_manual(values = c(txt1, txt)) + 78 | coord_cartesian(clip = "off") + 79 | labs( 80 | title = "", 81 | caption = caption, 82 | x = "Episode\n\nCumulative sentiment score for each episode. Season 4 has the most\nnegative sentiment and is the darkest of the series" 83 | ) + 84 | theme_void() + 85 | theme( 86 | text = element_text(family = ft, size = 64, colour = txt2), 87 | plot.background = element_rect(fill = bg), 88 | plot.title = element_markdown(hjust = 0.5, margin = margin(b=5)), 89 | plot.subtitle = element_text(hjust = 0.5, lineheight = 0.3, margin = margin(t = 0, b = 50)), 90 | plot.margin = margin(t = 0, b = 20, l = 50, r = 50), 91 | plot.caption = element_markdown(hjust = 0.5, margin = margin(t = 30, b = 20)), 92 | strip.text.x = element_text(), 93 | axis.title.x = element_text(margin = margin(t = 10), lineheight = 0.3), 94 | legend.position = "none" 95 | ) 96 | 97 | ggsave("2022/week42-stranger-things/stranger-things.png", plot = g_base, height = 16, width = 12) 98 | 99 | -------------------------------------------------------------------------------- /2022/week42-stranger-things/stranger-things.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/doehm/tidyTuesday/74fb84eee433ae1741e31857547909c6ce2c5240/2022/week42-stranger-things/stranger-things.png -------------------------------------------------------------------------------- /fonts/lego.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/doehm/tidyTuesday/74fb84eee433ae1741e31857547909c6ce2c5240/fonts/lego.zip -------------------------------------------------------------------------------- /fonts/lego/Legothick.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/doehm/tidyTuesday/74fb84eee433ae1741e31857547909c6ce2c5240/fonts/lego/Legothick.ttf -------------------------------------------------------------------------------- /tidyTuesday.Rproj: -------------------------------------------------------------------------------- 1 | Version: 1.0 2 | 3 | RestoreWorkspace: Default 4 | SaveWorkspace: Default 5 | AlwaysSaveHistory: Default 6 | 7 | EnableCodeIndexing: Yes 8 | UseSpacesForTab: Yes 9 | NumSpacesForTab: 2 10 | Encoding: UTF-8 11 | 12 | RnwWeave: Sweave 13 | LaTeX: pdfLaTeX 14 | 15 | AutoAppendNewline: Yes 16 | StripTrailingWhitespace: Yes 17 | --------------------------------------------------------------------------------