I have an xts object of data through time:
> head(vixData[,2:8], 5)
F1 F2 F3 F4 F5 F6 F7
2009-06-08 30.25 32.00 31.70 31.75 31.65 30.85 29.95
2009-06-09 29.10 30.95 30.95 31.15 31.10 30.40 29.45
2009-06-10 29.10 31.20 31.30 31.45 31.50 30.75 29.95
2009-06-11 28.10 30.60 30.75 30.90 31.00 30.20 29.25
2009-06-12 28.35 29.95 30.10 30.45 30.50 29.90 29.05
The F1-F7 will form a curve, like below:
plot(1:7, vixData[399,2:8], type = 'o', pch = 6)
I would like to do this through time. The rows of the xts object are the values for each day, which generate the curve. I am looking to generate something like this:
I am trying to use plot3D, and surf3D, but I cannot understand the documentation, or how to convert the dataframe into what surf3D wants. Any ideas or better package suggestions?
I have tried to use lattice::wireframe as suggested in the comments, but I get the following:
curveData <- vixData[-(1:100),2:8, drop = FALSE]
wireframe(t(as.matrix(curveData)), shade = TRUE, scales = list(arrows = FALSE),
aspect = c(0.65, 0.25), drape = TRUE,
zlab = "Level", xlab = "Contract", ylab = "Time", panel.aspect = .75)
This looks pretty close!! But - I am hoping I could maybe rotate the image and extend it some along the 'Time' axis, to give better clarity. Are there parameters for that? I cannot find it in the documentation.
plot( X , Y ) creates a 2-D line plot of the data in Y versus the corresponding values in X . To plot a set of coordinates connected by line segments, specify X and Y as vectors of the same length. To plot multiple sets of coordinates on the same set of axes, specify at least one of X or Y as a matrix.
Define the x-axis and corresponding y-axis values as lists. Plot them on canvas using .plot() function. Give a name to x-axis and y-axis using .xlabel() and .ylabel() functions. Give a title to your plot using .title() function.
The different types of 2D plots covered in this chapter are: Matplotlib Line Plot. Matplotlib Scatter Plot. Matplotlib Bar Plot.
The source file of chartSeries3d should help. Also, you may be interested in the
source("http://www.quantmod.com/examples/chartSeries3d/chartSeries3d.alpha.R")
library("xts")
data("sample_matrix")
chartSeries3d0( as.xts( sample_matrix ), col=c("lightblue","blue"))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With