Skip to content

Instantly share code, notes, and snippets.

View ajstewartlang's full-sized avatar

Andrew Stewart ajstewartlang

View GitHub Profile
@ajstewartlang
ajstewartlang / Tidy_Tuesday_May_21_2019
Created May 21, 2019 18:58
Tidy_Tuesday_May_21_2019
library(tidyverse)
library(janitor)
library(countrycode)
library(ggthemes)
waste_vs_gdp <- read_csv("https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2019/2019-05-21/per-capita-plastic-waste-vs-gdp-per-capita.csv")
waste_vs_gdp <- clean_names(waste_vs_gdp)
waste_vs_gdp$continent <- countrycode(sourcevar = waste_vs_gdp$entity,
@ajstewartlang
ajstewartlang / TidyTuesday_May21_2019
Last active May 21, 2019 18:59
TidyTuesday_May21_2019
library(tidyverse)
library(janitor)
library(countrycode)
library(ggthemes)
coast_vs_waste <- read_csv("https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2019/2019-05-21/coastal-population-vs-mismanaged-plastic.csv")
coast_vs_waste <- clean_names(coast_vs_waste)
coast_vs_waste$continent <- countrycode(sourcevar = coast_vs_waste$entity,
@ajstewartlang
ajstewartlang / epl_goal_contribution_matrix_18-19.r
Created May 20, 2019 14:38 — forked from Ryo-N7/epl_goal_contribution_matrix_18-19.r
Goal contribution matrix for Premier League 2018-2019
# pkgs
pacman::p_load(tidyverse, polite, scales, ggimage, ggforce,
rvest, glue, extrafont, ggrepel, magick)
loadfonts()
## add_logo function from Thomas Mock
add_logo <- function(plot_path, logo_path, logo_position, logo_scale = 10){
# Requires magick R Package https://github.com/ropensci/magick
library(tidyverse)
library(ggthemes)
library(tools)
library(gganimate)
library(ggimage)
full_trains <- read_csv("https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2019/2019-02-26/full_trains.csv")
p <- full_trains %>%
filter(service == "International" & year == 2017) %>%
@ajstewartlang
ajstewartlang / gist:b272364c0d5bfea5beb28ab3c0a66e15
Last active February 8, 2019 11:30
Simulation_script_10000_expts_cohens_d_.5
library(tidyverse)
library(broom)
library(Hmisc)
total_samples <- 10000
sample_size <- 128
participant <- rep(1:sample_size)
condition <- c(rep("fast", times = sample_size/2), rep("slow", times = sample_size/2))
all_data <- NULL
# From @nnstats on Twitter
# Imagine a hockey game where we know that Team A scores exactly 1 goal for sure and Team B takes 20 shots,
# each with a 5.5% chance of going in.
# Which team would you rather be?
# (nothing additional happens if you tie.)
library(tidyverse)
library(gganimate)
set.seed(1234)
# Note this uses the new version of gganimate by Thomas Lin Pedersen - @thomasp85
# it is not yet on CRAN so need to use devtools to install it
# devtools::install_github('thomasp85/gganimate')
library(gganimate) # New version of gganimate
library(tidyverse) # All praise the tidyverse
library(MASS) # Needed to sample from multivariate distribution
# Simulating multivariate data with specific covariance structure
# Use the mvrnorm() function from the MASS package
@ajstewartlang
ajstewartlang / gist:422fda3a81f0b7186f940176cbed70d9
Last active November 23, 2018 22:06
100000 samples with N=20 and no difference in population sampled from
library(tidyverse)
df <- NULL
set.seed(1111)
sample_size = 20
for (i in 1:100000) {
a <- rnorm(sample_size, mean = 10, sd = 2)
b <- rnorm(sample_size, mean = 10, sd = 2)
a <- cbind(a, rep ("A", sample_size), rep (i, sample_size))
## Written by Victor Yu (@VictorYuEpi)
## From https://pastebin.com/44c6GsDM
## playing around with some sports data - tracking the rank of athletes who completed the decathlon at the 2016 Rio Olympics #r #ggplot2 #gganimate #dataviz #Datavisualization
## install/load required packages ####
library(tidyverse)
library(RColorBrewer)
# Note, this uses the new version of gganimate by Thomas Lin Pedersen (@thomasp85) available from:
# https://github.com/thomasp85/gganimate
# Apologies for clunkiness of code below...
library(tidyverse)
library(gganimate)
data <- NULL
sample <- NULL
d <- NULL