Skip to content

Instantly share code, notes, and snippets.

Avatar

Matthew Lincoln mdlincoln

View GitHub Profile
View counts.csv
year nationality artists_strict
1550 Flemish 67
1550 Dutch 38
1551 Flemish 66
1551 Dutch 38
1552 Flemish 70
1552 Dutch 37
1553 Flemish 72
1553 Dutch 37
1554 Flemish 76
@mdlincoln
mdlincoln / yday_months.R
Created Sep 30, 2015
ggplot2 scale that displays the months of the year for data that has only the day of the year as an integer
View yday_months.R
yday_months_x <- scale_x_discrete(breaks = cumsum(c(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31)), labels = month.name)
@mdlincoln
mdlincoln / replace_each.R
Last active Oct 2, 2015
Replace values in a vector based on a named vector dictionary
View replace_each.R
#' Replace all matching values
#'
#' @param v Vector whose values are to be replaced
#' @param pairs A named vector of replacements
#' @export
#' @examples
#' x <- c("a", "a", "b", "c")
#' p <- c("a" = "alpha", "b" = "beta")
#' replace_each(x, p)
replace_each <- function(v, pairs) {
View pick-your-poison.R
msg <- function(..., prob = 0.25) {
if (runif(1) > prob) {
return(invisible())
}
messages <- c(...)
message(sample(messages, 1))
}
encourage <- function() {
@mdlincoln
mdlincoln / rotate_labels.R
Created Oct 31, 2015
Add this snippet to rotate x-axis labels by 45º in ggplot2
View rotate_labels.R
theme(axis.text.x = element_text(angle = 45, hjust = 1))
@mdlincoln
mdlincoln / mogrify.sh
Last active Nov 4, 2015
imageMagick convert any image to 300x300 DPI
View mogrify.sh
convert image -density 300 -units pixelsperinch outimage
View gist:f2b660851b14f3a455f9
<?
/////////////////////
// slack2html
// by @levelsio
/////////////////////
//
/////////////////////
// WHAT DOES THIS DO?
/////////////////////
//
View spaces.sh
# Friends don't let friends use
# two spaces after a period
sed -e 's/\. /. /g'
@mdlincoln
mdlincoln / europop.R
Last active Dec 18, 2015
Create an animated GIF of European urban population 1500-1800
View europop.R
library(devtools)
install_github("mdlincoln/europop")
library(europop)
library(dplyr)
library(rgdal)
library(ggplot2)
library(animation)
@mdlincoln
mdlincoln / range_simulation.R
Last active Dec 18, 2015
Animated GIF of simulation replications
View range_simulation.R
library(ggplot2)
library(dplyr)
library(animation)
load(url("http://matthewlincoln.net/assets/docs/sim_data.rda"))
saveGIF({
# We want one frame per replication
for(i in 1:max(bm_raw_sims$r)) {