require(tidyverse) install.packages("ggsci") require("ggsci") Full_EPL <- read.csv("FullEPL_Final.csv") ### Creating and Goals and Corners data frame ### Goals_and_Corners <- Full_EPL %>% select(Seasons, FTHomeGoals, FTAwayGoals, HomeCorners, AwayCorners) Goals_and_Corners_Summ <- aggregate(cbind(FTHomeGoals, FTAwayGoals ,HomeCorners, AwayCorners) ~ Seasons, Goals_and_Corners,sum) Goals_and_Corners_Summ %>% gather(key = "Home_Away", value = "Total_Goals", 2:3) %>% gather(key = "Home_Away", value = "Total Corners", 4:5) ### Creating new data frame from Summarized Goals and Corners ### ##Goals## Goals_Summ<- Goals_and_Corners_Summ %>% select(Seasons, FTHomeGoals, FTAwayGoals) %>% rename("Home" = FTHomeGoals, "Away" = FTAwayGoals) %>% gather(key = "Home_Away", value = "Total_Goals", 2:3) ##Corners## Corners_Summ<- Goals_and_Corners_Summ %>% select(Seasons, HomeCorners, AwayCorners) %>% rename("Home" = HomeCorners, "Away" = AwayCorners) %>% gather(key = "Home_Away", value = "Total_Corners", 2:3) Final_GoalsandCorners<- inner_join(Goals_Summ, Corners_Summ, by =c("Seasons", "Home_Away")) ### Creating Goals and Corners data frames using Gather function## ##Goals## Goals_Mean <- Goals_and_Corners%>% select(Seasons, FTHomeGoals, FTAwayGoals) %>% filter(Seasons =="1" |Seasons =="2" | Seasons =="3" | Seasons == "4" | Seasons =="5" | Seasons =="6" |Seasons =="7" | Seasons =="8" | Seasons == "9" | Seasons =="10")%>% group_by(Seasons) %>% summarise(Home = mean(FTHomeGoals), Away = mean(FTAwayGoals)) %>% gather(key = "Home_Away", value = "Average_Goals", 2:3) ##Corners## Corners_Mean <- Goals_and_Corners%>% select(Seasons, HomeCorners, AwayCorners) %>% filter(Seasons =="1" |Seasons =="2" | Seasons =="3" | Seasons == "4" | Seasons =="5" | Seasons =="6" |Seasons =="7" | Seasons =="8" | Seasons == "9" | Seasons =="10") %>% group_by(Seasons) %>% summarise(Home = mean(HomeCorners), Away = mean(AwayCorners)) %>% gather(key = "Home_Away", value = "Average_Corners", 2:3) ##Merging the data frames above ## GoalsandCorners_Mean<- inner_join(Goals_Mean, Corners_Mean, by =c("Seasons", "Home_Away")) ###Creating Bar Graphs### ##Goals## ggplot(data = Final_GoalsandCorners, mapping = aes(x = Seasons, y = Total_Goals , fill = Home_Away)) + geom_bar(stat = "identity", position = "dodge") + theme_bw() + scale_fill_discrete(name = "Home_Away") + scale_fill_npg() + ggtitle("Home and Away Goals per Season") + xlab("Seasons") + ylab("Total Goals") ##Corners## ggplot(data = Final_GoalsandCorners, mapping = aes(x = Seasons, y = Total_Corners , fill = Home_Away)) + geom_bar(stat = "identity", position = "dodge") + theme_bw() + scale_fill_discrete(name = "Home_Away") + scale_fill_jama() + ggtitle("Home and Away Corners per Season") + xlab("Seasons") + ylab("Total Corners") ##Mean## ##Average Goals per Season## ggplot(data = GoalsandCorners_Mean, mapping = aes(x = Seasons, y = Average_Goals , fill = Home_Away)) + geom_bar(stat = "identity", position = "dodge") + theme_bw() + scale_fill_jama(name = "Goal_Type") + ggtitle("Average Goals per season") + xlab("Seasons") + ylab("Average Goals") ##Average Corners per Season## ggplot(data = GoalsandCorners_Mean, mapping = aes(x = Seasons, y = Average_Corners , fill = Home_Away)) + geom_bar(stat = "identity", position = "dodge") + theme_bw() + scale_fill_npg(name = "Corner_Type") + ggtitle("Average Corners per season") + xlab("Seasons") + ylab("Average Corners") ##Trying a line graph## ggplot(data = GoalsandCorners_Mean, mapping = aes(x = Seasons, y = Average_Goals, group = Home_Away, col = Home_Away))+ geom_line(size = 4)+ ggtitle("Average Goals per season") + xlab("Seasons") + ylab("Average Goals")+ scale_fill_npg(name = "Home_Away", label = c("Home, Away")) ###Try line graph for total corners ???### ggplot(data = Final_GoalsandCorners, mapping = aes(x = Seasons, y = Total_Corners, group = Home_Away, col = Home_Away))+ geom_line(size = 4)+ ggtitle("Home and Away Corners per season") + xlab("Seasons") + ylab("Total Corners")+ scale_fill_npg(name = "Home_Away", label = c("Home, Away"))