Skip to content

Instantly share code, notes, and snippets.

View ottadini's full-sized avatar
👴

ben harrison ottadini

👴
View GitHub Profile
@ottadini
ottadini / somdata.csv
Last active December 20, 2015 04:08
Data file (CSV) for supervised mapping and prediction using kohonen package. "MEAS_TC","SP","LN","SN","GR","NEUT"
MEAS_TC SP LN SN GR NEUT
2.78 59.1810903609045 33.7436448559876 19.7536103778765 66.5766474766635 257.0368012729
1.49 49.0477497329406 184.145977437229 139.079797489143 54.7505195826885 326.800134003894
1.49 49.1289016073479 183.588534123696 138.027677512105 55.5411398043229 327.473945839365
2.201275709 18.2403310337942 19.2038626516248 10.7474792741976 62.0449186292617 494.416136250187
2.201275709 18.2155224379773 19.1800937852543 10.7244616233215 61.8744774871462 494.740941830979
1.276476312 9.33776939549743 14.1606094244497 19.0690215694105 14.9961159237259 363.002021309839
1.276476312 9.30627807118255 14.1655436529726 19.0953021764089 15.0205158738082 363.592835920731
2.4162441005 65.9385510407827 11.5964588279339 13.1929031148605 43.785062332152 142.583172944641
2.4162441005 66.2962310687366 11.5462659711476 13.1725547197125 43.607290645435 142.672765831378
@ottadini
ottadini / som-prediction.R
Last active December 20, 2015 04:19
An attempt at prediction of TC using the kohonen package.
# ===== #
library(kohonen)
# Load data, available at https://gist.github.com/ottadini/6068259
somdata <- read.csv("somdata.csv")
# Create SCALED test and training sets from data:
inTrain <- sample(nrow(somdata), nrow(somdata)*(2/3))
training <- scale(somdata[inTrain, ])
@ottadini
ottadini / lm_eqn.R
Last active July 11, 2017 03:41
Annotate a ggplot2 plot with regression line equation and R^2
# Source: http://stackoverflow.com/q/7549694/857416
lm_eqn = function(m) {
# Displays regression line equation and R^2 value on plot
# Usage:
# p + annotate("text", x=25, y=300, label=lm_eqn(lm(y ~ x, df)), parse=TRUE)
l <- list(a = format(coef(m)[1], digits = 2),
b = format(abs(coef(m)[2]), digits = 2),
r2 = format(summary(m)$r.squared, digits = 3));
@ottadini
ottadini / ssomdata.csv
Last active December 25, 2015 03:59
Code and data for Super-organised som using kohonen package
DEPTH Strat MEAS_TC GR SP LN SN NEUT
88.0872 Boisdale Formation 2.78 66.5766474766635 59.1810903609045 33.7436448559876 19.7536103778765 257.0368012729
96.012 Boisdale Formation 1.49 54.7505195826885 49.0477497329406 184.145977437229 139.079797489143 326.800134003894
96.1644 Boisdale Formation 1.49 55.5411398043229 49.1289016073479 183.588534123696 138.027677512105 327.473945839365
142.0367 Tambo River Formation 2.201275709 62.0449186292617 18.2403310337942 19.2038626516248 10.7474792741976 494.416136250187
142.1891 Tambo River Formation 2.201275709 61.8744774871462 18.2155224379773 19.1800937852543 10.7244616233215 494.740941830979
151.0284 Gippsland Limestone Formation 1.276476312 14.9961159237259 9.33776939549743 14.1606094244497 19.0690215694105 363.002021309839
151.1808 Gippsland Limestone Formation 1.276476312 15.0205158738082 9.30627807118255 14.1655436529726 19.0953021764089 363.592835920731
156.5148 Tambo River Formation 2.4162441005 43.785062332152 65.9385510407827 11.5964588279339 13.1929031148605
@ottadini
ottadini / graphics.R
Created October 15, 2013 04:44
R base graphics and ggplot2 parameters for consistent plots
# Base graphics
# Create a PDF for a square shaped plot (e.g. for predictions vs observations regression)
pdf(file="pred-vs-meas_MLR.pdf", width=5, height=5, family="Times")
op <- par(pty='s') # plot type = square
plot(X, Y,
xlab=Xlabel, ylab=Ylabel, ylim=c(0, 3), xlim=c(0, 3)) #
abline(fit, lty=2)
par(op)
@ottadini
ottadini / plot.multi.dens.R
Last active December 25, 2015 17:49
Plot multiple density curves on one graph in R base graphics, taking care of the axis limits.

plot.multi.dens <- function(s){
# From: http://onertipaday.blogspot.com.au/2007/09/plotting-two-or-more-overlapping.html
# the input s MUST be a numeric list
# e.g.
# rating <- rnorm(200)
# rating2 <- rnorm(200, mean=.8)
# plot.multi.dens( list(rating, rating2))
junk.x = NULL
junk.y = NULL
@ottadini
ottadini / kohonen-hexagonal-SOM-plot.R
Created November 29, 2013 00:07
Means to create a coloured hexagonal "heat map" plot of SOM map from kohonen package.
# I cannot remember the source for this code. It isn't mine. Probably somewhere on stackoverflow.
require ("kohonen")
require ("latticeExtra")
require ("deldir")
data(wines)
som.wines <- som (scale (wines), grid = somgrid(5, 5, "hexagonal"))
df <- as.data.frame (cbind (som.wines$grid$pts, som.wines$codes))
levelplot (alcohol ~ x * y, data = df, panel = panel.voronoi, aspect = "iso")
@ottadini
ottadini / hexagonal-grid.R
Created November 29, 2013 00:08
Functions and code to create a hexagonal grid.
# Cannot remember the source for this code, it isn't mine.
genHexGrid <- function(dx, ll = c(0, 0), ur = c(1, 1))
{
dy <- sqrt(3) * dx / 2
x <- seq(ll[1], ur[1] - dx / 2, dx)
y <- seq(ll[2], ur[2], dy)
y <- rep(y, each = length(x))
@ottadini
ottadini / wrap.R
Created December 5, 2013 03:31
Function to wrap and add newlines to R strings (for labels and titles in plots).
wrap <- function(string){
paste(strwrap(string), collapse="\n")
}
@ottadini
ottadini / log-data.csv
Created January 14, 2014 04:34
Some multivariate well-log data for examples.
GR SP SN LN NEUT
0.932011582050924 0.44026862656239 -0.142920083918207 -0.93111799430797 -0.418657901807612
-0.737200804302749 0.111726350584309 -4.74651979583995 -2.14188629181454 -1.02792833777312
0.97320078722993 -0.543377630307396 1.13645060051328 0.831361363627547 0.489887703839593
0.445099239355994 -0.109160023503522 -0.26752371296901 -0.726381874865315 -0.397069175699025
0.494654268843848 -0.0458757375244674 -0.291692621514504 -0.0926310013351277 -1.07773494755937
-0.788852669410601 -0.960105779255306 0.868314692272913 0.972866917578171 0.750957159974232
-0.808524334767298 -0.105857232731928 -0.912789546614396 -0.817278608325249 -0.764252540689194
1.48119987511833 2.17171874951617 -1.0610360292608 -1.08615547717843 -0.978594194274006
-0.446712462933821 -0.878438629867644 -0.110603841252218 -0.379725423923287 0.261823449056729