Skip to main content

Posts

[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 We can convert this into a data frame and plot the initial data. library(ggplot2) df 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) img We can now combine these two parts and annotate the background image to the ggplot plot. We are using ggplot's annotation_custom and the rasterGrob function of the grid package. Essentially we are saying not to scale the imported...

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.

Three's a crowd

The Guardian published a great article today, highlighting the influence Antonio Conte had on the shift in tactics and starting formations during this and last year's Premier League seasons. Conte's Chelsea dominated the league with their 3-4-2-1 forcing other managers to revise their tactical plan. Chelsea was the first team in 53 years to win the league with a back three as their default formation. We can observe this shift when looking at the share of starting formations in Premier League matches with a back three. This share has increased significantly since Conte's arrival at Chelsea; both driven by his own choices and by other manager's trying to react. Back in the Serie A a back three is much more common and has at times been the favourite starting line-up:

Starting Formations Over Time - Premier League

While in relative little use prior to 2012, the 4-2-3-1 system has gained importance recently and has replaced 4-4-2 as the most important starting formation in the Premier League. This trend has reversed over the past two years as we see the 4-3-3 system gaining back importance and 3-4-2-1 becoming significant (leading Chelsea FC to their 2016 Premier League title).

Which Premier League team has the best spirit/luck? [Seasons 07/08-16/17]

Last week I have looked into late winners and equalizers by Premier League teams for the season 2016/17 to determine which team delivered the most last second punches. Arsenal came out on top with 9 net points won after the 85th minute which is equivalent to four late winners and an equalizer. Let's find out which team takes the lead over a longer history. My data set has information on goal timing since season 07/08 which gives us ten full seasons of last minute goals. To make sure the outcome is comparable and to not clutter the chart I have excluded teams that have not played at least five seasons in the highest league over that time frame. Tottenham takes this one home with just shy of 30 net points won after the 85th minute over the last ten seasons. Arsenal and Manchester City follow behind with 24 and 18 respectively. What stands out is that the Top 6 teams also take top spots in this ranking with the exceptions of Chelsea which is trailing behind a little. If this ...

Which Premier League team has the best spirit (or most luck depending on which side you are)?

You know the feeling. You are following the live ticker of your least favorite team (which also may be a few points above yours in the table). The finally seem to be dropping a few points against a team from the bottom. The match is already in injury time. You refresh the page faster than it can load. Then of course... they score a late winner. They always somehow do. Am I just making that up? Is it Fergie-time or Bayerndusel (for the Bundesliga followers)? Let's check which team has the most luck (or relentless spirit): Our analysis is based on a database similar to the below which shows us for every match in the season the end result and information on each goal. We will start by counting goals scored after minute 85 by each Premier League team during the season 2016/17. The threshold of minute 85 is arbitrary but think after that point in time I'll start talking about bloody luck and those again. Looking at the above plot, we can see that the two nor...