Skip to content

Instantly share code, notes, and snippets.

View epijim's full-sized avatar

James Black epijim

View GitHub Profile
filled.legend <-
function (x = seq(0, 1, length.out = nrow(z)), y = seq(0, 1,
length.out = ncol(z)), z, xlim = range(x, finite = TRUE),
ylim = range(y, finite = TRUE), zlim = range(z, finite = TRUE),
levels = pretty(zlim, nlevels), nlevels = 20, color.palette = cm.colors,
col = color.palette(length(levels) - 1), plot.title, plot.axes,
key.title, key.axes, asp = NA, xaxs = "i", yaxs = "i", las = 1,
axes = TRUE, frame.plot = axes, ...)
{
# modification of filled.contour by Carey McGilliard and Bridget Ferris
filled.contour3 <-
function (x = seq(0, 1, length.out = nrow(z)),
y = seq(0, 1, length.out = ncol(z)), z, xlim = range(x, finite = TRUE),
ylim = range(y, finite = TRUE), zlim = range(z, finite = TRUE),
levels = pretty(zlim, nlevels), nlevels = 20, color.palette = cm.colors,
col = color.palette(length(levels) - 1), plot.title, plot.axes,
key.title, key.axes, asp = NA, xaxs = "i", yaxs = "i", las = 1,
axes = TRUE, frame.plot = axes,mar, ...)
{
# modification by Ian Taylor of the filled.contour function
@epijim
epijim / contour.r
Last active December 22, 2015 18:39
Contour plot in R
#Example Four Panel Contour Plot with One Legend
#Author: Carey R McGilliard
#September 2010
#http://wiki.cbr.washington.edu/qerm/index.php/R/Contour_Plots
#This code uses a modified version of filled.contour called filled.contour3 (created by Carey McGilliard, Ian Taylor, and Bridget Ferris)
#to make an example figure of four contour plots sharing a legend (to the right).
#The example demonstrates how to use various color schemes for the contour plots and legend, but the user will want to
#pick one color scheme for all four plots such that the legend matches the plots.
# HOW TO BELOW
# http://www.sr.bham.ac.uk/~ajrs/R/r-tutorials.html#NEDplot
#--Read in data file:
url <- "http://www.sr.bham.ac.uk/~ajrs"
file <- "R/datasets/a85_extended_NEDsearch.txt"
A <- read.table(paste(url, file, sep="/"), sep="|", skip=20, header=TRUE)
close(url(paste(url, file, sep="/"))) # close connection after use
#--Specfify output graphics device:
@epijim
epijim / 2way.r
Created September 10, 2013 13:56
2 categories
#--The following was used to define the colours, but since it's a non-standard
# package, I've used the hexadecimal colour codes explicity below to avoid the
# need to install "RColorBrewer". See http://colorbrewer2.org/ for more info.
#require(RColorBrewer)
#colset <- brewer.pal(3, "Pastel2")
colset <- c("#B3E2CD", "#FDCDAC", "#CBD5E8")
path <- "http://www.sr.bham.ac.uk/~ajrs/R/datasets"
#--Data file as taken from XMM website, but with "#" added to comment lines
@epijim
epijim / Correlagram _scatterplot matrix.R
Last active December 22, 2015 17:39
The corrgram package in R can produce a scattergraph in the lower diamond, with smoothed lines and confidence ellipse in the upper diamond. Great for visualising correlations in the dataset.
library(corrgram)
# Create correlagram of scatter against lines with conficence
# lines are loess smoothed curve
# eclipse is bivariate 68% concentration ellipse (68% of data inside!)
corrgram(Dataframe[,VECTORofCOLUMNSofINTEREST], order=FALSE, lower.panel=panel.pts,
upper.panel=panel.ellipse, text.panel=panel.txt,
diag.panel=panel.minmax,
main="Correlations between variables within the vector VECTORofCOLUMNSofINTEREST")