Visualizing Euro 2012: First Group Games
[This article was first published on DiffusePrioR » R, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.
Now that every team has played a match it will be interesting to see how this has affected the (inverse) odds of victory. Since the plot in my last post was a bit ‘busy’, I have decided to use the facet_wrap function in gglplot2 to stratify by group.
Also, re-producing the ‘busy’ plot from the last post yields the following.
Germany, despite not playing well, has gained, while the Netherlands, despite playing quite well, have declined. These two countries will play each other in the next round, so it will be interesting to see how a victory for the Netherlands would change these graphics.
Data and code:
# after loading data as object called eur n <- dim(eur)[1] eur <- t(eur[1:n,]) dat <- NULL for(i in 1:n){dat <- data.frame(rbind(dat,cbind(eur[-1,i],names(eur[-1,i]),i)))} dat$V1 <- 1/as.numeric(as.character(dat$V1)) dat$V3 <- as.character(dat$V2) dat$V3[dat$i!=n] <- c("") dat$group <- ifelse(dat$V2 %in% c("RUS","GRE","POL","CZE"),"Group.A","Group.D") dat$group <- ifelse(dat$V2 %in% c("GER","NED","POR","DEN"),"Group.B",dat$group) dat$group <- ifelse(dat$V2 %in% c("IRL","CRO","ITA","ESP"),"Group.C",dat$group) dat$i <- as.numeric(as.character(dat$i)) ggplot(dat, aes(x=i, y=V1, colour = V2, group=V2, label=V3)) + geom_line(size=0.8) + geom_point(size=4, shape=21, fill="white") + #theme_bw() + geom_text(hjust=-0.3, vjust=0) + scale_x_continuous('Day',limits=c(1,(n+0.4)),breaks=1:n) + scale_y_continuous('1/Odds') + theme_bw() + opts(title = expression("Euro 2012, Inverse Odds of Victory"), legend.position=c(80,80)) ggplot(dat, aes(x=i, y=V1, colour = V2, group=V2, label=V3)) + geom_line(size=0.8) + geom_point(size=4, shape=21, fill="white") + #theme_bw() + geom_text(hjust=-0.3, vjust=0.4) + scale_x_continuous('Day',limits=c(1,(n+0.8)),breaks=1:n) + scale_y_continuous('1/Odds') + facet_wrap( ~ group, ncol = 2, scales="free_y") + theme_bw() + opts(title = expression("Euro 2012, Inverse Odds of Victory"), legend.position=c(80,80))
To leave a comment for the author, please follow the link and comment on their blog: DiffusePrioR » R.
R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.