-2

So in my project that is on football(soccer), what I want to find is how a title winning team goes on a winning run. For eg. 18 wins in a row that helped them to the title. So I want to show the trend/pattern of how they're winnning the consecutive games. So I have a csv file in which i have columns of W/D/L ( win/draw/loss) which consist of the data for this pattern. I'm doing my project using Python but the person who obtained the image using R of which I have no idea about. So if anyone could help me in obtaining this image in Python or R, it would be appreaciated.

The image has been attached below. Thanks for any help :).

WDL pattern of teams

  • `R` user here: My first go at this would be using R with the ggplot2-package, take a look at the `facet_grid()`-function. Since you are not providing sample data in a readable R-format, I cannot provide an actual answer. – Wimpel Mar 19 '21 at 08:54
  • ok so the column would be W W W W W D L D D W W W W D D L L W something like this. So i do not know what readable R-format is. This is what i have in my csv file – Karthik Garimella Mar 19 '21 at 11:29

1 Answers1

0

Here's one way to do it in R using some made up data:

library(ggplot2)

#Some test data
set.seed(0)
testdata <- expand.grid(Team=c("Liverpool","Man U","Man City","Leicester", "Wolves"), Game=1:27)
testdata$Result <- sample(factor(c("Win","Draw","Loss"), levels=c("Win","Draw","Loss")), length(testdata[[1]]), 
                          replace=TRUE, prob=c(0.4,0.2,0.4))

#plot
ggplot(testdata, aes(x=Game, y=as.numeric(Result), fill=Result)) + facet_grid(Team~., switch="y") +
  geom_tile(colour="grey80", width=1,height=1) + scale_y_reverse(breaks=NULL) +
  ylab("") + scale_fill_manual(values=c(Win="green3",Draw="Orange",Loss="Red")) 

This results in the following plot:

enter image description here

If your data is not ordered with the teams in descending order, you'd need to convert testdata$Team to a factor ordered by the position in the league, see this question for example.

Miff
  • 7,486
  • 20
  • 20
  • So my data is ordered in the csv file and i need to read the file. So i will check on how to read the file in R on the net but how do I insert those W/D/L chars in the ggplot function? – Karthik Garimella Mar 19 '21 at 11:35