简体   繁体   English

Python 中是否有任何 plot 方法可以给我下图中的 plot? 如果没有,有人可以帮助在 R 中实现它吗?

[英]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.连续18场胜利帮助他们夺得冠军。 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.所以我有一个 csv 文件,其中我有 W/D/L 列(赢/画/输),其中包含此模式的数据。 I'm doing my project using Python but the person who obtained the image using R of which I have no idea about.我正在使用 Python 做我的项目,但是使用 R 获得图像的人对此我一无所知。 So if anyone could help me in obtaining this image in Python or R, it would be appreaciated.因此,如果有人可以帮助我在 Python 或 R 中获得此图像,将不胜感激。

The image has been attached below.图片已附在下面。 Thanks for any help:).谢谢你的帮助:)。

WDL pattern of teams团队的 WDL 模式

Here's one way to do it in R using some made up data:这是使用一些虚构数据在 R 中执行此操作的一种方法:

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:这导致以下 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.如果您的数据未按球队降序排列,则需要将 testdata$Team 转换为联盟中 position 排序的因子,例如,请参阅此问题

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 为什么下面的代码返回一个空列表。我不明白它的原因,所以如果有人可以帮助我,那会让我高兴 - Why is the code below return an empty list.I could not understand the reason of it so if someone can help me about that , that will make me happy 有人可以帮我优化下面的 python 代码吗,我在某些测试用例中遇到超时异常 - Can someone help me in optimising the below python code, I am getting timeout exception for some of the test cases 它什么也没给。 有人可以帮助我了解 python 中的字典、对象和类吗? - It doesn't give anthing. Can someone help me about dictionaries and objects and classes in python? python中是否有任何方法,例如r中的“ lag.plot1”? - Is there any method in python like `lag.plot1` in r? 有人可以帮我写代码吗? (Python) - Can someone help me with my code? (python) 有人可以帮我理解python中的循环吗 - Can someone help me understand this for loop in python 有人可以帮助我解决 FileNotFoundError python - someone can help me with FileNotFoundError python 有人可以帮助我进行Python的并行处理吗? - Can someone help me with parallel processing for Python? Python 不会让我 plot,有什么建议吗? - Python wont let me plot, any suggestion? 有人可以帮我处理我的 Python 代码吗? - Could someone please help me with my Python code?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM