Skip to content

Instantly share code, notes, and snippets.

@zachmayer
Created August 23, 2011 15:13
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zachmayer/1165388 to your computer and use it in GitHub Desktop.
Save zachmayer/1165388 to your computer and use it in GitHub Desktop.
Variable Interactions
cor(iris[-5])
pairs(iris[-5], bg=iris$Species, pch=21)
cor(iris[-5])
pairs(iris[-5], bg=iris$Species, pch=21)
Sepal.Length Sepal.Width Petal.Length Petal.Width
Sepal.Length 1.0000000 -0.1175698 0.8717538 0.8179411
Sepal.Width -0.1175698 1.0000000 -0.4284401 -0.3661259
Petal.Length 0.8717538 -0.4284401 1.0000000 0.9628654
Petal.Width 0.8179411 -0.3661259 0.9628654 1.0000000
Sepal.Length Sepal.Width Petal.Length Petal.Width
Sepal.Length 1.0000000 -0.1175698 0.8717538 0.8179411
Sepal.Width -0.1175698 1.0000000 -0.4284401 -0.3661259
Petal.Length 0.8717538 -0.4284401 1.0000000 0.9628654
Petal.Width 0.8179411 -0.3661259 0.9628654 1.0000000
library(PerformanceAnalytics)
chart.Correlation(iris[-5], bg=iris$Species, pch=21)
library(PerformanceAnalytics)
chart.Correlation(iris[-5], bg=iris$Species, pch=21)
library(quantmod)
getSymbols(c('SPY','LQD','GLD'))
Data <- cbind(Cl(SPY),Cl(LQD),Cl(GLD))
Year <- as.factor(format(index(Data),'%Y'))
chart.Correlation(Data,bg=seq(1:5)[Year],pch=21)
par(xpd=TRUE)
legend(0, 1, as.vector(unique(Year)), fill=seq(1:5))
library(quantmod)
getSymbols(c('SPY','LQD','GLD'))
Data <- cbind(Cl(SPY),Cl(LQD),Cl(GLD))
Year <- as.factor(format(index(Data),'%Y'))
chart.Correlation(Data,bg=c(1,3,4,5,6)[Year],pch=21)
par(xpd=TRUE)
legend(0, 1, as.vector(unique(Year)), fill=c(1,3,4,5,6))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment