Skip to content

Instantly share code, notes, and snippets.

Ben Marwick benmarwick

Block or report user

Report or block benmarwick

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
benmarwick / gist:cffb82fb6d9192354d495a2e0ded4e55
Last active Sep 13, 2019
Plot the population of Han Chinese in Taiwan from Wikipedia
View gist:cffb82fb6d9192354d495a2e0ded4e55
pop_han_in_tw <- tribble(
~year, ~population,
1684, 120000,
1764, 666210,
1782, 912920,
1811, 1944737,
benmarwick / inspect-rmd-diff-from-last-commit.R
Last active Aug 12, 2019
How to compare the current commit of an RMarkdown file with the most recent commit. Useful when we merge a pull request and want to check again how it has changed the document
View inspect-rmd-diff-from-last-commit.R
# reviewer pkg comes from
# this gets the sha of the previous commit
# result will open in a web browser
benmarwick / gist:82776e452d61cfbd44972ae6a4c23c21
Last active Jul 28, 2019
Stacked, overlapping time series plots on a common y-axis with ggplot2
View gist:82776e452d61cfbd44972ae6a4c23c21
# starting with code from
#' Create some data to plot
n <- 100
df <- data.frame(DateTime = seq(10, 20, length.out = 100),
View 001-get-pkg-data-from-cran-github-mirror.R
.token = "" # get one from
# get all pkgs on GitHub mirror of CRAN
n <- 5000 # 16125 #
cran_repos <- gh("/users/:username/repos",
username = "cran",
benmarwick / prentiss-1998-pca.R
Last active Aug 13, 2019
Exploring the PCA published by Prentiss (1998) to understand the usefulness of the Sullivan and Rozen debitage typology
View prentiss-1998-pca.R
# Exploring the PCA published by Prentiss (1998) to understand the
# usefulness of the Sullivan and Rozen debitage typology
# read in & tidy the data -----------------------------------------------
# got these data from table 7 (p. 644) of
# OCR'd using
prentiss <- readr::read_csv("tabula-Prentiss 1988.csv")
benmarwick / app.R
Last active May 1, 2019
Shiny app to get outlines of an object in an image using Canny edge detection
View app.R
library("EBImage") # >= 4.19.3
ui <- fluidPage(# Application title
titlePanel("Image outline, chords, and landmarks"),
benmarwick / gist:8cf22ecb74ac511f8ac1c70aef6038a7
Last active Mar 22, 2019
How to make diamond plots after Bergstrom and West (2018) "Why scatter plots suggest causality, and what we can do about it"
View gist:8cf22ecb74ac511f8ac1c70aef6038a7
# &
# they use Mathematica, boo! So let's make them with R
# starting with
p <- ggplot() +
geom_point(data = anscombe,
benmarwick / tidy-multiple-summaries.R
Last active Jul 1, 2019
Tidily summarizing multiple metric attributes of artefacts
View tidy-multiple-summaries.R
# Summarising multiple metric attributes of artefacts
p1 <- read_excel("data/riumailuoi.xlsx", sheet = 'phase1')
summary_stats_table <- function(x) {
x %>%
View 000-scrape-wikipedia.R
# list of lists
url <- ""
# Table of sites per country can be found at each of these pages
# probably the simplest entry point
# Africa
africa <- ""
# Americas
benmarwick / point_dist_to_polygon.Rmd
Created Feb 16, 2019
Two methods to get distance from point to enclosing polygon boundary
View point_dist_to_polygon.Rmd
title: 'C14 analysis: Coastal vs Inland'
output: html_document
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
Import and clean the data:
You can’t perform that action at this time.