Skip to content

Instantly share code, notes, and snippets.

@multidis
Created February 21, 2014 08:21
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 multidis/9130607 to your computer and use it in GitHub Desktop.
Save multidis/9130607 to your computer and use it in GitHub Desktop.
Correlation matrix visualization as ellipses. See http://is-r.tumblr.com/post/34352513559/plotting-correlation-ellipses
library("ellipse")
## Function to plot colored correlation ellipses
## http://is-r.tumblr.com/post/34352513559/plotting-correlation-ellipses
correlationEllipses <- function(cor){
require(ellipse)
ToRGB <- function(x){rgb(x[1]/255, x[2]/255, x[3]/255)}
C1 <- ToRGB(c(178, 24, 43))
C2 <- ToRGB(c(214, 96, 77))
C3 <- ToRGB(c(244, 165, 130))
C4 <- ToRGB(c(253, 219, 199))
C5 <- ToRGB(c(247, 247, 247))
C6 <- ToRGB(c(209, 229, 240))
C7 <- ToRGB(c(146, 197, 222))
C8 <- ToRGB(c(67, 147, 195))
C9 <- ToRGB(c(33, 102, 172))
CustomPalette <- colorRampPalette(rev(c(C1, C2, C3, C4, C5, C6, C7, C8, C9)))
ord <- order(cor[1, ])
xc <- cor[ord, ord]
colors <- unlist(CustomPalette(100))
plotcorr(xc, col=colors[xc * 50 + 50])
}
## visualize correlation matrix Gij
correlationEllipses(Gij)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment