Skip to content

Instantly share code, notes, and snippets.

View icj's full-sized avatar

Isaac Jenkins icj

View GitHub Profile

Keybase proof

I hereby claim:

  • I am icj on github.
  • I am icj (https://keybase.io/icj) on keybase.
  • I have a public key ASD0JNOC-vnkIM4CiceSI6psuD6kcxOeetVfFOPVTKuknwo

To claim this, I am signing this object:

@icj
icj / scrub-tableby.R
Created March 9, 2018 20:38
convert arsenal::tableby object to data frame that is more like summary output (for arsenal >v1.0)
scrub_tableby <- function(x) {
x <- summary(x)
df <- x$object
idx <- colnames(df) %nin% c("variable", "term", "label", "variable.type",
"test", "p.value")
format_all <- function(x, ...) vapply(x, format, NA_character_, ...)
df[idx] <- lapply(df[idx], format_all,
digits = x$control$digits,
format = "f", # the format="f" is not used for tbstat objects
@icj
icj / ggplot-kaplan-meier.R
Last active May 18, 2016 23:32
Function to plot Kaplan-Meier curves in ggplot. This also plots a "Number at risk" table below the survival curve.
.icj_survcomb <- function(x, rel_ht = c(4, 1), ...) {
# Function to stack the survival curve and the risk table
# Args
# x: the output of .icj_ggsurv()
# rel_ht: relative size of plot and table (see cowplot::plot_grid)
# ...: other arguments to cowplot::plot_grid()
#
# Value
# a ggplot object containing both the curve and the risk table
library(ggplot2)
@icj
icj / summary-fun.R
Last active August 18, 2016 21:36
Functions to create summary tables by a grouping variable.
summ_cont1 <- function(df, group, value,
header = NULL, digits = 1, na.rm = TRUE,
center = median, lower = min, upper = max,
total_col = "Total", overall_n = TRUE,
missing_group = "Missing",
missing_row = TRUE, missing_digits = 0,
lower_upper_divider = "-") {
library(dplyr)
library(tidyr)
library(ggplot2)
library(dplyr)
library(gridExtra)
library(jsonlite)
json_colors <- fromJSON("https://raw.githubusercontent.com/teamcolors/teamcolors.github.io/master/assets/data/team-colors.json")
team_colors <- bind_rows(
lapply(names(json_colors), function(league) {
names(json_colors[[league]]$color$hex) <- json_colors[[league]]$team
@icj
icj / over-under.R
Last active August 29, 2015 14:23
Creates an "Over-Under" plot in R using ggplot2. The plot looks like this http://rpubs.com/icj/overunder. There should be only one measurement at each x-value.
over_under <- function(df, x, y, cut_line, over_col = "red", under_col = "dodgerblue") {
# Creates an over-under plot
#
# Args
# df: data frame containing x and y axes variables
# x: name (character) or index of column containing x-axis variable
# y: name (character) or index of column containing y-axis variable
# cut_line: value that divides y into over and under regions
# over_col: color of over region
# under_col: color of under region