Skip to content

Instantly share code, notes, and snippets.

library(ggplot2)
library(gridExtra)
mtcars$cyl <- ordered(mtcars$cyl)
p <- ggplot(mtcars, aes(mpg, hp, colour = cyl)) + geom_point()
p1 <- p + theme(legend.position = "none")
p2 <- ggplot(mtcars, aes(x=mpg, group=cyl, colour=cyl))
p2 <- p2 + stat_density(fill = NA, position="dodge")
@benmarwick
benmarwick / DH-2013-abstracts-topic-model.R
Created August 11, 2013 17:35
R code to reproduce Shawn Graham's topic model of the DH2013 conference abstracts (http://electricarchaeology.ca/2013/08/09/topic-modeling-dh2013-with-paper-machines/). Best run with RStudio. If things get sluggish, press CTRL-L to clear the console
# R code to reproduce Shawn Graham's topic model
# of the DH2013 conference abstracts:
# http://electricarchaeology.ca/2013/08/09/topic-modeling-dh2013-with-paper-machines/
# Best run with RStudio. If things get sluggish,
# press CTRL-L to clear the console
@benmarwick
benmarwick / artefact-morpho.R
Last active March 3, 2021 14:55
R code for converting B&W jpgs of artefact silhouettes to matrices and computing basic Elliptical Fourier statistics, including PCA and MANOVA
# This script is a workflow for analysing 2D artefact outlines from 3D
# scan objects captured by NextEngine and ScanStudio. Part of the process
# occurs in ScanStudio and GIMP and the quantative analysis of the outlines
# is done in R. In GIMP we process the images into B&W silhouettes ready for R.
# In R we do elliptical fourier analysis to summarise the image outlines
# then PCA and MANOVA to discriminate between shape variations
# and test for differences
########### Using GIMP to preparing ScanStudio images for input into R ###########
## Get screenshot from scanstudio into GIMP
This gist is no longer updated, see this one the for the most current version:
https://gist.github.com/benmarwick/6260541
# This script is a workflow for analysing 2D artefact outlines from 3D
# scan objects captured by NextEngine and ScanStudio. Part of the process
# occurs in ScanStudio and GIMP and the quantative analysis of the outlines
# is done in R. In GIMP we process the images into B&W silhouettes ready for R.
# In R we do elliptical fourier analysis to summarise the image outlines
# then PCA and MANOVA to discriminate between shape variations
# and test for differences
@benmarwick
benmarwick / basic-ANOVA.R
Last active September 7, 2017 14:15
Notes on basic ANOVA in R
# basic workflow for ANOVA
# some fake example data
x <- runif(100) # The measurement variable (100 random numbers)
y <- sample(rep(letters[1:5], each=20)) # The catagorical variable (five groups)
# make a data frame of the x and y vectors
df <- data.frame(measure = x, group = y)
# inspec the data frame to make sure it looks right
str(df)
@benmarwick
benmarwick / AU13_ARCHY_482_Geoarch.R
Last active December 26, 2015 04:59
R code for working on the data from our labs. Note that these are no longer actively developed. For the most recent code, see here: https://github.com/benmarwick/au13uwgeoarchlab
## get data from google sheet
# connect to google sheet
require(RCurl) # if you get an error message here that says something like 'there is no package called 'RCurl''
# then you need to install the package by typing this into the console (and then hitting enter): install.packages("RCurl")
# wait for the package to download and install, then run line 3 again before proceeding.
options(RCurlOptions = list(capath = system.file("CurlSSL", "cacert.pem", package = "RCurl"), ssl.verifypeer = FALSE))
# in google spreadsheet, go to file-> publish to web -> get link to publish to web -> get csv file
goog <- "https://docs.google.com/spreadsheet/pub?key=0As7CmPqGXTzldE5UV3FOZTRlYy10ZF9JOWcxYy1tSGc&single=true&gid=0&output=csv"
# assign data from google sheet to R object
data <- read.csv(textConnection(getURL(goog)), stringsAsFactors = FALSE)
@benmarwick
benmarwick / AU13_ARCHY_499_Geoarch.R
Last active January 16, 2020 00:34
Code for working with Horbia LPSA output and Mag Sus data
########### working with the Horiba LA-950 data ######################
# First step is to convert ngb files to txt, since ngb is not a format
# that R can read.
# 1. Open the LA-950 for windows program (I have a copy of the software you can have)
# 2. Go to the 'File List View' in the left panel, select all
# the files and right-click on them and select 'delete', then
# choose 'delete from file view' (not delete from computer)
@benmarwick
benmarwick / DY-XYZ-data-on-an-irregular-grid-to-an-interpolated-raster.r
Last active December 27, 2015 20:29
Plotting remote sensing data, especially how to go from XYZ data on an irregular grid to an interpolated raster
Here's the code for the Denny Yard data:
## Working with remote sensing data from GEM Gradiometer
# First get data from machine onto a computer. Here we've got the
# data on a google sheet...
# get data from google drive... connect to google sheet
require(RCurl) # if you get an error message here that says something like 'there is no package called 'RCurl''
# then you need to install the package by typing this into the console (and then hitting enter): install.packages("RCurl")
@benmarwick
benmarwick / loess-interpolation-depth-age.r
Last active December 28, 2015 07:09
Interpolate age from depth using local fitting (aka loess)
###############################################################################
############ Interpolate age from depth using local fitting (aka loess) #######
# Assuming that we have a data frame called 'dates' that has a numeric variable called 'Depth.m'
# which is depth in meters and another called 'cal.median' which is an age determination in kya...
span <- 0.45 # this has a big influence on the shape of the curve, experiment with it!
cal.date.lo <- loess(cal.median ~ Depth.m, dates, span = span)
cal.date.pr <- predict(cal.date.lo, data.frame(Depth.m = seq(0, 5, 0.01)))
plot(cal.date.pr) # inspect to seee that it looks right
@benmarwick
benmarwick / Claude_Morphometrics_with_R.R
Last active March 26, 2023 02:49
Functions developed in Claude J. (2008). Morphometrics with R. Springer.
# This file comes from:
# http://www.isem.univ-montp2.fr/recherche/teams/developmental-biology-and-evolution/staff/claudejulien/?lang=en
# Errata for the book are also on that webpage
## All code here originally written by Julien CLAUDE to accommpany his book 'Morphometrics with R'.
# I've simply reproduced the code here to make it easier for me to find and source.
######functions developped in Claude J. (2008). Morphometrics with R. Springer.
######Refer to the book if you use them
####f1.1