I hereby claim:
-
I am jonocarroll on github.
-
I am jonocarroll (https://keybase.io/jonocarroll) on keybase.
-
I have a public key ASBY3mLwKW3JR6kHm4Pb0RN9EJIp6G3X8nD9SJMhylURGAo
I hereby claim:
I am jonocarroll on github.
I am jonocarroll (https://keybase.io/jonocarroll) on keybase.
I have a public key ASBY3mLwKW3JR6kHm4Pb0RN9EJIp6G3X8nD9SJMhylURGAo
| ## create a copy of mtcars | |
| m <- mtcars | |
| ## set every other value of cyl to NA | |
| m$cyl <- m$cyl[c(TRUE, NA)] | |
| ## show a table of cyl vs am | |
| table(m$cyl, m$am, useNA = "always") | |
| # 0 1 <NA> | |
| # 4 2 3 0 |
| library(threed) | |
| library(dplyr) | |
| library(gganimate) | |
| library(ggplot2) | |
| angles <- tail(seq(0, pi/2, length.out = 15), -1) | |
| camera_to_world <- threed::look_at_matrix(eye = c(1.5, 1.75, 4), at = c(0, 0, 0)) | |
| objlist <- vector("list", length(angles)) |
| library(rvest) | |
| ## GDP per capita, top 11 countries | |
| n_countries <- 11 | |
| url <- "https://en.wikipedia.org/wiki/List_of_countries_by_GDP_(nominal)_per_capita" | |
| html <- read_html(url) | |
| gdppc <- html_table(html_nodes(html, "table")[3])[[1]][1:n_countries, ] | |
| ## clean up; remove non-ASCII and perform type conversions | |
| gdppc$Country <- gsub("Â ", "", gdppc$Country) |
| ## flags borrowed from | |
| ## http://flagpedia.net/ | |
| ## use LaTeX tikzDevice to render images as x-axis labels | |
| ## based on baptiste: https://gist.github.com/baptiste/9505ff4f54b31d1d7149e435faf295f9 | |
| library(tikzDevice) | |
| library(ggplot2) | |
| options(tikzLatexPackages = c(getOption("tikzLatexPackages"), "\\usepackage{graphicx}\n")) |
| --- | |
| title: "Test Animation in PDF" | |
| author: "Jonathan Carroll" | |
| date: "09/10/2018" | |
| output: pdf_document | |
| header-includes: | |
| - \usepackage[final,autoplay]{animate} | |
| --- | |
| ```{r setup, include=FALSE} |
| `+` <- function(e1, e2) { | |
| ## unary | |
| if (missing(e2)) return(e1) | |
| if (!is.na(suppressWarnings(as.numeric(e1))) & !is.na(suppressWarnings(as.numeric(e2)))) { | |
| ## both arguments numeric-like but characters | |
| return(base::`+`(as.numeric(e1), as.numeric(e2))) | |
| } else if ((is.character(e1) & is.na(suppressWarnings(as.numeric(e1)))) | | |
| (is.character(e2) & is.na(suppressWarnings(as.numeric(e2))))) { | |
| ## at least one true character | |
| return(paste0(e1, e2)) |
| # modified from https://gist.github.com/sa-lee/c271b47d8065412d3d42c1ad8e63048d | |
| library(datasauRus) | |
| library(gganimate) | |
| library(magrittr) | |
| p <- datasaurus_dozen %>% | |
| ggplot() + | |
| geom_point(aes(x = x, y = y), col = "steelblue") + | |
| theme(legend.position = 'none', | |
| aspect.ratio = 1, |
| gistr |
| gistr |