This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)), |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 ----- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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), |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |