Last active
December 10, 2015 22:59
-
-
Save illy/4506159 to your computer and use it in GitHub Desktop.
Sample script of using ggplot to plot acf matrix data.
This file contains hidden or 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
m.geQuote <- as.matrix(geQuote[,2:5]) | |
acf.geQuote <- acf(m.geQuote, lag=5, plot=F, na.action=na.contiguous) | |
m.acf.geQuote <- melt(acf.geQuote$acf) | |
m.acf.geQuote$Var1[m.acf.geQuote$Var1 == 1] <- "Day0" | |
m.acf.geQuote$Var1[m.acf.geQuote$Var1 == 2] <- "Day1" | |
m.acf.geQuote$Var1[m.acf.geQuote$Var1 == 3] <- "Day2" | |
m.acf.geQuote$Var1[m.acf.geQuote$Var1 == 4] <- "Day3" | |
m.acf.geQuote$Var1[m.acf.geQuote$Var1 == 5] <- "Day4" | |
m.acf.geQuote$Var2[m.acf.geQuote$Var2 == 1] <- "Open" | |
m.acf.geQuote$Var2[m.acf.geQuote$Var2 == 2] <- "Close" | |
m.acf.geQuote$Var2[m.acf.geQuote$Var2 == 3] <- "Low" | |
m.acf.geQuote$Var2[m.acf.geQuote$Var2 == 4] <- "High" | |
m.acf.geQuote$Var2 <- factor(m.acf.geQuote$Var2, | |
levels=unique(m.acf.geQuote$Var2), ordered=T) | |
m.acf.geQuote$Var3[m.acf.geQuote$Var3 == 1] <- "Open" | |
m.acf.geQuote$Var3[m.acf.geQuote$Var3 == 2] <- "Close" | |
m.acf.geQuote$Var3[m.acf.geQuote$Var3 == 3] <- "Low" | |
m.acf.geQuote$Var3[m.acf.geQuote$Var3 == 4] <- "High" | |
m.acf.geQuote$Var3 <- factor(m.acf.geQuote$Var3, | |
levels=unique(m.acf.geQuote$Var3), ordered=T) | |
myvalue <- format(m.acf.geQuote$value, digits=2, scientific=F) | |
p <- ggplot(m.acf.geQuote) | |
p <- p + geom_raster(aes(x=Var1, y=Var2, lable=value, fill= value)) + | |
facet_wrap(~Var3, nrow=4) + | |
ggtitle("Cross-correlation of 4 different prices of GE ticker") + | |
theme(legend.position="none") + | |
labs(fill="Correlation") + | |
geom_text(aes(Var1, Var2, label=myvalue), color="snow", size=4) + | |
xlab("") + ylab("") | |
print(p) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment