[R] panel/prepanel for polar plots ala xYplot

Deepayan Sarkar deepayan at stat.wisc.edu
Wed Feb 16 21:11:53 CET 2005


On Wednesday 16 February 2005 11:11, Randall Pruim wrote:
> First a bit of background:
>
> After doing a search for a flexible polar plot function and coming up
> empty, I have begun writing one myself.  Since I am new to writing
> mid-level graphics routines, this has required some learning about
> lattice, grid and related things.
>
> I am to the point where I have a workable proof of concept, but still
> need to make some improvements.  My goal is to have something akin to
> a polar version of xYplot.  Although the particular plot I need
> requires some customization of that idea, the use of Cbind() has made
> that fairly easy.
>
> Now some questions:
>
> 1) What are the best sources of documentation for lattice/grid?  I
> have found a few things by googling, but mostly I have been reverse
> engineering code and experimenting to figure out how things work.

Why is the package documentation insufficient? There are some grid 
articles on Paul's website, and S-PLUS Trellis documentation mostly 
applies to lattice.

> 2) What is the best way to generate "axis" and labels for them?
>
>  Currently my radplot is a wrapper for xyplot that (a) turns off the
> axes and labels, and (b) calls xyplot with panel.radplot,
> prepanel.radplot, and radplot.superpose replacing the obvious things.
> I am generating the "axes" (concentric circles and peripheral labels)
> in panel.radplot, but this means that they are redrawn for each group
> when there is superposition.  Furthermore, there seems to be some
> jittering, so besides inefficiency, the result is not crisp.

If you want something that's to be done once per panel and something 
else that's to be done once per group within panel, I would suggest you 
separate out the per-group part in a function and call that multiple 
times from your panel function. An example of this is panel.dotplot, 
which essentially looks like:

function (x, y, 
          levels.fos = unique(y), 
          groups = NULL,
          ...)
{
    panel.abline(h = levels.fos)
    if (is.null(groups)) panel.xyplot(x = x, y = y, ...)
    else panel.superpose(x = x, y = y, groups = groups, 
                         panel.groups = panel.xyplot, ...)
}

This ensures that the reference lines are drawn only once per panel (and 
not once per group, which would have overwritten the dots from earlier 
groups).

>  How are axes generated in xyplot?  

In xyplot, the axes are generated separately from the panel function, 
because they are outside the panels (and the same axes are associated 
with multiple panels).  It sounds like you want something similar to 
cloud, where the axes are part of each panel. In that case, your panel 
function needs to be responsible for drawing the axes.

>  To do this correctly will I have 
> to go deeper and make a new version of trellis.skeleton or make a new
> call to it?  

I don't see why.

> If I put the code into prepanel.radplot will it be 
> executed once per panel or once per group in each panel?

The prepanel function should absolutely not do any plotting.

> 3) I'd be happy to receive any other suggestions for how to approach
> the design of a robust, formula-based (including xYplot-like options)
> radial/polar plot.  I'd also be happy to hear of any packages that
> include something heading in this direction, if they exist and I just
> didn't locate them.
>
> Thanks in advance for any assistance.
>
> ---rjp
>
> PS.  For the curioius, the plot I am designing has a function call
> like
>
>  radplot(Cbind(y,ratio)~x|g, groups=h, ...)
>
> where y is numeric and x may be numeric or a factor.  The resulting
> plot has "spokes" for each value of x with length y, the last 1 -
> min(ratio, 1/ratio) fraction of the spoke rendered differently.  This
> is similar to adding error bars to a plot in xYplot -- only in polar
> coordinates.
>
> ==============================================
>    Randall Pruim
>    Dept. of Biostatistics, University of Michigan
>
>    email:  rpruim at umich.edu
>    phone:  734.615.9825
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide!
> http://www.R-project.org/posting-guide.html




More information about the R-help mailing list