[英]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.