Last active
December 31, 2015 22:49
-
-
Save Protonk/8056408 to your computer and use it in GitHub Desktop.
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(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