ABSTRACT

Both plot_ly() and ggplotly() support key frame 1 animations through the frame argument/aesthetic. They also support an ids argument/aesthetic to ensure smooth transitions between objects with the same id (which helps facilitate object constancy 2 ). Figure 14.1 recreates the famous gapminder animation of the evolution in the relationship between GDP per capita and life expectancy evolved over time (Bryan, 2015). The data is recorded on a yearly basis, so the year is assigned to frame, and each point in the scatterplot represents a country, so the country is assigned to ids, ensuring a smooth transition from year to year for a given country. Animation of the evolution in the relationship between GDP per capita and life expectancy in numerous countries. https://s3-euw1-ap-pe-df-pch-content-public-p.s3.eu-west-1.amazonaws.com/9780429447273/5aa76a70-2d8a-4f48-af74-4a299517eb99/content/fig14_1.tif" xmlns:xlink="https://www.w3.org/1999/xlink"/> data(gapminder, package = "gapminder") gg <- ggplot(gapminder, aes(gdpPercap, lifeExp, color = continent)) +   geom_point(aes(size = pop, frame = year, ids = country)) +   scale_x_log10() ggplotly(gg)