Skip to content

Instantly share code, notes, and snippets.

@Protonk
Last active December 31, 2015 22:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Protonk/8056408 to your computer and use it in GitHub Desktop.
Save Protonk/8056408 to your computer and use it in GitHub Desktop.
library(jpeg)
library(plyr)
# Read in Girl before a Mirror from somewhere
# readJPEG only accepts a path, so give it one without much tomfoolery
picasso.path <- tempfile('girl_before_a_mirror.jpg')
download.file('http://bobholt.me/images/girl_before_a_mirror.jpg', picasso.path)
gbm <- readJPEG(picasso.path)
unlink(picasso.path)
# helper function to plot eigenvalues
plotEigen <- function(m) {
# Gimme a square matrix
corMat <- cor(t(m))
y <- eigen(corMat)$values
plot(y = y, x = seq_along(y), log = "x", las = 1)
}
# cheap way to get multiple plots on a single page
old.par <- par(mfrow = c(1,1))
LO <- layout(matrix(1:6, ncol=2))
# Each channel is a m * n matrix
# we use a_ply because plot is called for side effects and we don't need a return value
a_ply(gbm, 3, plotEigen)
# prcomp has a plot method. Yay.
a_ply(gbm, 3, function(x) {plot(prcomp(x))})
par(old.par)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment