Achim,

Thank you for your response, and for your work on the zoo package in
general.  Also, that implementation of the color scheme looks great.

Frankly, I can't remember exactly what I was originally trying to
accomplish for this particular problem, but I think that your suggestion of
reviewing the plotting section of the zoo vignette would solve the problem.
 Calculating the colors ahead of time and passing them in as a list is
great solution that I didn't know was possible.

I still have some lingering questions about the panel function, which has
been one of those things in R that I would like to understand better.

Using your example, I would like to be able to pass in an additional
variable to make each set of hues like this:

mycol <- function(i, v)  hcl(
  h = ifelse(i > 0, v, 0),
  c = 80 * abs(i)^1.5,
  l = 90 - 60 * abs(i)^1.5)

mypanel <- function(x, y, v, ...) {
  lines(x, y, col = "gray")
  points(x, y, col = mycol(y / max(abs(y)), v), pch = 19)
}
plot(zobj, panel = mypanel, v=0)
plot(zobj, panel = mypanel, v=50)
plot(zobj, panel = mypanel, v=100)
plot(zobj, panel = mypanel, v=150)


This runs, but generates warnings. I was trying to find the right way to
pass additional arguments to panel.

I was trying things like this:
plot(zobj, panel = mypanel(x, y, v=150))
plot(zobj, panel = mypanel(..., v=150))


I was surprised at how many ways I could call panel, but how unpredictable
(to me) the results were!  Things that I didn't think would work were ok,
and other things that seemed correct would threw errors.

If you have some insight I would like to hear it, but this isn't that
important because there are obviously other approaches for making the same
/ similar output.




Thank you,
   Gene Leynes
_____________________________________________
*Data Scientist*
*http://www.linkedin.com/in/geneleynes
*
<http://goog_598053156>*http://geneorama.com/ <http://geneorama.com/%20>*



On Tue, Jul 31, 2012 at 3:24 AM, Achim Zeileis <Achim.Zeileis@uibk.ac.at>wrote:

> On Sun, 29 Jul 2012, Gene Leynes wrote:
>
>  I would really like some help with understanding the panel function, in
>> zoo.  Thank you.
>>
>
> 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
>
>  R 15.1 and zoo 1.7-7.
>>
>>
>> library(zoo)
>> x = seq(0,3*pi,length.out=100)
>> y = sin(x)
>> zobj = zoo(y, x)
>>
>> ##############################**#############################
>> ## EXAMPLE 1 - GLOBAL ARGUMENT
>> ## This panel function works
>> ## But, it relies on mycol, which is a global variable
>> ##############################**#############################
>> palette(rainbow(100))
>> mypanel_v1 = function(x, y, ...){
>> lines(x, y, lty=2, col='grey')
>> points(x, y, col=mycol, pch=16)
>> }
>> mycol = round((y - min(y)) / (max(y) - min(y)) * 99) + 1
>> plot(zobj, panel=mypanel_v1)
>>
>>
>> ##############################**#############################
>> ## EXAMPLE 2 - PASSING IN MY_COLOR AS PARAM (WITH WARNING)
>> ## How would I make the color argument modular?
>> ## This works, but throws errors
>> ## What is the best way to to this?
>> ##############################**#############################
>> palette(rainbow(100))
>> mypanel_v2 = function(x, y, MY_COLOR, ...){
>> lines(x, y, lty=2, col='grey')
>> points(x, y, col=MY_COLOR, pch=16)
>>
>> ## By the way I also tried a variety of strategies
>> ## like this:
>> # points(..., col=MY_COLOR, pch=16)
>> ## but I get got warnings about passing in pch and col
>> ## more than once, and "matching multiple arguments".
>>
>> ## The col value has the length of number of zoo
>> ## objects rather than the number of points in each
>> ## column....
>> }
>> mycol = round((y - min(y)) / (max(y) - min(y)) * 50) + 1
>> plot(zobj, panel=mypanel_v2, MY_COLOR = mycol)
>>
>>
>>
>> Thank you,
>>   Gene Leynes
>> ______________________________**_______________
>> *Data Scientist*
>> *http://www.linkedin.com/in/**geneleynes<http://www.linkedin.com/in/geneleynes>
>> *
>> <http://goog_598053156>*http:/**/geneorama.com/ <http://geneorama.com/> <
>> http://geneorama.com/%20>*
>>
>>         [[alternative HTML version deleted]]
>>
>> ______________________________**________________
>> R-help@r-project.org mailing list
>> https://stat.ethz.ch/mailman/**listinfo/r-help<https://stat.ethz.ch/mailman/listinfo/r-help>
>> PLEASE do read the posting guide http://www.R-project.org/**
>> posting-guide.html <http://www.R-project.org/posting-guide.html>
>> and provide commented, minimal, self-contained, reproducible code.
>>
>>

	[[alternative HTML version deleted]]

