Skip to content

Instantly share code, notes, and snippets.

View ChrisHarrod's full-sized avatar

Chris Harrod ChrisHarrod

  • Universidad de Antofagasta
  • Antofagasta, Chile
  • 14:01 (UTC -03:00)
  • X @chris_harrod
View GitHub Profile
@elliottmorris
elliottmorris / election_night_live_model.R
Last active October 18, 2025 10:10
A live election-night prediction model using The Economist's pre-election forecast
#' Description
#' This file runs a live election-night forecast based on The Economist's pre-election forecasting model
#' available at projects.economist.com/us-2020-forecast/president.
#' It is resampling model based on https://pkremp.github.io/update_prob.html.
#' This script does not input any real election results! You will have to enter your picks/constraints manually (scroll to the bottom of the script).
#'
#' Licence
#' This software is published by *[The Economist](https://www.economist.com)* under the [MIT licence](https://opensource.org/licenses/MIT). The data generated by *The Economist* are available under the [Creative Commons Attribution 4.0 International License](https://creativecommons.org/licenses/by/4.0/).
#' The licences include only the data and the software authored by *The Economist*, and do not cover any *Economist* content or third-party data or content made available using the software. More information about licensing, syndication and the copyright of *Economist* content can be fou
@JackAHutchings
JackAHutchings / gist:05bd1166a01ee58b1b8eca7d0d11a320
Last active May 7, 2020 19:04
ggplot Secondary Axis Demo
library(ggplot2)
data <- data.frame(a = c(rnorm(100,1,0.1),rnorm(10,1.2,0.2)),
b = c(rnorm(100,8,2),rnorm(10,13,2)),
c = c(rep("Group1",100),rep("Group2",10)))
data$c_dummy = ifelse(data$c == "Group1",0.5,1.5)
ggplot(data,aes(x=c_dummy,y=a,group=c)) +
geom_boxplot() +
@benmarwick
benmarwick / super-and-sub-script-labels.R
Last active January 28, 2026 19:54
ggplot axis labels with superscript and subscript
library(tidyverse)
# using expression() for the text formatting:
ggplot(mtcars,
aes(disp,
mpg)) +
geom_point() +
# ~ for spaces, and * for no-space between (unquoted) expressions
ylab(expression(Anthropogenic~SO[4]^{"2-"}~(ngm^-3))) +
xlab(expression(italic(delta)^13*C[ap]*"‰")) +
@Rekyt
Rekyt / arrow_pcoa.Rmd
Last active November 19, 2024 21:20
Plotting arrows on a PCoA
---
title: "Adding arrows to PCoA"
author: "Matthias Grenié"
date: "26 septembre 2018"
output: pdf_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
@valentinitnelav
valentinitnelav / Plot inwards ticks - ggplot.R
Last active October 7, 2021 13:14
Plot with inwards ticks - ggplot
# ==========================================================================
# Example of plot for publication with inwards ticks in ggplot
# ==========================================================================
library(ggplot2)
# ==================================
# create some data
# ==================================
set.seed(1)
@jebyrnes
jebyrnes / had_crut_spider_plot.R
Created May 13, 2016 18:40
R code to reproduce the awesome visualization of global temperature change from Ed Hawkins at http://www.climate-lab-book.ac.uk/2016/spiralling-global-temperatures/ using R and ggplot2 (with the animations package)
library(dplyr)
library(tidyr)
library(ggplot2)
library(animation)
#Data from https://crudata.uea.ac.uk/cru/data/temperature/
#As well as data read in script
source("read_cru_hemi.R")
temp_dat <- read_cru_hemi("./HadCRUT4-gl.dat")
#remove cover
@benmarwick
benmarwick / 000_geom_bag.r
Last active January 5, 2025 01:16
Basic bagplot geom for ggplot2
#' Bagplot
#'
#' The bag geom is useful for graphical summaries of scatterplots. It
#' is effective at showing the location, spread, skewness, and
#' outliers of a data set.
#'
#' A bagplot is a bivariate generalization of the well known boxplot. It
#' was proposed by Rousseeuw, Ruts, and Tukey. This geom plots bagplots that
#' are very similar to the one described in Rousseeuw et al. and
#' uses code from their bagplot functions in the aplpack pacakge.