How to create NBA shot charts in R

A while ago I found this fantastic post about NBA shot charts built in Python. Since my Python skills are quite basic I decided to reproduce such charts in R using data scraped from the internet and ggplot2.

Getting the Data

First we need the shot data from This blog post from Greg Reda does a great job explaining how to find the underlying API and extract data from a web app (in this case,

To get shot data for Stephen Curry we will use this url. The url shows the shots taken by Curry during the 2014-15 regular season in a JSON structure. Note also that Season, SeasonType and PlayerID are parameters in the url. Stephen Curry’s PlayerID is 201939.

Continue reading


How much does a yard cost in the NFL?

NFL teams spend a lot of money on their key players, specially running backs whose objective is to conquer the most amount of rushing yards as possible. But how to measure the return on investment in running backs? Are teams getting the return expected? How much does a rushing yard cost in the NFL?

I plotted rushing yards for each running back during the regular NFL season of 2014 and their respective average yearly salary (the total contracted amount divided by contract duration). The result shows an expected positive correlation: the more money spent on running back salaries the more rushing yards a team is expected to gain. Running backs perceived as “good” tend to get more money, right? However this is not true for every team when we look at the big picture. Continue reading

Principal Component Analysis and surfers performance

I had access to surfing data from, a site that collects data for fantasy surfing.  It contains average scores for 55 surfers in the 2014 World Surfing League under different conditions: wind, wave size, surf break, weather and more. Scores are continuous, varying from 0 to 20.

This is how the WSL scoring works in more detail: Continue reading

[VIDEO] The Math Behind Basketball

This is an interesting talk by Rajiv Maheswaran, Professor at the University of Southern California’s Computer Science Department.

He talks about capturing the massive amount of data that happens during a basketball game and using machine learning to understand complex events like “post ups” and “pick and rolls”. The machine can now see the game with the eyes of a coach.

Mind blown.

Who is the next Rugby League player to follow Jarryd Hayne to the NFL according to the data?

Former Australian Rugby League player Jarryd Hayne has become the story of the NFL pre season playing for the San Francisco 49ers. After 2 games, Hayne is second in the league in rushing yards (117) and leads the 49ers in average yards per punt return (21.6).

Are there other Rugby League players capable of causing the same impact in the NFL? If so, who are they? Who should NFL recruiters keep an eye on? Continue reading