Skip to content

Instantly share code, notes, and snippets.

View sheymann's full-sized avatar

Sébastien Heymann sheymann

View GitHub Profile
@sheymann
sheymann / skew.py
Created May 16, 2012 08:10
Mean, Standard deviation and Skewness functions
import sys
import math
myvalues = [-3, -2, -1, -1, 0, 1, 2, 3, 7]
def moy(l):
sommeval = reduce(lambda somme, val: somme+val, l, 0)
return (float(sommeval)/len(l))
@sheymann
sheymann / gist:2400082
Created April 16, 2012 17:22
R ggplot2 tip: Change legend options
g <- g + opts(legend.position = c(0.5,0.86),
legend.title = theme_blank(),
legend.text = theme_text(size=11),
legend.key.size = unit(1, "lines"),
legend.key = theme_blank())
@sheymann
sheymann / debug.R
Created April 16, 2012 16:04
R tip: enable DEBUG mode
options(error=utils::recover)
@sheymann
sheymann / export_plot.R
Created April 16, 2012 16:01
R tip: Export a ggplot plot in PDF, EPS and PNG files
ExportPlot <- function(gplot, filename, width=2, height=1.5) {
# Export plot in PDF and EPS.
# Notice that A4: width=11.69, height=8.27
ggsave(paste(filename, '.pdf', sep=""), gplot, width = width, height = height)
postscript(file = paste(filename, '.eps', sep=""), width = width, height = height)
print(gplot)
dev.off()
png(file = paste(filename, '_.png', sep=""), width = width * 100, height = height * 100)
print(gplot)
dev.off()
@sheymann
sheymann / export_data.R
Created April 16, 2012 16:00
R tip: Export a data frame in a tabular file
ExportData <- function(data, filename) {
# Export data in a tabular file.
sink(paste(filename, '.txt', sep=""), append=FALSE, split=FALSE)
print(data)
sink()
}
@sheymann
sheymann / decorate_plot.R
Created April 16, 2012 15:58
R tip: Make a ggplot output ready for publication
# ----------------------------------------------------------------------------
# Rudolf Cardinal, March 2011
# Simple extensions to ggplot2 (v0.8.7); see http://www.psychol.cam.ac.uk/statistics/R/
# ----------------------------------------------------------------------------
theme_L_border <- function(colour = "black", size = 1, linetype = 1) {
# use with e.g.: ggplot(...) + opts( panel.border=theme_L_border() ) + ...
structure(
function(x = 0, y = 0, width = 1, height = 1, ...) {
polylineGrob(