简体   繁体   中英

Is there any plot method in Python that can give me the plot in the image below? If not, could someone help in implementing it in R?

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

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:

在此处输入图像描述

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM