[英]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
[英]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?
所以在我关于足球的项目中,我想找到的是一支冠军球队如何取得胜利。 例如。 连续18场胜利帮助他们夺得冠军。 所以我想展示他们如何赢得连续比赛的趋势/模式。 所以我有一个 csv 文件,其中我有 W/D/L 列(赢/画/输),其中包含此模式的数据。 我正在使用 Python 做我的项目,但是使用 R 获得图像的人对此我一无所知。 因此,如果有人可以帮助我在 Python 或 R 中获得此图像,将不胜感激。
图片已附在下面。 谢谢你的帮助:)。
这是使用一些虚构数据在 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"))
这导致以下 plot:
如果您的数据未按球队降序排列,则需要将 testdata$Team 转换为联盟中 position 排序的因子,例如,请参阅此问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.