Skip to content

Instantly share code, notes, and snippets.

View ellisp's full-sized avatar

Peter Ellis ellisp

View GitHub Profile
@ellisp
ellisp / dualplot.R
Last active February 28, 2023 15:45
dualplot <- function(x1, y1, y2, x2 = x1,
col = c("#C54E6D", "#009380"),
lwd = c(1, 1), colgrid = NULL,
mar = c(3, 6, 3, 6) + 0.1,
ylab1 = paste(substitute(y1), collapse = ""),
ylab2 = paste(substitute(y2), collapse = ""),
nxbreaks = 5,
yleg1 = paste(gsub("\n$", "", ylab1), "(left axis)"),
yleg2 = paste(ylab2, "(right axis)"),
ylim1 = NULL, ylim2 = NULL, ylim.ref = NULL,
@ellisp
ellisp / us-update.R
Created November 6, 2020 06:56
Plot of the latest for the votecount for the 2020 US election in selected states
library(extrafont)
library(tidyverse)
library(scales)
myfont <- "Roboto"
main_font <- "Roboto"
heading_font <- "Sarala"
@ellisp
ellisp / Creds.R
Last active December 26, 2015 07:29
A utility for handling user credentials to databases
#----AskCreds - so RStudio can access ODBC-------------------
AskCreds <- function(Title="User credentials for a database", startuid="", returnValOnCancel = "ID_CANCEL") {
# Peter Ellis, 12 August 2013
# A wrapper function to provide a GUI to ask a user for user id and password so they
# can be given to a database in a future call of connectODBC()
# Based on http://www.sciviews.org/_rgui/tcltk/ModalDialog.html
require(tcltk)
dlg <- tktoplevel()
tkwm.deiconify(dlg)
@ellisp
ellisp / OnTheFly.R
Last active December 26, 2015 07:29
seasonal adjustment, indexing and rolling averages on the fly within ggplot in R
#---------------Index and Index12---------------
Index <- function(x, ref=x[1]){
# Function that takes a vector or time series (or any object actually)
# and returns it as an index based on 100. Defaults to using the
# first value of the vector as reference value, but this can be overridden.
if(length(ref)>1) stop("Reference value must be a single number")
x*100/ref