Skip to content

Instantly share code, notes, and snippets.

@JoesDataDiner
Created February 23, 2013 14:12
Show Gist options
  • Save JoesDataDiner/5019912 to your computer and use it in GitHub Desktop.
Save JoesDataDiner/5019912 to your computer and use it in GitHub Desktop.
The Financial Crisis on Tape Part I - Graph - Final
#Personally I find the TLT anti correlation, rather obscures judging
#Put it to the right/
PrefOrder = c("SPY","QQQ","EEM","IWM","EFA","IYR","GLD","TLT")
rolling.correlmatrix$Var1 = factor(rolling.correlmatrix$Var1, PrefOrder) #careful not to just rename levels here!
rolling.correlmatrix$Var2 = factor(rolling.correlmatrix$Var2, PrefOrder) #careful not to just rename levels here!
#introduce the purple colouring to the top of the range to better highlight correlation changes.
mycolvec_2 = c(
rev(brewer.pal(8,"Blues")),
colorRampPalette(c(
colorRampPalette(c("white",brewer.pal(9,"Set3")[2],
brewer.pal(9,"Set1")[c(6,5,1)])
)(10)
rev(brewer.pal(9,"PRGn")[1])
))(9)
)
#The final graph shown at the start of the blog:
ggplot(rolling.correlmatrix, aes(x = Var1, y = Var2, fill = Correl)) +
geom_tile() +
scale_fill_gradientn(colours = mycolvec_2
,limits = c(-1,1))+
facet_grid(quarter~year)+ theme_bw()+
theme(panel.grid.major.x = element_blank(),
panel.grid.major.y = element_blank(),
axis.title.x = element_blank(),
axis.title.y = element_blank(),
axis.text.x=element_text(angle=90))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment