Skip to content

Instantly share code, notes, and snippets.

@cwickham
cwickham / stat_qqline.r
Created October 10, 2012 21:19
ggplot2 stat for adding lines to quantile-quantile plots
require(proto)
stat_qqline <- function (mapping = NULL, data = NULL, geom = "abline", position = "identity",
distribution = qnorm, dparams = list(), na.rm = FALSE, ...) {
StatQqline$new(mapping = mapping, data = data, geom = geom, position = position,
distribution = distribution, dparams = dparams, na.rm = na.rm, ...)
}
StatQqline <- proto(ggplot2:::Stat, {
objname <- "qqline"
@cwickham
cwickham / server.r
Created November 5, 2012 05:19
anova
library(shiny)
library(ggplot2)
# Define server logic required to generate and plot a random distribution
shinyServer(function(input, output) {
generate_data <- reactive(
function(){
mu <- c(input$mu_1, input$mu_2, input$mu_3)
tmp <- data.frame(len = rnorm(length(mu) * input$n,
mean = rep(mu, each = input$n),
fitted_variofit <- function (x, max.dist, scaled = FALSE, ...) {
my.l <- list()
if (missing(max.dist)) {
my.l$max.dist <- x$max.dist
if (is.null(my.l$max.dist))
stop("argument max.dist needed for this object")
}
else my.l$max.dist <- max.dist
if (any(x$cov.model == c("matern", "powered.exponential",
"cauchy", "gencauchy", "gneiting.matern")))
@cwickham
cwickham / july4.R
Last active August 29, 2015 14:03
Happy 4th of July!
library(plyr)
library(ggplot2)
# from: http://www.codeproject.com/Articles/18149/Draw-a-US-Flag-using-C-and-GDI
star_coords <- function(x, y, r, r1){
a <- 72 * pi /180
b <- a/2
df <- data.frame(
x = x + c(0, r1*sin(b), r*cos(pi/2 - a), r1*cos(a + b - pi/2), r*sin(b),
0, -r*sin(b), -r1*cos(a + b - pi/2), - r*cos(pi/2 - a), -r1*sin(b)),
@cwickham
cwickham / stat_qqline.R
Created July 7, 2014 19:27
Add a line to qqplots
require(proto)
stat_qqline <- function (mapping = NULL, data = NULL, geom = "abline", position = "identity",
distribution = qnorm, dparams = list(), na.rm = FALSE, ...) {
StatQqline$new(mapping = mapping, data = data, geom = geom, position = position,
distribution = distribution, dparams = dparams, na.rm = na.rm, ...)
}
StatQqline <- proto(ggplot2:::Stat, {
objname <- "qqline"
@cwickham
cwickham / add_cat.r
Created July 31, 2014 23:44
add a cat
library(httr)
library(ggplot2)
add_cat <- function(width = 400, height = 400){
r <- GET(paste("http://theoldreader.com/kittens", width, height, sep = "/"))
stop_for_status(r)
img <- content(r)
bw <- 0.2989*img[,,1] + 0.5870*img[,,2] + 0.1140*img[,,3]
lighter <- bw + (0.7 * (1-bw))
annotation_raster(lighter, xmin=-Inf, xmax=Inf, ymin=-Inf, ymax=Inf)
> PUT("https://canvas.instructure.com/api/v1/courses/890522/pages/my-new-page",
+ body = list("wiki_page[body]"= paste(readLines("test-simple.html"), collapse = "\n")),
+ add_headers("Authorization" = paste0("Bearer ", token)), verbose())
-> PUT /api/v1/courses/890522/pages/my-new-page HTTP/1.1
-> User-Agent: curl/7.30.0 Rcurl/1.95.4.1 httr/0.4.0.99
-> Host: canvas.instructure.com
-> Accept: */*
-> Accept-Encoding: gzip
-> Cookie: _csrf_token=R%2FAKhdtpkRA0HlWiFs4W%2B%2Bmu77rW7bM9XuUsvOa%2Bvc0Q32Hs7gzrYx9WfvRDjHK0i8yAzr7Y8FMo0WDQ05Xyuw%3D%3D; canvas_session=TPgoJzbRWborci-ryiUD9A.YcHtPu1gIj92ifvQL5cJY0A7GSoRD1VKXyuwQDR2dbsXl-LG-wsDyqYnpJ2wkOS-sjEfLPPpwT3i7lw-tsWa5mS4jMyVQROjcas_0ojuypKooSlaRrVmh8pofrfnLBZBh6iaPzTjeiVkzOZe3W1bXw.AU-3cNhCsO3pM8yv5mNNw22tBtg.VEVt-g
-> Authorization: Bearer 7~lzo8qNB80Ta0D6oq3tGVW9TzFs5MXbnA3FmEOIHzbQ5U2nOzuFV7n7TEq9dCpCPg
# devtools::install_github("lintr", "jimhester")
library(lintr)
library(magrittr)
# stuff to fix buggy lintr package
split_chain <- magrittr:::split_chain
wrap_function <- magrittr:::wrap_function
is_placeholder <- magrittr:::is_placeholder
is_compound_pipe <- magrittr:::is_compound_pipe
---
title: "F-test exercises"
author: "ST552 Winter 2015"
date: "January 23, 2015"
output: html_document
---
> In a study of cheddar cheese from the LaTrobe Valley of Victoria, Australia, samples of cheese were analyzed for their chemical composition and were subjected to taste tests. Overall taste scores were obtained by combining the scores from several tasters.
>
library(stringr)
library(RCurl)
#Google polyline decoder borrowed from:
#http://facstaff.unca.edu/mcmcclur/GoogleMaps/EncodePolyline/decode.js
DecodeLineR <- function(encoded) {
len = str_length(encoded)
encoded <- strsplit(encoded, NULL)[[1]]
index = 1
N <- 100000