Home Page

Row

Premier League 2018 2019

Season Review

League Champions

Manchester City

Goals Scored

1072

Transfer Fees

1.17 Billion

Highest Transfers Fees (Chelsea)

148.25 Million

Row

Total TV Revenue Payout

2.46 Billion

Golden Boot Winners

M. Salah, S. Mane, P. Aubameyang

FPA Player of the Season

Virgil Van Dyke

Row

Top Scoring Teams

Sky Sports & BT Sports Payout

Net Spend

Net Spend

Data Table

---
title: "Premier League 2018-2019"
output: 
  flexdashboard::flex_dashboard:
    orientation: rows
    vertical_layout: fill
    social: [ "twitter", "facebook", "menu"]
    source_code: embed
    theme: readable
---

```{r setup, include=FALSE}
library(flexdashboard)
library(knitr)
library(tidyverse)
library(DT)
library(rpivotTable)
library(ggplot2)
library(ggthemes)
library(dplyr)
library(openintro)
library(highcharter)
library(scales)
library(janitor)
```


```{r}
epl <- read_csv("C:\\Users\\ald04\\Desktop\\RR\\Datascience\\Football\\epl_1819.csv",n_max = 20)
epl_transfer <- read_csv("C:\\Users\\ald04\\Desktop\\RR\\Datascience\\Football\\transfer.csv",n_max = 20)
# Cleaning ----------------------------------------------------------------
epl_transfer$end_2016 <- as.numeric(gsub(",","",epl_transfer$end_2016))
epl_transfer$end_2015 <- as.numeric(gsub(",","",epl_transfer$end_2015))
epl_transfer$end_2014 <- as.numeric(gsub(",","",epl_transfer$end_2014))
epl_transfer$end_2012 <- as.numeric(gsub(",","",epl_transfer$end_2012))
epl_transfer$end_2011 <- as.numeric(gsub(",","",epl_transfer$end_2011))
# Formatting --------------------------------------------------------------
epl_mod <- gather(epl_transfer,"period","amount",2:11)
Liv<- epl %>% 
  filter(Team == "Liverpool")
epl <- clean_names(epl)

```

```{r}
mycolors <- c("blue", "#FFC125", "darkgreen", "darkorange")
```

Home Page
=====================================

Row
-------------------------------------

### Premier League  2018 2019

```{r}
valueBox(paste("Season Review"),
        color = "#fbf2e9")
```


### **League Champions**

```{r}
valueBox(paste("Manchester City"),
         icon = "fa-crown",
         color = "Light Gray")

```


### **Goals Scored**

```{r}
valueBox(sum(epl$attack_scored),
         icon = "fa-bullseye",
         color = "Light Gray")
```

### **Transfer Fees**

```{r}
transfer_value <-epl_mod %>% 
  filter(period == "end_2019") %>% 
  tally(abs(round(amount))/1000)
valueBox(paste(round(transfer_value,2),"Billion"),
          color = "Light Gray",
          icon = 'fa-coins')
```

### **Highest Transfers Fees (Chelsea)**

```{r}

HighSpend <- epl_mod %>% 
  filter(period == "end_2019" & team == "Chelsea") %>% 
  select(amount) %>% 
  mutate(amount = amount * -1)

valueBox(paste(HighSpend$amount,"Million"),
         icon = 'fa-piggy-bank',
          color = "Light Gray")
```


Row
-------------------------------

###  **Total TV Revenue  Payout**

```{r}
valueBox(paste(round(sum(epl$finance_tv_revenue)/1000000000,2), "Billion"),
        color = "Light Gray",
         icon = "fa-tv")

```

### **Golden Boot Winners**

```{r}
valueBox(paste("M. Salah,  
               S. Mane, 
               P. Aubameyang"),
         color = "Light Gray",
         icon = "fa-medal")
```

### **FPA Player of the Season**

```{r}
valueBox(paste("Virgil Van Dyke"),
         color = "Light Gray",
         icon = "fa-trophy")
```

Row
------------------------------------
### **Top Scoring Teams**

```{r}
epl %>% 
  group_by(team) %>% 
  tally(attack_scored) %>% 
  top_n(5) %>%
  arrange(n) %>% 
  ggplot(aes(reorder(team,n),n))+
  geom_col(fill = "#FAAB18", show.legend = FALSE) +
  geom_text(aes(label = n), col = "white", size = 10,nudge_y = -6) +
  coord_flip() +
  theme_fivethirtyeight (base_size = 15) +
  labs(title ="Highest Scoring Teams",
       x = "",
       y = "")
```

### **Sky Sports & BT Sports Payout**

```{r}
epl %>% 
  group_by(team) %>% 
  tally(finance_tv_revenue) %>% 
  top_n(5) %>%
  arrange(n) %>% 
  ggplot(aes(reorder(team,n),n))+
  geom_col(fill = "#FAAB18", show.legend = FALSE) +
  #geom_text(aes(label = round(n/1000000,1)), col = "black", size = 10) +
  coord_flip() +
  theme_fivethirtyeight (base_size = 15) +
  labs(title ="Top TV Revenue Earners(£)",
       x = "",
       y = "")+
  scale_y_continuous(labels = comma)
```

Net Spend
========================================

### Net Spend

```{r}
 NetSpendBar<- epl_mod %>%  
  ggplot(aes(period,amount,fill = amount))+
  geom_col()+
scale_x_discrete(expand = c(0,0),labels = c("2010","2011","2012","2013","2014",
                                            "2015","2016","2017","2018","2019"))+
scale_fill_continuous(high = "green",low = "red")+
  labs(title = "Club Transfer Spend 2010 - 2019",
       x = "End of Season",
       y = "Amount in Millions (£)") +
  geom_hline(yintercept=0, size=1, col = "grey")+
  coord_flip()+
   theme(legend.position="none",
   panel.background = element_rect(fill = '#4682B4'),
   plot.background=element_rect(fill="#4682B4"),    ##4B6A94
   panel.grid.minor = element_blank(),
   #panel.grid.minor = element_line(colour = "white"),
   panel.grid.major = element_line(colour = "white"),
   panel.grid.major.y = element_blank(),
   #panel.grid.major.x = element_blank(),
   #panel.grid.minor = element_blank(),
   plot.title=element_text(size=15, 
   face="bold",colour = "white",hjust=0.5,lineheight=1.2),  # title
  plot.subtitle=element_text(size=13, colour = "black",face="bold"),  # subtitle
  plot.caption=element_text(size=13,colour = "white"),  # caption
  axis.title.x=element_text(size=13,colour = "white", face = "bold",),  # X axis title
  axis.title.y=element_text(size=13,colour = "white", face = "bold"),  # Y axis title
  axis.text.x=element_text(size=10,colour = "white", face = "bold"),  # X axis text
  axis.text.y=element_text(size=10,colour="white",hjust=1, face="bold"),
  axis.line.x = element_line(colour = "#FFFFFF", size=1, lineend = "butt"),
  axis.line.y = element_line(colour = "#FFFFFF", size=1),
  axis.ticks.x = element_line(colour = "#FFFFFF"),
  axis.ticks.y = element_line(colour = "#FFFFFF"))+
  facet_wrap(.~team)
NetSpendBar
```

Data Table
========================================

```{r}
datatable(epl,
          caption = "Premier League 2018 2019",
          rownames = T,
          filter = "top",
          options = list(pageLength = 25))
```