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 presidential-births-by-year.R
library(tidyverse)
library(scales)
library(patchwork)
births_1994_1999 <- read_csv("https://raw.githubusercontent.com/fivethirtyeight/data/master/births/US_births_1994-2003_CDC_NCHS.csv") %>%
# Ignore anything after 2000
filter(year < 2000)
births_2000_2014 <- read_csv("https://raw.githubusercontent.com/fivethirtyeight/data/master/births/US_births_2000-2014_SSA.csv")
View presidential-births.R
library(tidyverse)
library(scales)
births_1994_1999 <- read_csv("https://raw.githubusercontent.com/fivethirtyeight/data/master/births/US_births_1994-2003_CDC_NCHS.csv") %>%
# Ignore anything after 2000
filter(year < 2000)
births_2000_2014 <- read_csv("https://raw.githubusercontent.com/fivethirtyeight/data/master/births/US_births_2000-2014_SSA.csv")
births_combined <- bind_rows(births_1994_1999, births_2000_2014)
View jitter_grid.md
library(tidyverse)

example_df <- tribble(
  ~Year, ~Category, ~Name,
  2015,  "A",       "1",
  2015,  "A",       "3",
  2015,  "A",       "5",
  2015,  "C",       "2",
  2015,  "C",       "4",
View tidy_race_data.md
library(tidyverse)

example <- tribble(
  ~Country, ~speed_100m, ~speed_200m, ~speed_400m, ~speed_800m, ~speed_1500m, ~speed_3000m, ~speed_marathon,
  "Argentina", 11.57, 22.94, 52.50, 2.05, 4.25, 9.19, 150.32,
  "Australia", 11.12, 22.23, 48.63, 1.98, 4.02, 8.63, 143.51,
  "Brazil", 11.17, 22.60, 50.62, 1.97, 4.17, 9.04, 147.41
)
View joining-tables.md
library(tidyverse)

set.seed(1234)

# Make a fake version of your dataset
possible_V4529s <- c("Completed rape", "Attempted rape", "Sex aslt w m aslt", 
                     "Sex aslt w s aslt", "At rob inj m asl", "Rob w inj maslt",
                     "Simp aslt w inj", "At mtr veh theft")
View logit-odds-props.md
library(tidyverse)
library(broom)
library(latex2exp)
library(patchwork)
set.seed(1234)

logit_df <- tibble(x = seq(-5, 5, length.out = 100)) %>% 
    mutate(p = 1/(1 + exp(-x))) %>% 
    mutate(y = rbinom(n(), size = 1, prob = p))
View horizontal_pointranges.md
library(tidyverse)
library(palmerpenguins)

avg_flipper <- penguins %>% 
  group_by(species) %>% 
  summarize(avg_flipper_length = mean(flipper_length_mm, na.rm = TRUE))
#> `summarise()` ungrouping output (override with `.groups` argument)

# Native horizontal geoms, but legend pointranges are still vertical
View clrs.md
# Colors via http://clrs.cc/
clrs <- list(
  navy = "#001F3F",
  blue = "#0074D9",
  aqua = "#7FDBFF",
  teal = "#39CCCC",
  olive = "#3D9970",
  green = "#2ECC40",
  lime = "#01FF70",
View tidygeocoder.R
library(tidyverse)
library(tidygeocoder)
library(sf)
library(albersusa)
places <- tribble(
~name, ~address,
"My empty GSU office", "14 Marietta Street NW, Atlanta, GA 30303",
"My old BYU office", "155 East 1230 North, Provo, UT 84604",
"My old Duke office", "201 Science Dr, Durham, NC 27708"
View broom_model_results.md
library(tidyverse)
library(broom)

cars <- cars %>% 
  mutate(speed.c = scale(speed, center = TRUE, scale = FALSE))

mod1 <- lm(dist ~ speed.c, data = cars)

tidy(mod1)
You can’t perform that action at this time.