Skip to content

Instantly share code, notes, and snippets.

@adamhsparks
adamhsparks / StatQuantileBin.R
Created April 16, 2023 11:39 — forked from eliocamp/StatQuantileBin.R
Percentogram (histogram with bins of equal number of observations)
StatQuantileBin <- ggplot2::ggproto("StatQuantileBin", ggplot2::StatBin,
default_aes = ggplot2::aes(x = ggplot2::after_stat(density), y = ggplot2::after_stat(density), weight = 1),
compute_group = function(data, scales,
binwidth = NULL, bins = 30, breaks = NULL, trim = 0,
closed = c("right", "left"), pad = FALSE,
flipped_aes = FALSE,
# The following arguments are not used, but must
# be listed so parameters are computed correctly
origin = NULL, right = NULL, drop = NULL,
@adamhsparks
adamhsparks / fetchGHdata.R
Created October 5, 2022 09:05 — forked from ritchieking/fetchGHdata.R
Fetch a data file directly from a private GitHub repo in R
# Download any data file from a private GitHub repo
# regardless of how large it is.
# Returns a string that will then need to be parsed
# by read_csv or the like to turn it into a data frame.
# Dependencies
require(tidyverse)
require(httr)
require(rlist)
require(jsonlite)
# see https://www.topbug.net/blog/2013/04/14/install-and-use-gnu-command-line-tools-in-mac-os-x/
# core
brew install coreutils
# key commands
brew install binutils
brew install diffutils
brew install ed
brew install findutils
@adamhsparks
adamhsparks / bibtex_2academic.R
Created February 14, 2019 10:45 — forked from lbusett/bibtex_2academic.R
script for importing publications from a "bibtex" file to a hugo-academic website
#' @title bibtex_2academic
#' @description import publications from a bibtex file to a hugo-academic website
#' @author Lorenzo Busetto, phD (2017) <[email protected]>
bibtex_2academic <- function(bibfile,
outfold,
abstract = FALSE,
overwrite = FALSE) {
require(RefManageR)
@adamhsparks
adamhsparks / _Nvim-R-Tmux.md
Created January 9, 2019 01:52 — forked from tgirke/_Nvim-R-Tmux.md
Nvim-R-Tmux: An Integrated Working Environment for R
@adamhsparks
adamhsparks / geom_point_sf.md
Created August 20, 2018 20:16 — forked from andrewheiss/geom_point_sf.md
geom_point and geom_sf
library(tidyverse)
library(sf)

Generate fake data (tribble() is a cool function, btw)

events <- tribble(
  ~event, ~latitude, ~longitude,
@adamhsparks
adamhsparks / Ignore_DS_Store.sh
Last active April 27, 2022 07:08 — forked from linuslundahl/Ignore .DS_Store forever
Make git always ignore .DS_Store
git config --global core.excludesfile ~/.gitignore
echo .DS_Store >> ~/.gitignore
@adamhsparks
adamhsparks / colorcoded-map-population-structures.R
Created June 30, 2017 23:52 — forked from ikashnitsky/colorcoded-map-population-structures.R
Code to reproduce the RGB map of the population structure of NUTS-3 regions of Europe -- https://ikashnitsky.github.io/2017/colorcoded-map/
################################################################################
#
# ikashnitsky.github.io 2017-06-30
# Produce an RGB coded map of pop structures at NUTS-3 level
# Ilya Kashnitsky, [email protected]
#
################################################################################
# Erase all objects in memory
rm(list = ls(all = TRUE))
# data from http://ec.europa.eu/eurostat/web/gisco/geodata/reference-data/population-distribution-demography/geostat
# Originally seen at http://spatial.ly/2014/08/population-lines/
# So, this blew up on both Reddit and Twitter. Two bugs fixed (southern Spain was a mess,
# and some countries where missing -- measure twice, submit once, damnit), and two silly superflous lines removed after
# @hadleywickham pointed that out. The result of the code below can be seen at http://imgur.com/nhVJqwk
library(tidyverse)
read_csv('../data/geostat-2011/GEOSTAT_grid_POP_1K_2011_V2_0_1.csv') %>%
@adamhsparks
adamhsparks / orig.png
Created April 24, 2016 12:06 — forked from hrbrmstr/orig.png
Supreme Annotations - moar splainin here: http://rud.is/b/2016/03/16/supreme-annotations/ - NOTE: this requires the github version of ggplot2
orig.png