Skip to main content

Posts

Showing posts from January, 2018

[How-To] How to plot a chart on top of a background image in ggplot2

This post is an instructional one on how to plot a chart on top of a background image in ggplot2 and R. The motivation for plotting on a background may just be a design choice or it may serve the purpose of supporting the message of the chart. I will show how i create my previous post's chart showing the location of successful free kicks on a football pitch. Below code creates a 10x10 matrix with normally distributed doubles, which we will use as dummy data so you can easily replicate the results. N <- 10 M <- 10 data <- matrix(rnorm(N*M,mean=0,sd=1), N, M) We can convert this into a data frame and plot the initial data. library(ggplot2) df <- as.data.frame(as.table(data)) ggplot(df, aes(Var2, Var1)) + geom_tile(aes(fill = Freq)) + scale_fill_gradient(low = "white", high = "tomato") Next we need a background image which you can import with the jpeg package. In my case this is a picture of half a football pitch. library(jpeg)

Don't give one away there! Over 24,000 free kicks analyzed

Everybody knows the feeling: your team gives away a last-minute free kick at the edge of the box. A goal could cost you points or even worse: extra time. How likely is it really to score a direct free kick? I have looked through over 24,000 free kicks across the top European leagues and competitions to show you the spots a free kick is most promising and what the overall conversion rate is, i.e. how often do you actually score from such an opportunity. To make this data more insightful I have split the pitch (or better half a pitch) into 100 equal sized boxes. If a free kick is taken inside on of these boxes I group the outcome together. Below you see a heat map plotted on top of a half pitch. The boxes with the deepest red colour have the highest conversion rates. About half of the pitch remains green. For the 18 yard box the reason is obvious: there are no direct free kicks possible inside the box. On other parts of the pitch players don't usually opt for the direct free ki

Revolving Doors

After sacking Markus Gisdol this morning, Hamburg is going to appoint their 15th manager since the season 09/10. They are not the only team with revolving doors: Palermo has churned through 25 managers in the same time period, averaging almost 3 managers a season.