Created
February 7, 2012 15:21
-
-
Save ramnathv/1760199 to your computer and use it in GitHub Desktop.
Growth of $1 Chart using ggplot2
This file contains 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
# LOAD LIBRARIES | |
require(quantmod) | |
require(ggplot2) | |
# GET DATA, CONVERT TO DATA FRAMES | |
getSymbols("VBMFX", from = "1990-01-01", to = Sys.Date(), adjust = TRUE) | |
getSymbols("VFINX", from = "1990-01-01", to = Sys.Date(), adjust = TRUE) | |
vbfmx <- data.frame(VBMFX, date = index(VBMFX)) | |
vfinx <- data.frame(VFINX, date = index(VFINX)) | |
# SET PLOT THEME OPTIONS | |
plain <- opts( | |
panel.grid.major = theme_blank(), | |
panel.grid.minor = theme_blank(), | |
plot.background = theme_rect(fill = 'gray95', colour = NA), | |
panel.background = theme_blank(), | |
plot.title = theme_text(face = 'bold', hjust = 0, size = 24, vjust = 1) | |
) | |
# PLOT IT!! | |
qplot(date, VFINX.Open/VFINX.Open[1], data = vfinx, geom = 'line', colour = I('maroon')) + | |
geom_line(data = vbfmx, aes(y = VBMFX.Open/VBMFX.Open[1]), colour = 'deepskyblue3') + | |
geom_hline(yintercept = seq(1, 6, 1), colour = 'gray80') + | |
xlab('') + ylab('') + | |
opts(title = 'Cumulative Growth since 1991') + | |
plain |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment