Skip to content

Instantly share code, notes, and snippets.

@bryanmayer
bryanmayer / print_xtable.R
Created February 5, 2018 18:07
wrapper for using xtable and print.xtable. Does not handle long tables.
print_xtable = function(table_in,
caption = "FILL IN CAPTION",
digits = NULL,
align = NULL,
include.rownames = F,
comment = F,
sanitize.text.function = function(x) x,
xtable.options = NULL,
return_xtable = F,
...){
@bryanmayer
bryanmayer / extract_legend
Created March 13, 2017 21:47
function to extract legend from ggplot2
extract_legend = function(plot_in, theme_in = theme(legend.position = "top"))
gtable::gtable_filter(ggplot_gtable(ggplot_build(plot_in + theme_in)), "guide-box")
library(ggplot2)
library(RColorBrewer)
gg_color_hue <- function(n) {
hues = seq(15, 375, length = n + 1)
hcl(h = hues, l = 65, c = 100)[1:n]
}
n = 4
cols = gg_color_hue(n)
# Setting PATH for Python 3.5
# The orginal version is saved in .bash_profile.pysave
PATH="/Library/Frameworks/Python.framework/Versions/3.5/bin:${PATH}"
export PATH
# added by Anaconda3 2.5.0 installer
#export PATH="/Users/bryanmayer/anaconda/bin:$PATH"
#export PYTHONPATH=/Users/bryanmayer/anaconda/bin/python:$PYTHONPATH
@bryanmayer
bryanmayer / xtableCommand.R
Last active January 1, 2016 21:09
Automatic italics into latex tables using xtable in R
library(xtable)
library(plyr)
fakedata = data.frame(
Bacteria = c("G. vaginalis", "L. crispatus"),
Count = log10(rlnorm(2*100, 13.5))
)
table1 = ddply(fakedata, .(Bacteria), summarize,
Bacteria = paste("\\textit{",unique(Bacteria),"}", sep=""),
@bryanmayer
bryanmayer / customAxis.R
Last active January 1, 2016 19:19
Using multiple colours and fontfaces for axes labels in ggplot
library(ggplot2)
fakedata = data.frame(
Bacteria = c("G. vaginalis", "BVAB", "L. crispatus"),
Count = log10(rlnorm(3*100, 13.5))
)
#create functions to map fontface and colour to bacteria category
#just using sapply
fontFaceFunction = function(bacteriaList)
@bryanmayer
bryanmayer / repeatcolumn.R
Created December 18, 2013 23:01
create a column for baseline values in timeseries data. are there better ways?
library(plyr)
testdata = data.frame(
ID = rep(c("A", "B", "C"), each = 6),
time = rep(seq(0, 5, 1), 3),
output = rnorm(3 * 6)
)
testdata = merge(testdata,
ddply(