class: center, middle, inverse, title-slide # Easing Street ## a gganimate easing gallery ###
Gina Reynolds, April 2019 ###
--- # Introduction [gganimate](https://gganimate.com/index.html) is cool. But, it does take a while to compile each plot because each animation is composed of a lot of frames. Given that you have a lot of options too, it may take some patience to iterate to the perfect plot. There are a particularly lot of easing options, and easing can give your animated plots very different character --- some of the options are playfulness, some matter-of-fact, some dramatic! This book provides examples of the gganimate easing options. The example is moving from data plotted in one dimension to the same data represented in a histogram. Basically, histograms are solving an overplotting problem --- when there aren't a lot of observations, we show the distribution in just one dimension, but when there are a lot, adding another dimension helps avoid overplotting. I'm liking "elastic-in-out" easing for this application. For now, I'm just looking at ease-in-ease-out, but maybe I'll extend the project to ease-in only and ease-out only. More intuition on easing and side side-by-side comparison of easing functions, another useful resource is [easing.net](https://easings.net/en). Many thanks are due to the gganimate principal authors Thomas Lin Pedersen and David Robinson for making this awesome package available. --- # Easing options There are some options, quoting exactly from [https://gganimate.com/reference/ease_aes.html](https://gganimate.com/reference/ease_aes.html): - quadratic - Models a power-of-2 function - cubic - Models a power-of-3 function - quartic - Models a power-of-4 function - quintic - Models a power-of-5 function - sine - Models a sine function - circular - Models a pi/2 circle arc - exponential - Models an exponential function - elastic - Models an elastic release of energy - back - Models a pullback and release - bounce - Models the bouncing of a ball And when it is applied: - in - out - in and out --- # A gganimate plot Here is code to generate one of the animated plots to come. The highlighted line is where the easing decision is made. In the animations that follow, all is identical to this code, except for the easing piece. ```r ggplot(start_and_end_points) + aes(x = lifeExp) + aes(y = hight_in_hist) + geom_rect(data = start_and_end_rectangle, aes(xmin = break_low, xmax = break_low + by, ymin = 0, ymax = total_height, x = NULL, y = NULL)) + geom_vline(xintercept = break_low, alpha = .3) + geom_hline(yintercept = seq(1, max(end_points$hight_in_hist) + 2, by = 1), alpha = .4, color = "magenta") + geom_point(alpha = .6, col = "steelblue", size = 4) + geom_segment(alpha = .3, col = "steelblue", aes(x = break_low, xend = break_low + by, yend = hight_in_hist)) + gganimate::transition_time(time) + scale_y_continuous(breaks = seq(0, max(end_points$hight_in_hist) + 2, by = 1)) + labs(y = "Count", x = "Life Expectency") + * ease_aes("quadratic-in-out") ``` --- # quadratic-in-out <img src="easing_examples_files/figure-html/unnamed-chunk-3-1.gif" width="100%" /> --- # exponential-in-out <img src="easing_examples_files/figure-html/unnamed-chunk-4-1.gif" width="100%" /> --- # elastic-in-out <img src="easing_examples_files/figure-html/unnamed-chunk-5-1.gif" width="100%" /> --- # back-in-out <img src="easing_examples_files/figure-html/unnamed-chunk-6-1.gif" width="100%" /> --- # bounce-in-out <img src="easing_examples_files/figure-html/unnamed-chunk-7-1.gif" width="100%" /> --- # circular-in-out <img src="easing_examples_files/figure-html/unnamed-chunk-8-1.gif" width="100%" /> --- # cubic-in-out <img src="easing_examples_files/figure-html/unnamed-chunk-9-1.gif" width="100%" /> --- # quartic-in-out <img src="easing_examples_files/figure-html/unnamed-chunk-10-1.gif" width="100%" /> --- # quintic-in-out <img src="easing_examples_files/figure-html/unnamed-chunk-11-1.gif" width="100%" /> --- # sine-in-out <img src="easing_examples_files/figure-html/unnamed-chunk-12-1.gif" width="100%" /> <style type="text/css"> .remark-code{line-height: 1.5; font-size: 90%} </style>