Skip to content

Instantly share code, notes, and snippets.

@paleolimbot
paleolimbot / mn_pourbaix.R
Created August 16, 2018 18:45
Manganeese 3D pourbaix diagram using PHREEQC and tidyphreeqc
library(tidyverse)
library(gganimate)
library(tidyphreeqc)
phr_use_db_minteq()
theme_set(theme_bw())
library(ggspatial)
result <- phr_run(
phr_solution_list(
pH = seq(3, 13, 0.1),
@paleolimbot
paleolimbot / 2018-08_paleodem.Rmd
Created August 20, 2018 23:45
Animation of the paleogeography of earth for the past 542 million years
---
title: "Paleogeography of earth for the past 542 million years"
author: "Dewey Dunnington"
date: '2018-08-20'
output: github_document
---
```{r setup, include=FALSE}
library(rvest)
library(tidyverse)
library(tibble)
library(dplyr)
library(purrr)
chisq_test_distr <- function(sample, fit_p, nbins = floor(length(sample) / 8)) {
cut_quantiles <- seq(0, 1, length.out = nbins + 1)
cut_values <- quantile(sample, cut_quantiles)
cut_values[1] <- -Inf
cuts <- tibble(
library(tidyverse)
library(tidyphreeqc)
phr_input(
phr_surface_master_species("Iron_oxy", "Iron_oxyOH"),
phr_surface_species("Iron_oxyOH = Iron_oxyOH"),
phr_surface_species("Iron_oxyOH + Zn+2 = Iron_oxyOZn+ + H+", log_k = -1.99),
phr_solution("Zn" = 0.1, units = "mol/kgw"),
phr_surface(
Iron_oxyOH = phr_surface_item(sites = 0.07, specific_area_per_gram = 600, grams = 30)
library(tidyverse)
library(tidyphreeqc)
solution_cacl2 <- phr_solution(
0, "CaCl2",
units = "mmol/kgw",
temp = 25,
pH = "7 charge",
pe = "12.5 O2(g) -0.68",
Ca = 0.6,
---
title: "R Notebook"
output: html_notebook
---
```{r setup}
library(tidyverse)
```
@paleolimbot
paleolimbot / Plotting_with_ggplot_suggestion.R
Created June 3, 2019 13:08
Suggestion for changes in HistDAWass for the release of ggplot2
library(ggplot2)
# these are defined elsewhere
x <- runif(100)
border <- "black"
xlabel <- "xlabel"
col <- "white"
compQ <- function(x, quant) quantile(x, quant)
# this is where your code
library(testthat)
library(rlang)
withr::with_namespace("ggplot2", {
# Checks that mapping refers to at least one column in data
check_aes_column_refs <- function(mapping, data) {
if (empty(data) || length(mapping) == 0) return()
@paleolimbot
paleolimbot / scale_df.R
Created June 6, 2019 23:30
A ggplot2 scale that can handle a data frame column
library(ggplot2)
ScaleDataFrame <- ggproto(
"ScaleDataFrame", Scale,
aesthetics = NULL,
plot_env = emptyenv(),
scales_list = ggproto(NULL, ggplot2:::ScalesList),
transform = function(self, x) {
x[] <- purrr::map2(
library(tidyverse)
library(sf)
box <- st_bbox(c(xmin = -120, xmax = -60, ymin = 45, ymax = 80), crs = 4326)
poly <- tibble(geometry = st_as_sfc(box)) %>% st_as_sf()
boundary <- st_cast(poly, "LINESTRING")
boundary_points <- st_make_grid(boundary, what = "corners") %>%
tibble(geometry = .) %>%
st_as_sf() %>%