The data this week comes from Eurovision. Hattip to Tanya Shapiro and Bob Rudis for sharing some methods to cleaning/scraping this data.
The country to country voting data comes from Data.World
The code is silly, but the emo
package got confused by the following countries (e.g., is it the Netherlands or the Carribean Netherlands?). So I removed the confusing countries by mapping them to countries I knew wouldn’t be in the database. Fortunately, none of the confusing countries were in the top group.
eurovision <- read_csv("eurovision.csv") %>%
mutate(artist_country = case_when(
artist_country == "Netherlands" ~ "Mexico",
artist_country == "Czech Republic" ~ "Guyana",
artist_country == "North Macedonia" ~ "Cuba",
artist_country == "Georgia" ~ "Brazil",
artist_country == "Serbia & Montenegro" ~ "Haiti",
artist_country == "Yugoslavia" ~ "Guatemala",
TRUE ~ artist_country))
library(ggimage)
temp <- eurovision$artist_country %>% map(emo::flag)
temp2 <- temp %>% map(attr, which = "data") %>%
map_df(dplyr::select, runes) %>%
mutate(runes = str_replace(runes, "\\s", "-") )
emojis <- temp2 %>% # data built into package
mutate(emoji_url = paste0("https://abs.twimg.com/emoji/v2/72x72/",
tolower(runes), ".png"))
eurovision %>%
bind_cols(emojis) %>%
filter(section == "grand-final") %>%
#filter(year = 2022) %>%
group_by(artist_country) %>%
filter(sum(!is.na(rank)) > 12) %>%
filter(year >=2000) %>%
filter(min(rank, na.rm = TRUE) == 1) %>%
mutate(country = ifelse(year == 2022 | (artist_country == "Russia" & year == 2021), emoji_url, NA)) %>%
ggplot(aes(x = year, y = rank)) +
geom_image(aes(x = year + 2, image = country)) +
ggbump::geom_bump(aes(color = artist_country)) +
scale_color_brewer(palette = "Set1") +
scale_y_reverse()
Getting the flags onto the plot was a huge endeavor.
praise()
## [1] "You are unreal!"