This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(ggraph) | |
library(tidygraph) | |
library(gganimate) | |
# Data from http://konect.uni-koblenz.de/networks/sociopatterns-infectious | |
infect <- read.table('out.sociopatterns-infectious', skip = 2, sep = ' ', stringsAsFactors = FALSE) | |
infect$V3 <- NULL | |
names(infect) <- c('from', 'to', 'time') | |
infect$time <- as.POSIXct(infect$time, origin = Sys.time() - as.numeric(Sys.time())) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(gapminder) | |
library(ggplot2) | |
library(gganimate) | |
p <- ggplot(gapminder, aes(gdpPercap, lifeExp, size = pop, colour = country)) + | |
geom_point(alpha = 0.7) + | |
scale_colour_manual(values = country_colors) + | |
scale_size(range = c(2, 12)) + | |
scale_x_log10() + | |
facet_wrap(~continent) + |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(sf) | |
library(ggplot2) | |
library(gganimate) | |
# Data from personal correspondance | |
# Collapse all dates to the same year | |
d$year <- format(d$date, '%Y') | |
d$stand_time <- as.POSIXct(paste0('2000-', format(d$date, '%m-%d %T'))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(ggplot2) | |
library(gganimate) | |
library(sf) | |
earth <- sf::st_as_sf(rnaturalearth::countries110) | |
views <- data.frame(rbind( | |
st_bbox(earth[earth$name == 'Denmark',]), | |
st_bbox(earth[earth$name == 'Australia',]) | |
)) | |
p <- ggplot() + | |
geom_sf(data = earth, fill = 'white') + |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(gganimate) # thomasp85/gganimate | |
library(cartogram) | |
library(geogrid) # Need github version jbaileyh/geogrid | |
library(rnaturalearth) | |
library(sf) | |
library(scico) | |
us <- ne_states('united states of america', returnclass = 'sf') | |
us <- us[!us$woe_name %in% c('Alaska', 'Hawaii'), ] | |
us <- st_transform(us, '+proj=eqdc +lat_0=39 +lon_0=-96 +lat_1=33 +lat_2=45 +x_0=0 +y_0=0 +datum=NAD83 +units=m +no_defs') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
st_close <- function(x) { | |
UseMethod('st_close') | |
} | |
st_close.sfg <- function(x) x | |
st_close.POLYGON <- function(x) { | |
if (st_is_empty(x)) return(x) | |
x[] <- lapply(x[], close_mat) | |
x[vapply(x[], nrow, integer(1)) > 3] | |
} | |
st_close.MULTIPOLYGON <- function(x) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
upper <- seq(0, pi, length.out = 181)[-181] | |
upper <-cbind(x = cos(upper), y = sin(upper)) | |
lower <- seq(pi, 2*pi, length.out = 181)[-181] | |
lower <- cbind(x = cos(lower), y = sin(lower)) | |
right <- seq(1.5*pi, 2.5*pi, length.out = 181)[-181] | |
right <- cbind(x = cos(right), y = sin(right)) | |
left <- seq(0.5*pi, 1.5*pi, length.out = 181)[-181] | |
left <- cbind(x = cos(left), y = sin(left)) | |
full <- cbind(x = cos(seq(0, 2*pi, length.out = 361)[-361]), | |
y = sin(seq(0, 2*pi, length.out = 361)[-361])) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(gganimate) | |
airq <- airquality | |
airq$Month <- format(ISOdate(2004,1:12,1),"%B")[airq$Month] | |
ggplot(airq, aes(Day, Temp, group = Month)) + | |
geom_line() + | |
geom_segment(aes(xend = 31, yend = Temp), linetype = 2, colour = 'grey') + | |
geom_point(size = 2) + | |
geom_text(aes(x = 31.1, label = Month), hjust = 0) + |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
title: "PDF Animation Test" | |
output: pdf_document | |
header-includes: | |
- \usepackage{animate} | |
--- | |
`gganimate` now supports animations inside PDF documents. This feature is only | |
viewable with Acrobat Reader, however. Remember to include | |
`\usepackage{animate}` in the preamble and set `fig.show='animate'` in the chunk |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
title: "gganimate cookbook code" | |
output: | |
html_document: | |
df_print: tibble | |
highlight: kate | |
css: gganimate_cookbook.css | |
--- | |
```{r setup} |