Skip to content

Instantly share code, notes, and snippets.

View mbedward's full-sized avatar

Michael Bedward mbedward

View GitHub Profile
#===============================================================================
# 2020-06-19 -- twitter
# improve plot
# Ilya Kashnitsky, ilya.kashnitsky@gmail.com
#===============================================================================
# the challenge
# https://community.storytellingwithdata.com/exercises/one-little-changeand-a-redesign
library(tidyverse)
@mbedward
mbedward / gist:850fe1923d9b87e3d3c5f9a66fb7e7ca
Created August 21, 2018 07:16
Model observed proportions as Beta distributed with JAGS
# Some test data for proportions with mean 0.4
p <- rbeta(20, 4, 6)
# JAGS model
modelTxt <- "model {
for(i in 1:length(p)) {
p[i] ~ dbeta(alpha, beta)
}
alpha <- mu * phi
beta <- (1-mu) * phi
@mbedward
mbedward / example.R
Created March 7, 2017 23:56
This function retrieves data for a specified smooth term from a fitted gam object (package mgcv) which is handy when you want to graph the smoother with ggplot.
library(ggplot2)
library(mgcv)
# Toy data set
dat <- data.frame(
x = seq(0, 2*pi, length.out = 100),
y = sin(3*x) / sin(x/2)
)
# Randomly thin the data
@mbedward
mbedward / convex_hulls.png
Last active June 10, 2019 19:55
Example of drawing convex hulls around grouped points in R using dplyr and ggplot.
convex_hulls.png
@mbedward
mbedward / gist:6e3dbb232bafec0792ba
Last active September 26, 2021 14:08
Scala macro to convert between a case class instance and a Map of constructor parameters. Developed by Jonathan Chow (see http://blog.echo.sh/post/65955606729/exploring-scala-macros-map-to-case-class-conversion for description and usage). This version simply updates Jonathan's code to Scala 2.11.2
import scala.language.experimental.macros
import scala.reflect.macros.blackbox.Context
trait Mappable[T] {
def toMap(t: T): Map[String, Any]
def fromMap(map: Map[String, Any]): T
}
object Mappable {
@mbedward
mbedward / pom.xml to create GeoTools uber-jar
Created November 27, 2013 01:34
An example of how to safely combine GeoTools component jars into a single (uber) jar. It uses the Maven shade plugin to properly combine the META-INF/services entries of the individual GeoTools jars.
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.geotools</groupId>
<artifactId>gt-uber</artifactId>
<!-- The version of the GeoTools jars to combine -->
<version>10.2</version>