Analytics Log - Adil Khan

View Original

Create Animated Time Series Chart With gganimate + Google Analytics data in R Programming

So the blog has been quiet lately as I’ve been a bit tied up with GCP Data Engineering certification.

Having a bit of downtime, I wanted to delve into gganimate, having seen some visualizations on /r/dataisbeautiful. So here’s V1 of my chart using gganimate extension for ggplot2 to show a gif for time series data from Google Analytics channel data.

The data here is from this site and shows a spike from May ‘20 when the site started ranking in top 5 results for a few results.

The below full code is self explanatory for the most part but the core part of it creates a regular ggplot with geom_line() for a time series chart where x = date, y = sessions and uses a subset of the data where channelGrouping==”Organic Search”.

See this content in the original post

The main addition here is the transition_reveal(date) part that creates the animation. For this to work, you need to use the same field that you used in the x=date part of the ggplot. Once you have created the plot, you can save it with anim_save function.

This example is obviously a very basic one and there are quite beautiful ones. In this basic gif, you can see organic search spike around May ‘20 and has been consistently increasing as more content gets added to the site. Will be sharing more examples as I explore more features of this cool package.

See this content in the original post