Created
January 14, 2025 22:09
-
-
Save luisDVA/6eaa6f369bacace4cfe8630d29513dfc to your computer and use it in GitHub Desktop.
TidyTuesday, jan14 2025
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# tidytuesday, jan. 14th 2025 | |
library(dplyr) | |
library(tidyr) | |
library(stringr) | |
library(readr) | |
library(stringi) | |
conf2024 <- read_csv('https://raw.githubusercontent.com/rfordatascience/tidytuesday/main/data/2025/2025-01-14/conf2024.csv') | |
conf2023 <- read_csv('https://raw.githubusercontent.com/rfordatascience/tidytuesday/main/data/2025/2025-01-14/conf2023.csv') | |
conf2024 <- | |
conf2024 %>% | |
mutate(speaker_name = str_replace(speaker_name, ", and ",";")) %>% | |
mutate(speaker_name = str_replace(speaker_name, " and ",";")) %>% | |
separate_rows(speaker_name,sep = ",") |> | |
separate_rows(speaker_name,sep = ";") |> | |
mutate(speaker_name = str_squish(speaker_name)) | |
sp23 <- conf2023$speaker_name | |
sp24 <- conf2024$speaker_name | |
standardize_encoding <- function(vec) { | |
# to UTF-8 | |
vec_utf8 <- enc2utf8(vec) | |
# normalize | |
stringi::stri_trans_nfc(vec_utf8) | |
} | |
sp23 <- standardize_encoding(sp23) | |
sp24 <- standardize_encoding(sp24) | |
Speaker <- unique(c(sp23, sp24)) | |
df <- data.frame( | |
Speaker = Speaker, | |
Event1 = ifelse(Speaker %in% sp23, "Yes", "No"), | |
Event2 = ifelse(Speaker %in% sp24, "Yes", "No"), | |
Both = ifelse(Speaker %in% sp23 & Speaker %in% sp24, "Yes", "No") | |
) | |
firstNameToInitial <- function(names) { | |
name_parts <- strsplit(names, " ") | |
process_name <- function(name) { | |
if (length(name) > 1) { | |
first_initial <- substr(name[1], 1, 1) | |
rest_of_name <- paste(name[-1], collapse = " ") | |
paste0(first_initial, ". ", rest_of_name) | |
} else { | |
name | |
} | |
} | |
sapply(name_parts, process_name) | |
} | |
df <- | |
df |> mutate(Speaker=firstNameToInitial(Speaker)) | |
df <- | |
df %>% mutate(forwrap=case_when( | |
Event1=="Yes"&Event2=="No"~"just1", | |
Event1=="No"&Event2=="Yes"~"just2", | |
TRUE~"Both" | |
)) | |
df <- df |> mutate(Speaker=str_remove(Speaker,"\\(.*\\)")) | |
df <- df |> arrange(Speaker) | |
df$chunk <- cut(1:nrow(df), breaks = 2, labels = c("Chunk 1", "Chunk 2")) | |
library(ggplot2) | |
library(patchwork) | |
library(ggtext) | |
library(forcats) | |
dflong <- df |> | |
pivot_longer(cols = c(Event1, Event2)) %>% | |
mutate(name=str_replace(name,"Event1","2023")) %>% | |
mutate(name=str_replace(name,"Event2","2024")) | |
# ggplot(aes(x=Speaker,y=name,fill=value))+ | |
# theme(axis.text.x = element_text(angle = 90))+ | |
# scale_fill_brewer(guide="none")+ | |
# facet_wrap(~chunk,ncol=1 )+ | |
# geom_tile() | |
dflong <- | |
dflong %>% mutate(SpkrHL= | |
if_else(Both=="Yes",paste0("**",Speaker,"**"),Speaker)) | |
dflong |> filter(chunk=="Chunk 1") %>% | |
ggplot(aes(x=fct_inorder(SpkrHL),y=name,fill=value))+ | |
geom_tile(color="white")+ | |
theme(text = element_text(family = "FreeSans Regular"), | |
axis.text.x = element_markdown(angle = 90,hjust = 1, | |
size = 7.5,vjust=0.5), | |
axis.title.x = element_blank(), | |
axis.title.y = element_blank(), | |
axis.ticks = element_blank(), | |
panel.grid = element_blank(), | |
panel.background = element_rect(fill="#D1DBE5"))+ | |
scale_fill_manual(values = c("transparent","#213D4F"),guide="none")+ | |
dflong |> filter(chunk=="Chunk 2") %>% | |
ggplot(aes(x=fct_inorder(SpkrHL),y=name,fill=value))+ | |
geom_tile(color="white")+ | |
theme(text = element_text(family = "FreeSans Regular"), | |
axis.text.x = element_markdown(angle = 90,hjust = 1, | |
size = 7.5,vjust=0.5), | |
axis.title.x = element_blank(), | |
axis.title.y = element_blank(), | |
axis.ticks = element_blank(), | |
panel.grid = element_blank(), | |
panel.background = element_rect(fill="#D1DBE5"))+ | |
scale_fill_manual(values = c("transparent","#213D4F"),guide="none")+ | |
plot_layout(ncol=1)+ | |
plot_annotation(title = "Repeat speakers at posit::conf()", | |
subtitle = "Speakers that presented at both events are highlighted in bold", | |
caption = "TidyTuesday 2025. Luis D. Verde Arregoitia", | |
theme = theme(title = element_text(family = "FreeSans Regular",size = 17))) | |
ggsave(filename = "tidytuesdayLVjan2025.png",width = 10, height = 4, | |
units = "in",dpi = "retina") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment