Using ggplot to explore #AFLW 2019 performances

I have been looking at the #AFLW 2019 data. I took the opportunity to include some CRAN packages I have not used before.

The data (two csv files) and my code are in a GitHub repository (link). My code is very basic and reflects my own thinking out loud as a I learn more about R.

In the past, I have tended to bookmark R suggestions and yet never manage to return to them as the list gets longer. My new practice is to create an R file to explore packages or code that strike me as interesting.

I used patchwork (link) and ggforce (link) in addition to ggrepel (link) to look at the data in the context of ggplot2 (link).

I was particularly interested in how patchwork helped me combine a range of images.

These work really well as PDF A4 pages and I thought they would be helpful summaries to stimulate conversation.

The three plot example above is:

Trying gganimate

The gganimate CRAN package “extends the grammar of graphics as implemented by ggplot2 to include the description of animation. It does this by providing a range of new grammar classes that can be added to the plot object in order to customise how it should change with time”. (Link)

I have been trying out the package’s functionality with some WBBL cricket data. I followed the very basic guidelines to produce four gifs.

I am keen to explore this package in more detail. Before I started I used the vis_dat package (link) to check the structure of my data:

My very basic code for the animations was:

ggplot(df, aes(Wicket, WTPartnership03, size=WTPartnership03)) +
scale_x_continuous(breaks=1:10)+
geom_point(alpha = 0.7, show.legend = FALSE, colour=”blue”) +
labs(title = ‘Wicket Winning Team Partnerships WBBL03: {frame_time}’,
x = ‘Wicket’, y = ‘Proportions of Total Runs Scored Per Wicket WBBL03’) +
transition_time(Wicket) +
ease_aes(‘linear’)


I used anim_save(“~/Documents”) to save the animation. This command saves the most recent animation as a gif to your specified directory. I had some problems with my x axis so tried scale_x_continuous(breaks=1:10) to resolve the issue and provide me with an integer count for the header in the gif.

Trying visdat

I found a link to the vis_dat package on CRAN. In my ongoing learning journey in and with R, I am fascinated by the resources that are shared openly … in this case by Nicholas Tierney (link).

vis_dat “helps you visualise a dataframe and “get a look at the data” by displaying the variable classes in a dataframe as a plot with vis_dat, and getting a brief look into missing data patterns using vis_miss.”

I tried it with a csv file of data from the 2019 Asian Cup football tournament. The data include cards given by referees for fouls and other behaviours (including dissent). vis_dat confirmed that the data that are incomplete are for a red card and a second yellow card. Not all cards are red cards or second yellow cards. In my data set I use NA to indicate if a card has NOT been awarded.

An example of the first card given at the tournament:

My data are available as a Google Sheet (link).

The image at the start of this post was produced with vis_dat. I used vis_miss() to visualise the missing data. The function “allows for missingness to be clustered and columns rearranged”.

I am delighted I found this package. I enjoyed reading Nicholas’s thank yous. This underscored for me what a remarkable community nourishes innovation in R.

Thank you to Ivan Hanigan who first commented this suggestion after I made a blog post about an initial prototype ggplot_missing, and Jenny Bryan, whose tweet got me thinking about vis_dat, and for her code contributions that removed a lot of errors.
Thank you to Hadley Wickham for suggesting the use of the internals of readr to make vis_guess work. Thank you to Miles McBain for his suggestions on how to improve vis_guess. This resulted in making it at least 2-3 times faster. Thanks to Carson Sievert for writing the code that combined plotly with visdat, and for Noam Ross for suggesting this in the first place. Thank you also to Earo Wang and Stuart Lee for their help in getting capturing expressions in vis_expect.
Finally thank you to rOpenSci and it’s amazing onboarding process, this process has made visdat a much better package, thanks to the editor Noam Ross (@noamross), and the reviewers Sean Hughes (@seaaan) and Mara Averick (@batpigandme).