Tutorial-11
Interactive and Animated visualisations
Learning Objectives
Practice creating interactive visualisations
Practice creating animated visualisations
Preparation
Load the
gapminderpackage. We will be using this data.Also download the big-tech-stock-price.csv data from Moodle
Be sure to have installed the
plotlyandgganimatepackages
Motivation
Interactive and animated visualisations can improve the audience’s understanding of the data visualisation and its key messages.
Both interactivity and animation help show details on demand, reducing the overall cognitive load, and providing options for a more personalised view.
In this tutorial, we’ll practice creating interactive and animated visualisations.
Exercise 1
Load the plotly package
Turn the Apple stock price plot from last lecture into an interactive visualisation.
Change the tooltip, add new information or change the information shown.
Here is the code to reproduce the Apple stock price plot:
Exercise 2
Using the code provided fill in the missing blanks ??? to turn the above plot into an animation that shows how the gdpPercap changes through time.
library(gapminder)
library(ggplot2)
library(gganimate)
p <- ggplot(gapminder, aes(gdpPercap, lifeExp, size = pop, colour = country)) +
???(alpha = 0.7) +
scale_colour_manual(values = country_colors) +
scale_size(range = c(2, 12)) +
scale_x_???() +
???(~continent) +
theme(legend.position = 'none') +
labs(title = 'Year: {frame_time}', x = 'GDP per capita', y = 'life expectancy') +
???
pExercise 3
Enhance one of your visualisations from Assignment 1 using interactivity or animation.
Remember, be careful using these tools. Think about how interactivity and animation can be used to enhance your key messages! We want to avoid creating overly complex visualisations.
Finishing Up
Make sure you understand how to turn a ggplot object into an interactive graphic
Makes sure you understand the grammar of animation (transition_*())
Think about when is an appropriate time to create interactive and animated visualisations.
Lastly, we don’t need complex visualisations, sometimes, the simpler, the better.