--- title: "Intodution to dplyr with soccer data" output: html_document: code_folding: hide --- ```{r setup, include=FALSE} knitr::opts_chunk$set(echo = TRUE,warning=FALSE,message=FALSE) ``` ```{r} library(tidyverse) library(engsoccerdata) ``` ```{r} finals<- engsoccerdata::champs %>% as_tibble() %>% filter(Season > 1999) %>% filter(round %in% c("final")) %>% mutate(total = tothgoal + totvgoal ) %>% mutate(teams = paste0(Season, ": ", home," vs ",visitor)) %>% select(Season , home , visitor ,teams, total , tothgoal , totvgoal) %>% pivot_longer(cols = c(tothgoal, totvgoal)) %>% mutate(name= fct_rev(name)) %>% mutate(Season=as.factor(Season)) ggplot()+ geom_col(data = filter(finals,name=="totvgoal"), aes(value,Season, fill=name ))+ geom_col(data = filter(finals,name=="tothgoal"), aes(-value,Season, fill=name ))+ scale_x_continuous(labels=abs, expand = expansion(add = c(3,3)), breaks = c(-4:4) )+ geom_text(data = filter(finals,name=="totvgoal"), aes(value,Season, colour=name, label= visitor ), hjust=-0.2)+ geom_text(data = filter(finals,name=="tothgoal"), aes(-value,Season, colour=name, label= home ), hjust=1.2) + ggdark::dark_theme_gray() + scale_fill_manual(values = c("sienna1", "dodgerblue3")) + scale_color_manual(values =c("sienna1", "dodgerblue3")) + theme(legend.position = "none") + labs(x = "Goals scored", title = "Champions League finals", subtitle = "Results" ) ```