Skip to content

Instantly share code, notes, and snippets.

Avatar
👨‍💻
#rstats-ing all the things

Andrew Heiss andrewheiss

👨‍💻
#rstats-ing all the things
View GitHub Profile
View environment-talk.md

The earth is full of the goodness of the Lord

Given in the Berkeley Lake ward, 2022-08-14

When we lived in North Carolina, our house was on the outskirts of Durham, near one of the final intersections before the end of the city and county limits and the start of fairly open nature, with rivers and wilderness and hiking. When we lived in Utah, the mountains loomed over the valley and we were minutes away from hiking up mountains or through canyons.

When we were looking for houses here in Atlanta, right before we decided to buy our house in Peachtree Corners, we drove around the area to get a feel for the city. I work in downtown Atlanta at Georgia State University, so I knew that Atlanta was densely populated. But as we drove around out here in the suburbs, I figured we were on the very far outskirts of the city, close to nature. We drove up Peachtree Parkway/Medlock Bridge Road and crossed the Chattahoochee River and I was convinced that we had reached the end of Atlanta and that beyond that was open

View ggiraph-clickable-map.R
library(tidyverse)
library(sf)
library(tigris)
library(ggiraph)
library(glue)
# Get map data from the Census
state_shapes <- states(cb = TRUE) %>%
# Make this column a number
View map-with-info-labels.R
library(tidyverse)
library(sf)
library(tigris)
library(plotly)
library(glue)
state_shapes <- states() %>%
# Make this column a number
mutate(GEOID = as.numeric(GEOID)) %>%
# Only keep state IDs less than 60 to get rid of Guam, etc
View interactive-map-fun.R
library(tidyverse)
library(sf)
library(tigris)
library(plotly)
state_shapes <- states() %>%
# Make this column a number
mutate(GEOID = as.numeric(GEOID)) %>%
# Only keep state IDs less than 60 to get rid of Guam, etc
filter(GEOID < 60) %>%
View geom_ribbon_fill.md
library(tidyverse)

make_fancy_ribbon <- function(df, x, y, n = 1000) {
  interp <- approx(df[[x]], df[[y]], n = n)
  interp_df <- data.frame(interp$x, interp$y)
  colnames(interp_df) <- c(x, y)
  
  return(interp_df)
}
View geomtextpath_ggborderline.md
library(tidyverse)
library(gapminder)
library(geomtextpath)
library(ggborderline)
library(MetBrewer)

countries <- c("Norway", "Iraq", "Rwanda", "Afghanistan")
View ggborderline.md
library(tidyverse)
library(gapminder)
library(geomtextpath)
library(ggborderline)
library(MetBrewer)

countries <- c("Norway", "Iraq", "Rwanda", "Afghanistan")
View geomtextpath.md
library(tidyverse)
library(gapminder)
library(geomtextpath)
library(MetBrewer)

gapminder_lifeexp <- gapminder %>% 
  group_by(continent, year) %>% 
  summarize(avg_lifeexp = mean(lifeExp))
View combined-probabilities-simulation.md
library(tidyverse)
library(patchwork)

# Take a 20-question test; each question has an 80% chance of being correct
take_a_test <- function(...) {
  sample(c(TRUE, FALSE), 20, replace = TRUE, prob = c(0.8, 0.2))
}

set.seed(1234)
View pivoting-rank-extra-NAs.md
library(tidyverse)
library(gapminder)

gapminder_ranks_wrong <- gapminder %>% 
  filter(year %in% c(1952, 2007)) %>% 
  group_by(year) %>% 
  mutate(ranking = rank(-pop)) %>% 
  ungroup() %>%
  select(country, continent, year, pop, ranking) %>%