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
@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 / 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
/* 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 / styling.R
Created February 26, 2019 19:59
Single-quote styler
transformers <- styler::tidyverse_style()
transformers$token$fix_quotes <- function (pd_flat) {
str_const <- pd_flat$token == 'STR_CONST'
str_const_change <- grepl('^"(.*)"$', pd_flat$text[str_const])
raw_str <- sub('^"(.*)"$', '\\1', (pd_flat$text[str_const][str_const_change]))
raw_str <- gsub('(\\\\)?\'', '\\\\\'', raw_str)
raw_str <- gsub('\\\\"', '"', raw_str)
pd_flat$text[str_const][str_const_change] <- paste0('\'', raw_str, '\'')
pd_flat
}
@thomasp85
thomasp85 / gganimate_cookbook.rmd
Created January 29, 2019 11:58
Code for gganimate talk RStudio::conf 2019
---
title: "gganimate cookbook code"
output:
html_document:
df_print: tibble
highlight: kate
css: gganimate_cookbook.css
---
```{r setup}
@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
@thomasp85
thomasp85 / airq.R
Last active January 10, 2019 09:22
air quality
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) +
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]))
@thomasp85
thomasp85 / st_close.R
Last active July 15, 2018 01:34
An algorithm for closing erroneous polygons in sf
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) {
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')