[R] arrow plots
Paul Murrell
p.murrell at auckland.ac.nz
Sat Dec 19 20:08:02 CET 2009
Hi
Deepayan Sarkar wrote:
> On Wed, Dec 9, 2009 at 10:08 AM, Cable, Samuel B Civ USAF AFMC
> AFRL/RVBXI <Samuel.Cable at hanscom.af.mil> wrote:
>> Thanks, all, for the help. Much obliged. I realize now that I should
>> have said that I am using lattice graphics. The par() command has not
>> been helpful in convincing lattice to plot outside of the default
>> window. Any other advice is appreciated. Thanks again.
>
> [Sorry for the late reply, I missed your mail the first time around.]
>
> I think you need the 'legend' functionality. A naive example is:
>
> arrowFun <- function(x = c(0.25, 0.75), ...)
> {
> require(grid)
> linesGrob(x = x, y = 0.5, default.units = "npc",
> arrow = arrow(...))
> }
>
> xyplot(1 ~ 1, legend = list(top = list(fun = arrowFun, args = list(x =
> c(0.1, 0.5)))))
> xyplot(1 ~ 1, legend = list(top = list(fun = arrowFun(type = "closed"))))
>
>
> Your actual requirements would be more complicated because (1) your
> grob will be more complicated (but see draw.key and draw.colorkey for
> examples) and (2) your legend has to get resized in sync with the
> plot. The second part is more complicated, and the simplest approach
> would be to fix the absolute size of your panels (see ?print.trellis).
> Of course the easiest solution would be to draw your arrow inside the
> panel.
Or you could draw the arrow from within the context of the panel, BUT
locate the drawing outside the panel. It's not clear exactly what you
need, but perhaps something like this ...
xyplot(1:10 ~ 1:10)
trellis.focus("panel", 1, 1, clip.off=TRUE)
grid.segments(x0=unit(1, "native"),
y0=unit(1, "npc") + unit(1.5, "lines"),
x1=unit(5, "native"),
y1=unit(1, "npc") + unit(1.5, "lines"),
arrow=arrow(type="closed"))
trellis.unfocus()
... where the x-locations of the line segment are relative to the x-axis
scale on the panel, but the y-locations place it outside the panel (a
similar call to grid.text() would work for the labelling) gives you some
ideas (?)
Paul
> -Deepayan
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
--
Dr Paul Murrell
Department of Statistics
The University of Auckland
Private Bag 92019
Auckland
New Zealand
64 9 3737599 x85392
paul at stat.auckland.ac.nz
http://www.stat.auckland.ac.nz/~paul/
More information about the R-help
mailing list