A minimal flipbook

```{r, include = F} # This is the recommended set up for flipbooks # you might think about setting cache to TRUE as you gain practice --- building flipbooks from scratch can be time consuming knitr::opts_chunk$set(fig.width = 6, message = FALSE, warning = FALSE, comment = "", cache = F, fig.retina= 4) library(flipbookr) library(tidyverse) ``` # Hi! -- This 'minimal flipbook' template has a couple of classic examples to get you building your first flipbooks! -- flipbooks are code-movies. The frames of the movies are slides. Here we use the R package {xaringan} to create a remark.js slideshow. -- Slide breaks are indicated with `---` (be careful trailing white space is not allowed) -- flipbookr's `chunk_reveal()` disassembles a single code chunk and creates the "build" of multiple partial-code chunks on different slides (the --- is automatically generated for you too). -- We use `chunk_reveal()` it 'inline', not in a code chunk. -- Let's start! --- class: inverse, middle, center # First up: classic flipbook, using defaults to walk through code pipeline --- `r chunk_reveal("my_cars")` ```{r my_cars, include = FALSE} cars %>% filter(speed > 4) %>% ggplot() + aes(x = speed) + #BREAK aes(y = dist) + #BREAK geom_point( alpha = .8, color = "blue" ) + aes(size = speed) #BREAK ``` --- ```{r, echo=FALSE, include=FALSE} data(whiteside,package = 'MASS') ``` `r chunk_reveal("my_whiteside", break_type="user",title="### Whiteside by steps")` ```{r my_whiteside, include = FALSE} whiteside %>% #BREAK ggplot() + #BREAK aes(x = Temp) + #BREAK aes(y = Gas) + #BREAK geom_smooth( method="lm", formula = y ~ x, se=FALSE ) + #BREAK geom_point( alpha = .8, size = 5, ) + #BREAK ggtitle("Whiteside data: Simple Linear Regression") ``` --- ### What's wrong ? -- - Qualitative column `Insul` does not show up! - What about fitting one regression line per season? --- `r chunk_reveal("my_whiteside_group", break_type="user",title="### Whiteside by steps")` ```{r my_whiteside_group, include = FALSE} whiteside %>% ggplot() + aes(x = Temp, y = Gas) + #BREAK aes(group=Insul) + #BREAK geom_smooth( method="lm", formula = y ~ x, se=FALSE ) + #BREAK geom_point( alpha = .5, size = 2) + #BREAK ggtitle("Whiteside data: Simple Linear Regression per group") ``` --- --- `r chunk_reveal("my_whiteside_group_color", break_type="user",title="### Whiteside by steps")` ```{r my_whiteside_group_color, include = FALSE} whiteside %>% #BREAK ggplot() + #BREAK aes(x = Temp) + #BREAK aes(y = Gas) + #BREAK aes(group=Insul) + #BREAK aes(color=Insul, shape=Insul, linetype=Insul) + #BREAK geom_smooth( method="lm", formula = y ~ x, se=FALSE ) + #BREAK geom_point( alpha = .5, size = 2) + #BREAK ggtitle("Whiteside data: Simple Linear Regression per group") ``` --- class: inverse, center, middle # Next up: refer to same chunk, but use user defined breakpoints, and display output only --- `r chunk_reveal("my_cars", break_type = "user", display_type = "output", title = "### user defined break! using #BREAK message")` --- class: inverse, center, middle # Next up: cycle through different lines of code --- `r chunk_reveal("my_fill", break_type = "rotate", widths = c(1,1), title = "### cycle through lines of code marked #ROTATE")` ```{r my_fill, eval = F, echo = F} ggplot(data = cars) + aes(x = speed) + aes(y = dist) + geom_point(size = 8, shape = 21, alpha = .9, color = "snow") + aes(fill = speed) + scale_fill_viridis_c(option = "magma") + #ROTATE scale_fill_viridis_c(option = "cividis") + #ROTATE scale_fill_viridis_c(option = "plasma") #ROTATE ``` --- class: inverse, center, middle # Next up: look at multiple realizations of same code --- `r chunk_reveal("cars_multi", break_type = 5, title = "### see multiple realizations of code")` ```{r cars_multi, include = FALSE} cars %>% sample_frac(size = 1, replace = TRUE) %>% ggplot() + aes(x = speed) + aes(y = dist) + geom_count( alpha = .7, color = "blue", size = 4 ) + geom_smooth(method = lm, se = FALSE) + coord_cartesian(xlim = range(cars$speed), ylim = range(cars$dist)) + theme(legend.position = c(.9, .2)) ``` ```{css, eval = TRUE, echo = FALSE} .remark-code{line-height: 1.5; font-size: 80%} @media print { .has-continuation { display: block; } } code.r.hljs.remark-code{ position: relative; overflow-x: hidden; } code.r.hljs.remark-code:hover{ overflow-x:visible; width: 500px; border-style: solid; } ``` --- # Notes: - This minimal flipbook assumes you are online when you build and view. It is going to find the most recent remark.js info online. - xaringan/remark.js slideshows are not self contained, single file slide shows. Make sure you ship all the associated files that are created to display your flipbooks/slideshows. I like to push .html and associated files to github repository and use Github Pages to host for beyond local sharing. :-)