Skip to content

Instantly share code, notes, and snippets.

View bjurban's full-sized avatar

Bryan Urban bjurban

View GitHub Profile
@bjurban
bjurban / bivariate-splom.R
Created September 3, 2015 14:01
plot bivariate kernel density plot
library(lattice)
library(MASS)
splom(iris, upper.panel = function(x, y, subscripts, ...) {
if(is.numeric(x) & is.numeric(y)){
# calculate bivariate kernel density
v <- current.panel.limits() # allows full bleed by setting limits explicitly
f1 <- kde2d(x = x, y = y, n = 50, lims = c(v$xlim, v$ylim))
f <- data.frame(x = f1$x, y = rep(f1$y, each = length(f1$x)),
# weather-underground.R
# Bryan Urban
# 2015-06-19
# this gets local weather data for a list of weather station codes from
# www.weatherunderground.com
#
# note: for large timespans or multiple cities, data scraping can be slow
## SETUP -----
@bjurban
bjurban / axis-ticks.R
Created June 1, 2015 19:44
lattice alternating axis tick marks
# alternating axis tick marks
# Bryan Urban
# 2015-06-01
xscale.components.alt <- function(lim, by=5, ...){
ans <- xscale.components.default(lim, ...)
tck.at <- ans$bottom$ticks$at
tck.lab <- as.character(tck.at)
@bjurban
bjurban / legends.R
Last active August 29, 2015 14:22
lattice legends with groups
# Legends and Groups in Lattice
# Bryan Urban
# 2015-06-01
library(lattice)
head(mtcars)
my.col <- c("black", "blue", "red")
my.settings <-
list(superpose.line = list(col=my.col),
@bjurban
bjurban / levelplot_scale.R
Created April 30, 2015 22:08
levelplot with linear color spacing
# Make a levelplot with a custum linear scale
# Author: Bryan Urban
# Email: burban at fraunhofer dot org
# Date: 2015-04-30
library(lattice)
library(RColorBrewer)
# make some data
foo <- foo <- expand.grid(x = 1:100, y=1:10)
@bjurban
bjurban / tidy-hobo-data.R
Last active May 10, 2021 19:17
Combine a directory of HOBO .csv files
# Combine multiple raw HOBO data files into a single .csv file
# Author: Bryan Urban
# Email: burban@fraunhofer.org
# Date: 2015-04-30
## SETUP --------------------
# install these two packages first if you don't have them:
# install.packages("data.table")
# install.packages("lubridate")
@bjurban
bjurban / power_analysis.R
Last active August 29, 2015 14:18
Examples of Power Analysis for Design of Experiments in R
## power analysis in R from
## http://www.statmethods.net/stats/power.html
library(pwr)
# http://meera.snre.umich.edu/plan-an-evaluation/related-topics/power-analysis-statistical-significance-effect-size
## Effect Size
# ~ difference in means (control vs. treatment) divided by
# the standard deviation (e.g., of the control group)
# <0.1 = trivial effect
# adding a custom legend to levelplot when z values are categorical (not continuous)
library(lattice)
foo <- expand.grid(x = 1:10, y=1:10)
foo$z <- as.integer(runif(100)*3)
# foo$z takes on values of 0, 1 or 2: this could represent a factor
# default levelplot
levelplot(z~x*y, foo)
# levelplot with custom colors and custom legend