Skip to content

Instantly share code, notes, and snippets.

View thomasp85's full-sized avatar
🎯
Something new and exciting

Thomas Lin Pedersen thomasp85

🎯
Something new and exciting
View GitHub Profile
/* rs-theme-name: Idle Eyes */
/* rs-theme-is-dark: TRUE */
.ace_gutter {
background: #3b3b3b;
color: rgb(153,153,153)
}
.ace_print-margin {
width: 1px;
background: #555;
}
@thomasp85
thomasp85 / gist:7a13df82e4d6947eac20bccc46fd061f
Created January 17, 2022 10:37
tzprofiles verification
I am attesting that this GitHub handle thomasp85 is linked to the Tezos account tz2Pkj2xWJovKKCsABjnr3NbyMVJTMBkpTvb for tzprofiles
sig:spsig1Ehb3tCbCP8GEJnhztgv2fSLaSk2HYnNfuC5TczfrPC6DsXfqGNpiSPxj6PjyK3Z4hrQgbegczwP6GEek8HirA9FzoRGK9
@thomasp85
thomasp85 / Histogram_animation.R
Last active December 17, 2021 11:20
An example of animating the build up of a histogram with dropping balls using tweenr, gganimate and ggplot2
library(tweenr) # Available on CRAN
library(ggforce) # Install from thomasp85/ggforce
library(gganimate) # Install from dgrtwo/gganimate
set.seed(2)
x <- sample(9,20, prob=c(1,2,3,4,5,4,3,2,1), replace=T)
df <- data.frame(x = x, y = 15)
dfs <- list(df)
for(i in seq_len(nrow(df))) {
dftemp <- tail(dfs, 1)
dftemp[[1]]$y[i] <- sum(dftemp[[1]]$x[seq_len(i)] == dftemp[[1]]$x[i])
@thomasp85
thomasp85 / celebration2020.Rmd
Last active November 25, 2021 19:49
Code and exercises for the celebRation2020 ggplot2 workshop
---
title: "ggplot2 examples and exercises"
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
This document contains all the code that is displayed during the workshop. The
@thomasp85
thomasp85 / script.R
Last active October 13, 2021 01:33
Temporal Network Viz
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()))
@thomasp85
thomasp85 / Denmark_to_Australia.R
Created June 11, 2018 11:23
Preview of view_zoom
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') +
@thomasp85
thomasp85 / animate.R
Created February 3, 2016 19:43
Animating graph over time
library(ggraph)
library(gganimate)
library(igraph)
# 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$timebins <- as.numeric(cut(infect$time, breaks = 100))
# We want that nice fading effect so we need to add extra data for the trailing
@thomasp85
thomasp85 / seal_tracking.R
Last active December 9, 2020 18:23
Animating Elephant Seal movement
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')))
library(magick)
library(reshape2)
library(dplyr)
library(tidygraph)
library(particles)
library(animation)
plot_fun <- function(sim) {
df <- as_tibble(sim)
plot(df$x, df$y, col = df$color, pch = '.', axes = FALSE, xlim = c(-100, 317), ylim = c(-268, 100), xlab = NA, ylab = NA)
@thomasp85
thomasp85 / pdf_animation.rmd
Created October 11, 2018 19:40
An example of embedding a gganimate animation in a pdf
---
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