0

I am trying to plot multiple different xts objects in separate graphs as well as in a single graph. I have found that I cannot use ggplot2 because with all of my xts objects, the date column is in column 0 and I don't know how to name column 0. Therefore, I am unable to specify my aes()in the function. I will give an example of the SP500 returns below that I turned into an xts and made monthly. I got the data from Yahoo Finance (under the ticker "^GSPC") and imported it from excel.

library(readxl) 
SP500.1 = read_excel("~/Documents/Thesis/Data/^GSPC-S&P-Thesis.xlsx")

z <- read.zoo(SP500.1)
SP500ts <- as.xts(z)

SP500 = window(SP500ts, start=start.date, end=end.date)

I also found that when I use the Plot() function, my RStudio is not responding to the coding, and gives me a plot with two Y axis and no axis titles even when I use this code:

plot(SP500,
     main="SP500",
     ylab="Closing Price", 
     xlab="Date",
     type="l",
     col="Black",
     axes= FALSE)

Any advice would be greatly appreciated. Thanks, E

ERV
  • 5
  • 2
  • 1
    Please provide a _reproducible_ example. See https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example – Axeman Dec 04 '19 at 00:01
  • Related: https://stackoverflow.com/questions/43345388/plotting-an-xts-object-using-ggplot2 – Axeman Dec 04 '19 at 00:02
  • several options: 1. use tidyquant for tidyverse compatibility between quantmod and ggplot2. 2. transform xts object into data.frame and plot with ggplot2. 3. use package rtsplot to plot xts objects with base graphics. – phiver Dec 04 '19 at 09:14

0 Answers0