View gg_jitterbox.R
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# function to do a dodged half-boxplot and jittered points next to each other | |
# | |
# data_in should be a data frame | |
# factor_col should be a bare column name (not a string) | |
# although it will work if that column is factor or a character type | |
# numeric_col is the y axis continuous variable | |
# offset is the width of the boxplots and jittered point cloud | |
# | |
# the basic approach is to draw a boxplot without the tails | |
# (e.g. only the interquartile range) and then use segments to add the |
View half_violin_with_raw_data.R
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## GOAL: | |
## re-create a figure similar to Fig. 2 in Wilson et al. (2018), | |
## Nature 554: 183-188. Available from: | |
## https://www.nature.com/articles/nature25479#s1 | |
## | |
## combines a boxplot (or violin) with the raw data, by splitting each | |
## category location in two (box on left, raw data on right) | |
## call required packages |
View 0-ggplot-format-snippets.R
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
############################################################################## | |
## ## | |
## FORMATSNIPPETS.R ## | |
## ggplot format snippets ## | |
## ## | |
############################################################################## | |
#### LABELS #### | |
# Hide labels |
View geom_flat_violin.R
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# somewhat hackish solution to: | |
# https://twitter.com/EamonCaddigan/status/646759751242620928 | |
# based mostly on copy/pasting from ggplot2 geom_violin source: | |
# https://github.com/hadley/ggplot2/blob/master/R/geom-violin.r | |
library(ggplot2) | |
library(dplyr) | |
"%||%" <- function(a, b) { |
View GCMSAgilentDfileImport
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
##' Function readDFile | |
##' | |
##' Function readDFile | |
##' @param pathname the pathname of the directory containing the data to import | |
##' @return outData Output is a matrix of ion counts with rows as scantime and | |
##' columns as mass, and the respective values as labels | |
##' @export | |
readDFile<-function(pathname){ | |
filename<-file.path(pathname,'DATA.MS') |
View explore-correlations.r
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## Correlation matrix with p-values. See http://goo.gl/nahmV for documentation of this function | |
cor.prob <- function (X, dfr = nrow(X) - 2) { | |
R <- cor(X, use="pairwise.complete.obs") | |
above <- row(R) < col(R) | |
r2 <- R[above]^2 | |
Fstat <- r2 * dfr/(1 - r2) | |
R[above] <- 1 - pf(Fstat, 1, dfr) | |
R[row(R) == col(R)] <- NA | |
R | |
} |
View 0_reuse_code.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Use Gists to store code you would like to remember later on | |
console.log(window); // log the "window" object to the console |
View ipak.R
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ipak function: install and load multiple R packages. | |
# check to see if packages are installed. Install them if they are not, then load them into the R session. | |
ipak <- function(pkg){ | |
new.pkg <- pkg[!(pkg %in% installed.packages()[, "Package"])] | |
if (length(new.pkg)) | |
install.packages(new.pkg, dependencies = TRUE) | |
sapply(pkg, require, character.only = TRUE) | |
} |
View artefact-morpho.R
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
View plot with densities.R
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") |
NewerOlder