Skip to content

Instantly share code, notes, and snippets.

Danielle Navarro djnavarro

View GitHub Profile
@djnavarro
djnavarro / transition_filter_bayes.R
Created Apr 17, 2019
gganimated version of ASCII Bayes
View transition_filter_bayes.R
library(tidyverse)
library(asciify)
library(gganimate)
p <- ascii_data("bayes.png") %>%
ascii_map(
alphabet = as.character(0:9),
rescale = .15) %>%
ascii_plot(charsize = 4)
@djnavarro
djnavarro / ggplot2_geomvector.R
Created Mar 30, 2019
Custom ggplot2 geom that plots a (subset of a) vector field
View ggplot2_geomvector.R
library(ggplot2)
library(dplyr)
library(tibble)
library(tidyr)
GeomVector <- ggproto("GeomVector", Geom,
required_aes = c("x", "y", "direction", "length"),
default_aes = aes(
@djnavarro
djnavarro / mouse_to_cat.R
Created Mar 29, 2019
Transform mouse emoji into cat emoji
View mouse_to_cat.R
library(tidyverse)
library(fontr)
library(emojifont)
library(ggpolypath)
library(transformr)
library(animation)
library(Cairo)
# create the base images from cat emoji and mouse emoji!
cat <- glyph_polygon(ch = emoji("cat"), family = "EmojiOne")
@djnavarro
djnavarro / a_very_bad_thing.R
Created Mar 25, 2019
Probably the most malicious thing I've done with R
View a_very_bad_thing.R
# operator that reverses the direction of assignment
# only if called from the global environment
`%>>%` <- function(x,y) {
if(sys.nframe() == 1) {
assign(deparse(substitute(y)), x, parent.frame())
} else {
assign(deparse(substitute(x)), y, parent.frame())
}
}
View make_map2.R
library(geojsonio)
library(here)
library(broom)
reload <- FALSE
if(reload) {
spdf <- geojson_read(
x = here("unsw_map", "worldgeo.json"),
what = "sp"
)
@djnavarro
djnavarro / bayes_rain_viewer.R
Created Mar 12, 2019
Uses the asciify package to draw the "Bayesian rain" animation in the RStudio viewer pane
View bayes_rain_viewer.R
#devtools::install_github("djnavarro/asciify")
library(asciify)
library(magrittr)
temporary <- function(file) {
temp_dir <- tempfile()
dir.create(temp_dir)
file.path(temp_dir, file)
}
@djnavarro
djnavarro / bb_gapminder.R
Created Feb 26, 2019
draws the gganimate gapminder example, using bbc style
View bb_gapminder.R
# packages
library(tidyverse)
library(gganimate)
library(gapminder)
library(scales)
# modified version of the bbc_style function
# adapted from: https://github.com/bbc/bbplot
bbc_style2 <- function(font = "Helvetica") {
theme(
View thank_you_solid_stars.R
library(showtext)
library(fontr)
library(tidyverse)
library(transformr)
library(animation)
library(ggpolypath)
# use showfont to load the font
font_add_google("Allura")
@djnavarro
djnavarro / lissajous_transform.R
Created Feb 4, 2019
Tween between two lissajous curves using transformr
View lissajous_transform.R
library(tidyverse)
library(transformr)
library(tweenr)
library(animation)
# function to generate lissajous curves in a format
# suitable for later tweening
lissajous <- function(a=1, b=1, w=1, d=pi/2, t0=-pi, t1=pi, n=100) {
tibble(
t = seq(t0, t1, length.out = n),
View isoband_lgbt.R
library(isoband)
library(magick)
library(sf)
library(tidyverse)
# Adapted from Claus Wilke's code
# https://github.com/clauswilke/isoband
sf_from_image <- function(image, nbands) {
image_gray <- image %>% image_quantize(colorspace = "gray")
image_raster <- as.raster(image_gray)
You can’t perform that action at this time.