Maverik95

Posted on

# ANALYSING THE EPL 2019/2020 SEASON USING R'S TIDYVERSE

#### First things first, we need to import our Epl dataset. The data is in csv form so we will be using read.csv to import it

``````prem_leag <- read.csv("Epl_Dataset_19_20.csv")
``````

#### Import the tidyverse library

``````library(tidyverse)
``````

#### If you dont have the tidyverse library. You can install it by using:

``````install.packages('tidyverse')
``````

#### We are aware of the fact that Liverpool is leading the charts and teams such as Norwich are battling relegation.But lets see if the number of goals scored by these teams correlate with their positions

``````prem_leag %>%
select(id,Team, TGS, TP)%>%
ggplot(aes(x=Team, y=TGS, fill=TP))+
theme(axis.text.x = element_text(angle = 90, hjust = 1))+
geom_bar(stat = 'identity')
``````

#### Let's check the teams that have the lowest number of points and see where this low scoring teams rank

``````prem_leag %>%
select(id, Team)%>%
arrange(desc(id))%>%
``````

#### Let's check the number of goals conceded by the Epl teams and see how they relate with their position on the table

``````prem_leag %>%
select(id, Team, TGA)%>%
ggplot(aes(x=Team, y=TGA, fill=id))+
theme(axis.text.x = element_text(angle=90, hjust=1))+
geom_bar(stat="identity")
``````

#### Teams like Aston Villa, Norwich and Southampton conceded the most goals. But from the shades where Norwich and Aston Villa have light colors showing, they are at the bottom of the log. Southampton is not as light. This signifies that Southampton is higher up the log.But which factor makes Southampton higher up even when they have conceded the 2nd number of goals?

``````prem_leag %>%
select(Team, TGS)%>%
filter(Team=="Aston Villa"|Team=="Norwich"|Team=="Southampton")%>%
ggplot(aes(x=Team, y=TGS))+
geom_bar(stat = "identity")
``````

#### We can fill colors based on the different teams using the fill variable.

``````prem_leag %>%
select(Team, TGS)%>%
filter(Team=="Aston Villa"|Team=="Norwich"|Team=="Southampton")%>%
ggplot(aes(x=Team, y=TGS, fill=Team))+
geom_bar(stat = "identity")
``````

#### Lets take a closer look at the top 8 teams and look at how the goals they have conceded has affected their position on the Epl table.

``````prem_leag %>%
select(id, Team, TGA)%>%
arrange(id)%>%
ggplot(aes(reorder(Team, TGA), TGA, fill= id))+
theme(axis.text.x = element_text(angle = 90, hjust = 1))+
labs(x='Team', y='Total Goals Against')+
geom_bar(stat="identity")
``````

#### Let's now analyse the teams with a strong home form. And also the teams with a strong goalscoring home form

``````prem_leag%>%
select(id, Team, HP, HGS)%>%
filter(id<=10)%>%
ggplot(aes(reorder(Team,-HP), HP, fill=HGS))+
labs(x="Team", y="Total Home Points")+
theme(axis.text.x=element_text(angle=90, hjust = 1))+
geom_bar(stat="identity")
``````

#### Lets now analyse away performances by these teams

``````prem_leag %>%
select(id, Team, AMP, AP, TP)%>%
filter(id<=10)%>%
mutate(APP = round((AP/(AMP*3)*100), 2))%>%
ggplot(aes(reorder(Team, -APP), APP))+
labs(x="Team", y="% of Away points")+
theme(axis.text.x = element_text(angle = 90, hjust = 1))+
geom_bar(stat = "identity")
``````

#### Now we will look to determine whether the number of passes made by teams correlated with positions on the table.

``````prem_leag%>%
select(id, Team, TPS)%>%
arrange(desc(TPS))%>%
ggplot(aes(reorder(Team,-TPS), TPS, fill=id))+
labs(x="Team", y="Total Passes ")+
theme(axis.text.x=element_text(angle=90, hjust = 1))+
geom_bar(stat="identity")
``````

#### Finally, we are going to do an analysis on shots(on goal) to goal ratio

``````prem_leag %>%
select(id, Team, TSGR)%>%
filter(id<=10)%>%
ggplot(aes(reorder(Team, -TSGR), TSGR, fill=Team))+
labs(x="Teams", y="Shots to Goal Ratio", title = "Shots to goal ratio
of the top ten teams")+
theme(axis.text.x = element_text(angle = 90, hjust=1))+
geom_bar(stat = "identity")
``````

#### We once again filtered for the top 10 teams on the EPL table. Then we label our chart using the labs() function.

Dave Parr

Great work :)

Maverik95

Thank you David

David Rock

Beautiful
I love this
Can it give predictions

Maverik95

No it cant
But I could work on something like that