[R] user coordinates and rug plots in lattice graphics

John Fox jfox at mcmaster.ca
Mon Apr 8 23:41:54 CEST 2002


Dear Paul,

At 08:53 AM 4/9/2002 +1200, Paul Murrell wrote:

> > Using current.viewport()$yscale does the trick -- for example:
>
>
>One note of warning about this approach -- this is poking around in the
>internal structure of grid viewports, which are not guaranteed to stay that
>way.  This is not your fault of course because I have failed to supply
>decent (or any) support for querying grid's coordinate system state :)
>
>OTOH, there is a "better" way to do this -- at least, there is a way to do
>this which is more inkeeping with grid's philosophy.  If you want the rug
>lines anchored at the bottom of the plot region, the easy way to specify
>that is to use grid's "npc" coordinates -- bottom-left = (0, 0) and
>top-right = (1, 1).  Furthermore, you could draw the rug lines as actual
>line segments and make use of grid's other coordinate systems to control the
>height of the rug lines properly.  Here are a couple of alternative xyplot
>calls to show what I mean ...
>
>      # rug lines are 3mm high
>      xyplot(y~x|f,
>             panel = function(x,y,...) {
>               panel.xyplot(x,y,...)
>               grid.segments(x, unit(0, "npc"), x, unit(3, "mm"),
>                             default.units="native")
>          })
>      # rug lines are 1/20th of the height of the plot
>      xyplot(y~x|f,
>             panel = function(x,y,...) {
>               panel.xyplot(x,y,...)
>               grid.segments(x, unit(0, "npc"), x, unit(0.05, "npc"),
>                             default.units="native")
>          })
>
>... of course, the downside is that you have to encounter the raw grid
>functions to do this.

This is exactly what I wanted. I'll just encapsulate the call to 
grid.segments in an lrug function.

Thank you,
  John
-----------------------------------------------------
John Fox
Department of Sociology
McMaster University
Hamilton, Ontario, Canada L8S 4M4
email: jfox at mcmaster.ca
phone: 905-525-9140x23604
web: www.socsci.mcmaster.ca/jfox
-----------------------------------------------------

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list