Skip to content

Instantly share code, notes, and snippets.

@Kcnarf
Kcnarf / .block
Last active August 17, 2018 14:16
d3-voronoi-map usage
license: mit
@MilesMcBain
MilesMcBain / fools_five.R
Last active July 17, 2019 03:11
Fool's five
f <- function(...) {
function(df) with(df, ...)
}
footate <- function(.data, ...) {
dots <- list(...)
for (column in names(dots)) {
.data[[column]] <- dots[[column]](.data)
}
library(purrr)
library(dplyr)
row_count <- function(.x, .f){
.f <- as_mapper(.f)
reduce(.x, function(x, y) x + .f(y), .init = 0 )
}
data <- tribble(
~x, ~y, ~z,
library(gganimate) # thomasp85/gganimate
library(cartogram)
library(geogrid) # Need github version jbaileyh/geogrid
library(rnaturalearth)
library(sf)
library(scico)
us <- ne_states('united states of america', returnclass = 'sf')
us <- us[!us$woe_name %in% c('Alaska', 'Hawaii'), ]
us <- st_transform(us, '+proj=eqdc +lat_0=39 +lon_0=-96 +lat_1=33 +lat_2=45 +x_0=0 +y_0=0 +datum=NAD83 +units=m +no_defs')
@benmarwick
benmarwick / prentiss-1998-pca.R
Last active August 13, 2019 00:51
Exploring the PCA published by Prentiss (1998) to understand the usefulness of the Sullivan and Rozen debitage typology
#------------------------------------------------------
# Exploring the PCA published by Prentiss (1998) to understand the
# usefulness of the Sullivan and Rozen debitage typology
# read in & tidy the data -----------------------------------------------
library(tidyverse)
# got these data from table 7 (p. 644) of https://www.jstor.org/stable/2694112
# OCR'd using https://tabula.technology/
prentiss <- readr::read_csv("tabula-Prentiss 1988.csv")
@timelyportfolio
timelyportfolio / .block
Last active August 18, 2019 17:07 — forked from ramnathv/concaveman.R
Using Concaveman in R using V8 with beeswarm (fork)
license: mit
height: 100
library(slide)
library(dplyr, warn.conflicts = FALSE)
# be careful not to `library(tsibble)` as it will overwrite slide()
# quarterly data to start with
df <- tibble(
dates = seq(as.Date("2019-01-01"), as.Date("2021-01-01"), by = "1 quarter"),
yq = tsibble::yearquarter(dates)
)
@ikashnitsky
ikashnitsky / pal-safe-five-and-six.R
Last active January 17, 2020 13:43
Safe and efficient palette of five colors for R -- https://twitter.com/ikashnitsky/status/1200570023334559745
#===============================================================================
# 2019-11-30 -- gist
# Safe and efficient palette of five colors, print and colorblind friendly
# Ilya Kashnitsky, ilya.kashnitsky@gmail.com
#===============================================================================
library(magrittr)
library(prismatic)
# a function to test color paletes quickly
library(ggplot2)

# functions -----------------------------------------------

geom_liquid_area <- function(mapping = NULL, data = NULL, stat = "identity",
                             position = "stack", na.rm = FALSE, show.legend = NA,
                             inherit.aes = TRUE, ...) {
  layer(
    data = data,
@moodymudskipper
moodymudskipper / find classes
Last active November 6, 2020 04:42
find classes
# run from R GUI or you might have methods registered by IDE
# first method scrape S3 method tables, classes with no methods are not found
# second method parses code to find `class(foo) <- bar` lines and extracts string litterals if found, we could be a bit smarter there
# and find more, but that will still not be exhaustive, because we have things like `class(x) <- cl` and we'd have to check the code
# to see what `cl` is.
# we could also check if some objects are built with `structure`
# calls to `inherits` might also be checked
# The C code should also be inspected or we won't find for instance the "error" or "try-error" classes.