xyplot is nifty. It establishes a base plot to which layers can be added. Here's the process:
1. Obtain xts.
2. xyplot(xts). The output of this is called a trellis object.
3. You can add to trellis objects by calling the trellis object and adding a layer. This can be done a few ways. I did it as,
xyplot(xts) + as.layer(xyplot(xts2)),
which produces a plot that has xts and xts2 plotted. Layers can also be added to shade interesting portions of a plot. I'm still not great with how to implement conditions in R, so I can't do anything particularly interesting without tedious coding. Here are two plots I produced. The first is done by the standard R graphing procedures and the second with xyplot and layering.
First makes a plot(), a par(new=T) that allows a second plot() to be added to the original. It isn't hard to use but making it visually appealing requires understanding graphical parameters that I don't understand.
On the other hand, xyplot produces a trellis object that feeds into a command, asTheEconomist(), which is a part of the latticeExtra package. The plot below is for returns rather than levels, as above. The addition I want to make is to create a series of layers on this plot that show when both gas and oil returns are positive. Oh, right. Blue is NG, brown is oil. Labeling is not my focus. These layers will be partly transparent blocks of shading.
What does this chart tell us? It's hard to tell without the shading and even then, I don't think it'll look definitive. What I'm trying to see is how often returns in gas and oil are both positive or both negative. Good a starting point as any.
No comments:
Post a Comment