Skip to content
Prev 301803 / 398503 Next

Zoo panel function

On Sun, 29 Jul 2012, Gene Leynes wrote:

            
Have you looked at ?plot.zoo. Some of the features you ask about are 
explained there. In particular, it is explained that arguments like col, 
lty, etc. are expanded to the number of series. See also the "Plotting" 
section of vignette("zoo", package = "zoo").

In your case you want the color selection based on the response anyway, so 
you could do something like

mycol <- function(i) hcl(
   h = ifelse(i > 0, 260, 0),
   c = 80 * abs(i)^1.5,
   l = 90 - 60 * abs(i)^1.5
)
mypanel <- function(x, y, ...) {
   lines(x, y, col = "gray")
   points(x, y, col = mycol(y / max(abs(y))), pch = 19)
}
plot(zobj, panel = mypanel)

In case of a univariate series, you could also do plot(time(zobj), 
coredata(zobj), ...) and then use the usual base plot arguments.

(The above uses a diverging color scheme for selecting a color based on 
the value of the response. The underlying ideas are explained in Zeileis, 
Hornik, Murrell (2009). Escaping RGBland: Selecting Colors for Statistical 
Graphics. Computational Statistics & Data Analysis, 53, 3259-3270. 
doi:10.1016/j.csda.2008.11.033)

hth,
Z