How can I write R code that will take all columns from a single xts object and plot them on a single chart?
My xts object looks like screenshot below and I don't know while writing a code what will be the number of columns there: screenshot of xts object
I want R to take each of the columns and plot them as one of the lines on a single chart. Ideally, it should be some fancy quantmod charts (as each of columns is a price for a particular investment instrument) but even simple plot will be okay.
Additional comments.
Here is a datafile I use (csv): One Drive sharepoint link to zip file
And this is the code I have so far:
etfs_history_input <- read.zoo(file = "etfs_history.csv", sep = ",", index.column = 1, header = TRUE, FUN=as.POSIXct, tz = "Europe/Moscow", format = "%Y-%m-%d")
etfs_h <- as.xts(coredata(etfs_history_input), order.by = index(etfs_history_input))
The closest thing I managed to achieve in meeting my target output is writing this:
apply(etfs_h, 2, plot)
But result:
- plots different instruments on different charts
- doesn't show the instrument names (column titles)