Skip to content

Instantly share code, notes, and snippets.

Avatar

Jon Spring jonspring

View GitHub Profile
View SF COVID ICU animation 2021-12-31
library(httr); library(jsonlite)
library(tidyverse); library(lubridate)
library(gganimate); library(ggtext)
sf_hosp <- GET("https://data.sfgov.org/resource/nxjg-bhem.json?$limit=999999")
sf_hosp$content %>%
rawToChar %>%
fromJSON %>%
mutate(patientcount = as.numeric(patientcount),
View test_min.Rmd
---
title: "Test"
output: html_document
---
```{r setup, include=FALSE}
plot(mtcars$mpg)
```
View geom_lasso
# Inspired by Nadieh Bremer's lasso annotations here: https://twitter.com/NadiehBremer/status/1277622602735865856
# h/t Cedric Scherer: https://twitter.com/CedScherer/status/1278351840074240001
library(ggplot2); library(ggforce)
add_lasso_layer <- function(x1, x2, y) {
width = x2 - x1
space = width * 0.05
lasso_points = data.frame(
View teresita_fernandez_poisson
devtools::install_github("coolbutuseless/poissoned")
library(poissoned)
# v1
poisson_disc(ncols = 100, nrows = 50, cell_size = 10) %>%
as_tibble() %>%
arrange(y) %>%
mutate(rando = runif(n()),
visibility = case_when(
y >= 300 ~ (500-y)/200,
View grid_jittering
library(tidyverse)
example_df <- tribble(
~Year, ~Category, ~Name,
2015, "A", "1",
2015, "A", "3",
2015, "A", "5",
2015, "C", "2",
2015, "C", "4",
2016, "A", "1",
View Palmer Penguins umap animation
library(palmerpenguins)
library(tidyverse)
library(umap)
library(gganimate)
penguins_clean <- penguins %>% filter(!is.na(bill_length_mm), !is.na(sex))
penguinos <- function(neigh = 13) {
penguins_clean %>%
select(bill_length_mm:body_mass_g) %>%
scale() %>%
View ETS smoothing experiment
library(tidyverse)
library(fable)
library(gganimate)
set.seed(1)
df <- data.frame(x = 1:365,
y = cumsum(runif(365, min = -1)))
smoothy <- function(alpha1) {
df %>%
as_tsibble(index = x) %>%
View TidyTuesday 2019 #51: Dog namez, hooman namez
dog_moves <- readr::read_csv('https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2019/2019-12-17/dog_moves.csv')
dog_travel <- readr::read_csv('https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2019/2019-12-17/dog_travel.csv')
dog_descriptions <- readr::read_csv('https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2019/2019-12-17/dog_descriptions.csv')
library(tidyverse)
library(tidytext)
library(lubridate)
doggo_names <- dog_descriptions %>%
select(name, breed_primary, size, sex, size, contact_state, contact_zip, posted)
View starwars_pivot
# Some ideas to try out on the data from:
# https://gist.github.com/brooke-watson/ccf3d1b1f4449ab55a72f7835a52e599
# 0. Let's describe what type of data in each row
sw1_annotated <- starwars_garbage_data1 %>%
# Counting each new group of data
mutate(group = cumsum(v1 == "Character Name")) %>%
# Assign rows within each group
@jonspring
jonspring / Sunsets for pundit
Last active Dec 18, 2019
When the lights go down in the city.... Local sunset times
View Sunsets for pundit
# https://twitter.com/jonlovett/status/1191490424965218304
# What I'm curious about is how we're distributed inside of our time zones, because the further east you are inside of a time zone, the harder standard time hits. Boston's sunset is 4:34pm today. Brutal. Detroit's sunset, on the other side of the same time zone, is 5:22pm.
# I'm a big fan of Jon Lovett's podcasts, and I love trying new things in R, so it was Game On when I saw the tweet above. I googled around and combined a few data sources to get US counties' populations, coordinates, sunsets, and time zones. From those you can see who has it worst in the evenings when standard time kicks in.
# Curiously, big cities in the US tend to be on the east, "darker evening" end of their time zones.
####### Libraries #####