Skip to content

Instantly share code, notes, and snippets.

View rmcelreath's full-sized avatar
🦔

Richard McElreath rmcelreath

🦔
View GitHub Profile
@rohit-gupta
rohit-gupta / CDC_High_School_YRBS_Plot.R
Last active November 16, 2018 15:54
CDC_High_School_YRBS_Plot.R
library(readr)
library(tidyr)
library(ggplot2)
CDC_YRBS_eversex <- read_delim("CDC_YRBS_eversex.tsv",
"\t", escape_double = FALSE, na = "N/A",
trim_ws = TRUE)
CDC_YRBS_eversex$Grade <- factor(CDC_YRBS_eversex$Grade, levels=c("9th","10th", "11th", "12th"))
@jonesor
jonesor / palettebuildr.R
Last active August 29, 2015 14:15
Extract colours from a JPG file to use as a (divergent) colour palette.
palettebuildr <- function(pathToJPEG = "logo.jpg", ncols = 3, dist.method = "euclidian", clust.method = "complete"){
require(jpeg)
#Read in the jpeg file
img <- readJPEG(pathToJPEG)
#Using the whole image is overkill, especially for large files.
#Therefore, create a grid from which extract the colors
xgrid <- ceiling(seq(1, dim(img)[1], length.out = 50))
ygrid <- ceiling(seq(1, dim(img)[2], length.out = 50))