Skip to content

Instantly share code, notes, and snippets.

View cmjt's full-sized avatar

Charlotte M. Jones-Todd cmjt

View GitHub Profile
@cmjt
cmjt / dragon_data.csv
Created March 22, 2024 05:27
plot a dragon, character names from the Fourth Wing taken from https://www.estapinto.com/books/fourth-wing-book-review-characters
We can make this file beautiful and searchable if this error is corrected: Unclosed quoted field in line 5.
"dragon_names","dragon_types","dragon_colors","x_1","y_1","x_2","y_2","x_3","y_3","x_4","y_4","x_5","y_5","x_6","y_6","x_7","y_7"
"Tairneanach","Morningstartail","Black",-0.0160343095587667,-0.475012970956097,-0.0247717663682427,-0.304502853610342,0.0614933710135008,-0.176835528276684,0.122175367326438,-0.0995065517127183,0.210537935906918,0.155265104264409,0.158427809729873,-0.102608542064535,0.263012352765849,0.035214765915639
"Andarnaurram","Feathertail","Golden",0.19231236270105,-0.149204632011216,0.281983066002848,-0.11516001192224,0.309111682691777,0.0288341594268495,0.385965977458134,0.0862044222680958,0.42238952609094,0.193471469416141,0.426407762703258,0.236976608122578,0.392688796405665,0.293607250488481
"Sgaeyl","Daggertail","Blue",0.251862850077826,0.359554903021405,0.174180621943546,0.252011878084052,0.202186848002473,0.349189177255015,0.221394902138276,0.513197257884685,0.283732765187058,0.690871758640864,0.370439467031693,0.845297890425778,0.440090741497124,0.966165123030898
"Deigh","Daggertail
@cmjt
cmjt / predictmeans_summary.r
Last active February 11, 2022 00:19
Functions to create a pairwise comparison table from predictmeans output
#' Function to extract pairwise comparison names
#' from the output of predictmeans::predictmeans()
#' @source Kathy Ruggiero, k.ruggiero@auckland.ac.nz
#' @param pm a predictmeans output object
comparison_names <- function(pm){
trtNames <- colnames(pm$`Pairwise LSDs`)
# Paste pairs of names with "-" between them to show comparison
comparison <- NULL
k <- 1
@cmjt
cmjt / horse.csv
Last active September 13, 2021 01:49
x, y coordinates of simplified cantering horse (scraped from https://jasmindiaz.weebly.com/mathematical-model-of-me.html)
x y
1.83984375 4
3.515624999999993 4.521739130434781
4.07421875 4.521739130434781
5.44921875 4.913043478260869
6.007812499999993 7.608695652173912
7.08203125 7.608695652173912
7.94140625 8.478260869565217
8.328125 9.043478260869565
10.6484375 8.695652173913043
@cmjt
cmjt / inla_on_nesi.md
Last active July 13, 2022 02:54
Installing INLA on NeSi

Installing INLA on NeSi

Firstly, navigate to your NeSi folder. Then, run the following to load the spatial R-related software you'll need to use in your NeSi session

module load R-Geo/4.2.1-gimkl-2022a

Open R:

## CRAN packages
library(Pareto) ## heavy tailed distribution
library(ggplot2) ## plotting
library(patchwork)
## GitHub packages
library(ggcats) ## remotes::install_github("R-CoderDotCom/ggcats@main")
set.seed(6666)
t <- 100; alpha = 20
@cmjt
cmjt / rgen.r
Last active December 2, 2020 23:01
Stats department Christmas quiz plots
###################################################
##** All based on https://github.com/djnavarro **##
##*********** No credit is mine ***********########
###################################################
## required packages
devtools::install_github("djnavarro/turmite59")
devtools::install_github("djnavarro/scrawl")
devtools::install_github("djnavarro/flametree")
################################
@cmjt
cmjt / nz_rivers.r
Last active August 27, 2020 22:45
NZ river networks
## library for shapefiles
library(sf)
library(ggplot2)
## data from https://data-niwa.opendata.arcgis.com/datasets/river-lines
## read in from GitHub
url <- "https://github.com/cmjt/eeda/raw/master/gh-data/rivers_nz.rda?raw=True"
repmis::source_data(url)
## setting diverging colour palette
cols <- c(RColorBrewer::brewer.pal(4, "Dark2"),
rep(RColorBrewer::brewer.pal(8, "Dark2"),75,))
@cmjt
cmjt / ll_2_utm.r
Created July 24, 2019 00:23
Function to transform latitude and longitude coordinates to UTM.
#' Function to convert latitude and longitude coordinates
#' to UTM. Will automatically calculate the UTM zone.
#' Only works is UTM zone is unique
#' @param latitude vector of latitude coordinates
#' @param longitude vector of longitude coordinates
library(rgdal)
ll.2.utm <- function(latitude,longitude){
## find utm zone
zone = (floor((longitude + 180)/6) %% 60) + 1
if(length(table(zone)) > 1){stop("data spans multiple UTM zones")}
@cmjt
cmjt / AUSvsENG.txt
Created December 17, 2018 21:28
Wicket info for Women's Ashes 2015 Australia vs England
"session" "over" "batting.team" "batswoman" "not.facing" "bowler" "wicket" "contig"
"1" 1 21.5 "Australia" "EJ Villani" "NE Bolton" "A Shrubsole" "caught" 21.5
"2" 1 23.5 "Australia" "MM Lanning" "NE Bolton" "A Shrubsole" "caught" 23.5
"3" 1 29.5 "Australia" "NE Bolton" "EA Perry" "A Shrubsole" "bowled" 29.5
"4" 1 33.1 "Australia" "EA Perry" "AJ Blackwell" "A Shrubsole" "caught" 33.1
"5" 1 38.3 "Australia" "AJ Blackwell" "JL Jonassen" "KH Brunt" "lbw" 38.3
"6" 1 59.6 "Australia" "AJ Healy" "JL Jonassen" "LA Marsh" "lbw" 59.6
"7" 1 64.3 "Australia" "SJ Coyte" "JL Jonassen" "KL Cross" "caught" 64.3
"8" 1 71.4 "Australia" "ML Schutt" "JL Jonassen" "LA Marsh" "lbw" 71.4
"9" 1 100.5 "Australia" "JL Jonassen" "KM Beams" "KH Brunt" "lbw" 100.5
@cmjt
cmjt / guess_position.r
Last active May 15, 2025 11:13
R function to randomly plot a cricket fielding position for a right handed batsman and give the "player" 10 seconds to guess before the position is named
#' Function to randomly plot a cricket fielding position for a right handed batsman
#' and give the "player" 10 seconds to guess before the position is named
#' @param times the number of times you want to "play", by default 1
#' @param show.inner logical, do you want the inner field boundaries plotted
#' @param show.all logical, if TRUE then all fielding positions will be plotted
guess.position <- function(times = 1, show.inner = FALSE, show.all = FALSE){
fielding.positions <- data.frame(x = c(0.55,1.45,1.35,0.7,0.6,0.8,1.2,
1.075,0.925,0.925,0.75,0.9,1.1,
0.8,0.75,0.7,0.75,0.8,0.85,
1.2,1.3,1.2,1.4),