library(tidyverse)
# set the fonts
library(showtext)
library(sysfonts)
library(extrafont)
::showtext_auto()
showtext::showtext_opts(dpi=320)
showtextfont_add_google(name="Roboto Condensed",
family="Roboto Condensed")
font_add_google(name="Nerko One",
family="Nerko One")
<- tidytuesdayR::tt_load(2022, week = 48)
tuesdata # wcmatches <- tuesdata$wcmatches
<- tuesdata$worldcups worldcups
%>%names worldcups
%>%DataExplorer::profile_missing() worldcups
%>%head worldcups
%>%pull(year)%>%summary() worldcups
<- worldcups%>%
countries pivot_longer(cols = 2:6,names_to = "position",values_to = "countries") %>%
count(countries)%>%
pull(countries)
countries
<- rnaturalearth::ne_countries(returnclass = "sf")
world
<- world%>%
a filter(name%in%countries) %>%
data.frame() %>%
pull(name)
setdiff(countries,a)
%>%
worlddata.frame() %>%
arrange(name) %>%
pull(name)
%>%
worldcups pivot_longer(cols = 2:6,names_to = "position",values_to = "countries")%>%
distinct() %>%
filter(countries=="Yugoslavia")
<- worldcups %>%
worldcups_long pivot_longer(cols = 2:6,names_to = "position",values_to = "countries")%>%
distinct() %>%
mutate(countries=case_when(countries=="Czechoslovakia"~"Czech Rep.",
=="England"~"United Kingdom",
countries=="Japan, South Korea"~"Japan",
countries=="South Korea"~"Korea",
countries=="Soviet Union"~"Russia",
countries=="USA"~"United States",
countries=="West Germany"~"Germany",
countriesTRUE~countries))
worldcups_long
%>%count(year) worldcups_long
library(sf)
<- worldcups_long %>%
full_sf left_join(world,by=c("countries"="name")) %>%
st_as_sf()
full_sf
ggplot(world) +
geom_sf() +
geom_sf(data = full_sf,aes(fill=position))
ggplot(world) +
geom_sf() +
geom_sf(data = full_sf,aes(fill=attendance))
Continuous:
- scale_fill_gsea
- scale_fill_material
ggplot(world%>%filter(!name=="Antarctica")) +
geom_sf(color="grey80",
alpha=0.8,
linewidth=0.05,
fill="grey40") +
geom_sf(data = full_sf,
aes(fill=goals_scored),
color="grey70",
linewidth=0.2) +
coord_sf() +
::scale_fill_material(palette = c("cyan"),
ggscialpha = 0.8, reverse = FALSE) +
guides(color="none") +
labs(title="FIFA World Cup\ntotal Goals scored since 1930",
subtitle="",
caption="#TidyTuesday week48 FIFA WORLD CUP\nDataSource: FIFA World Cup | DataViz: Federica Gazzelloni",
fill="Goals Scored\n\n1930-2018") +
::theme_map() +
ggthemestheme(text=element_text(color="cyan",family = "Roboto Condensed"),
plot.caption = element_text(hjust = 0.5,lineheight = 1.5),
legend.position = c(0,0),
legend.background = element_blank(),
plot.title = element_text(family="Nerko One",size=16,hjust = 0.5),
plot.background = element_rect(color="black",fill="black"),
panel.background = element_rect(color="black",fill="black"))
ggsave("w48_fifa_world_cup.png",
dpi=220,
width = 9,
height = 6)