Skip to content

Instantly share code, notes, and snippets.

View wch's full-sized avatar

Winston Chang wch

View GitHub Profile
@wch
wch / pngtests.r
Created March 19, 2012 05:22
PNG output tests in R
library(ggplot2)
p <- ggplot(mtcars, aes(cyl, mpg)) + geom_point()
# Standard png device, with type="cairo"
# Result: not antialiased
png('png_cairo.png', type="cairo")
p
dev.off()
@wch
wch / qpdf_compresstest.r
Created March 19, 2012 16:47
Tests of PDF file sizes using qpdf
# Create the test plot
library(ggplot2)
ggplot(mtcars, aes(disp, mpg)) + geom_point()
ggsave("t.pdf", width=5, height=5, compress=FALSE)
# Use this for large files
#ggplot(diamonds, aes(carat, price, colour=color)) + geom_point()
#ggsave("t.pdf", width=5, height=5, compress=FALSE)
@wch
wch / ggplot2_speed_data.r
Created March 27, 2012 07:49
Script for loading and processing data on ggplot2 speed
require(RCurl)
require(plyr)
mytsv <- getURL("https://docs.google.com/spreadsheet/pub?key=0AhQ4CGoYYLyvdDd6b2Q5MG9ic2NoQWRPT3dLT0FyUkE&output=txt", ssl.verifypeer = FALSE)
raw <- read.delim(textConnection(mytsv), quote = "", stringsAsFactors = FALSE)
# Process the stuff from dput() on each row
parserow <- function(row) {
d <- eval(parse(text = row[[2]]))
@wch
wch / predictvals.r
Created April 28, 2012 17:44
Functions for generating predicted values from model objects in R
#' Find the range of the predictor variable, given the model object and the
#' name of the predictor variable
#'
# @examples
#' lm_mod <- lm(am ~ wt, data=mtcars)
#' model_xrange(lm_mod, "wt")
#'
#' mod_glm <- glm(am ~ wt, family=binomial, data=mtcars)
#' model_xrange(mod_glm, "wt")
#'
@wch
wch / ggplot2_items.r
Created May 10, 2012 20:11
ggplot2 webpage reference info
index <- list(
list(
name = "Geoms",
description = "Geoms, short for geometric objects, describe the type of plot you will produce.",
items = list(
list(
name = "geom_abline",
description = "Line, specified by slope and intercept" ),
@wch
wch / test_break_oob.r
Created May 14, 2012 21:54
Test script for ggplot2 #552: Setting breaks outside of axis ranges fails
#!/usr/bin/Rscript
# To try out this script, run this, in the top-level ggplot2/ dir:
# git bisect reset
# git bisect start
# git bisect good ggplot2-0.9.0
# git bisect bad ggplot2-0.9.1
# git bisect run bisect/test_break_oob.r
@wch
wch / gist:2765515
Created May 21, 2012 23:58
R meetup ggplot2 + plyr presentation
# Useful online resources
# ggplot2 website: http://had.co.nz/ggplot2/
# Mailing list: https://groups.google.com/forum/?fromgroups#!forum/ggplot2
# Cookbook for R: http://wiki.stdout.org/rcookbook/
install.packages('ggplot2')
# If you already have it installed, make sure it's up-to-date
update.packages()
@wch
wch / fileflags.c
Created June 1, 2012 05:04
Program for setting copy-on-write flag for files in a btrfs filesystem
#include <errno.h>
#include <fcntl.h>
#include <inttypes.h>
#include <linux/fs.h>
#include <linux/types.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/ioctl.h>
@wch
wch / gtable_test.r
Created July 19, 2012 17:27
gtable tests
# gtable tests
```{r setup, include=FALSE}
knit_hooks$set(optipng = hook_optipng)
```
```{r}
library(devtools)
dev_mode()
@wch
wch / gist:3229976
Created August 1, 2012 19:35
EC2 setup for R
# x-large high-cpu - set up
ec2-run-instances ami-82fa58eb --region us-east-1 --instance-type c1.xlarge --key ec2-keypair-us-east-1 --user-data-file bootstrap.sh
# Get IP address:
ec2-describe-instances --region us-east-1
# Wait for a bit, then run:
./setup.sh ec2-23-20-74-242.compute-1.amazonaws.com a_vagrant_machine/ ~/.ec2/ec2-keypair-us-east-1