Skip to content

Instantly share code, notes, and snippets.

@vadimnazarov
Created May 20, 2015 11:05
Show Gist options
  • Save vadimnazarov/73060555c157ecdae9fe to your computer and use it in GitHub Desktop.
Save vadimnazarov/73060555c157ecdae9fe to your computer and use it in GitHub Desktop.
pcaGenes <- function(.data, .cast.freq.seg = T, ..., ..do.plot = T){
if (.cast.freq.seg) { .data <- freq.segments(.data)[,-1] }
pca.res <- prcomp(t(as.matrix(.data)), ...)
if (.do.plot) {
pca.res <- data.frame(PC1 = pca.res$x[,1], PC2 = pca.res$x[,2], Subject = names(.data))
ggplot() + geom_point(aes(x = PC1, y = PC2, colour = Subject), size = 3, data = pca.res) +
theme_linedraw() + guides(size=F) + ggtitle("VJ-usage: Principal Components Analysis")
} else {
pca.res
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment