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,
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#=============================================================================== | |
# 2019-11-30 -- gist | |
# Safe and efficient palette of five colors, print and colorblind friendly | |
# Ilya Kashnitsky, [email protected] | |
#=============================================================================== | |
library(magrittr) | |
library(prismatic) | |
# a function to test color paletes quickly |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script> | |
(function() { | |
var divHTML = document.querySelectorAll(".details-open"); | |
divHTML.forEach(function (el) { | |
var preNodes = el.getElementsByTagName("pre"); | |
var outputNode = preNodes[1]; | |
outputNode.outerHTML = "<details open class='output'><summary>Output</summary>" + outputNode.outerHTML + "</details>"; | |
}) | |
})(); | |
(function() { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#=============================================================================== | |
# 2019-07-19-- ikashnitsky.github.io | |
# Reproduce Figure 2 from http://doi.org/10.1007/s10708-018-9953-5 | |
# Ilya Kashnitsky, [email protected] | |
#=============================================================================== | |
library(tidyverse) | |
library(hrbrthemes); import_roboto_condensed() | |
# the data as tribble |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
f <- function(...) { | |
function(df) with(df, ...) | |
} | |
footate <- function(.data, ...) { | |
dots <- list(...) | |
for (column in names(dots)) { | |
.data[[column]] <- dots[[column]](.data) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#------------------------------------------------------ | |
# 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") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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') |
Default ggplot2 aesthetics by geom.
geom | alpha | angle | colour | family | fill | fontface | height | hjust | lineheight | linetype | shape | size | stroke | vjust | weight | width | xmax | xmin | ymax | ymin |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
GeomAbline | NA | black | 1 | 0.5 | ||||||||||||||||
GeomAnnotationMap | NA | NA | grey20 | 1 | 0.5 | |||||||||||||||
GeomArea | NA | NA | grey20 | 1 | 0.5 | |||||||||||||||
GeomBar | NA | NA | grey35 | 1 | 0. |
NewerOlder