Skip to content

Instantly share code, notes, and snippets.

View seabbs's full-sized avatar
🏠
Working from home

Sam Abbott seabbs

🏠
Working from home
View GitHub Profile
#!/bin/bash
TODAY=`date +%Y-%m-%d`
TODAY_MD=`date +%B\ %d,\ %Y`
YEAR=`date +%Y`
PACKAGENAME=$1
##
## CHANGE ME!!!
@cpsievert
cpsievert / app.R
Last active October 23, 2018 03:36
Targeting views
library(plotly)
library(shiny)
# compute a correlation matrix
correlation <- round(cor(mtcars), 3)
nms <- names(mtcars)
ui <- fluidPage(
mainPanel(
plotlyOutput("heat"),
@seabbs
seabbs / spending_gap_normalised
Created June 7, 2019 10:37
Looking at normalised spending gap for global Tuberculosis funding
# Install and load the package --------------------------------------------
if(!require(pacman))install.packages("pacman")
pacman::p_load('dplyr', 'ggplot2', 'getTBinR')
pacman::p_load_gh('thomasp85/patchwork')
pacman::p_load_gh('bbc/bbplot')
# Look at available datasets\ ---------------------------------------------
available_datasets
## For password management
git config --global user.email "s.e.abbott12@gmail.com"
git config --global user.name "Sam Abbott"
git config --global credential.helper cache
git remote set-url origin https://github.com/USERNAME/REPOSITORY.git
# github settings
# developer settings
# create access token and copy
# git pull/push
@seabbs
seabbs / data-read-plus-munge
Last active July 24, 2019 08:57
Read in, munge and save a set of csvs + profiling information
# Get required packages - managed using pacman ---------------------------
# This installs packages if they are missing and otherwise loads them.
if (!require(pacman)) install.packages("pacman"); library(pacman)
p_load("tidyverse")
p_load("fs")
p_load("data.table")
p_load("lubridate")
p_load("purrr")
p_load("furrr")
library(future)
# //////////////////////////////////////////////////////////////////////////////
# Fresh R session takes around 40MB
pryr::mem_used()
#> Registered S3 method overwritten by 'pryr':
#> method from
#> print.bytes Rcpp
#> 35.7 MB
@jarvisc1
jarvisc1 / aa_plot_continent.r
Last active May 26, 2020 16:28
Plot range of Rt for continents
library(data.table)
library(ggplot2)
cases <- fread('_nowcasts/covid-global/national-summary/cases.csv')
df <- fread('_nowcasts/covid-global/national-summary/rt.csv')
continents <- fread('_nowcasts/covid-global/data/continents_cnty.csv')
cases <- cases[, .(country, date, cases = median)]
dfcont <- merge(df, continents, by.x = "country", by.y = "country_name", all.x = TRUE)
dfcont <- merge(dfcont, cases, by = c("country", "date"), all.x = TRUE)
@sharlagelfand
sharlagelfand / labeller
Created March 26, 2021 16:00
Demonstrating the usage of the argument `labeller = label_wrap_gen()` in the ggplot2 function facet_wrap()
library(ggplot2)
library(tibble)
df <- tribble(
~x, ~y, ~label,
1, 2, "A super long label oh god how am I going to deal with this",
2, 1, "A shorter one"
)
# Default - text is cut off
@sbfnk
sbfnk / get_utla_estimates.r
Created June 17, 2021 11:32
get all UTLA-level Rt estimates
library("gh")
library("vroom")
owner <- "epiforecasts"
repo <- "covid-rt-estimates"
path <- "subnational/united-kingdom-local/cases/summary/rt.csv"
rt_commits <-
gh("/repos/{owner}/{repo}/commits?path={path}",
owner = owner,
##' Get estimates shown at \url{https://epiforecasts.io/covid} for all times
##'
##' Nowcasts at \url{https://epiforecasts.covid} and the related github repository at
##' \url{https://github.com/epiforecasts/covid-rt-estimates} only cover the last 3
##' months. This function downloads all available estimates and applies a median
##' average to the provided quantiles to provide an estimate of a time series
##' covering all times available
##'
##' @param dataset character; data set corresponding to directories at
##' \url{https://github.com/epiforecasts/covid-rt-estimates}. Default is