[R] user coordinates and rug plots in lattice graphics

Deepayan Sarkar deepayansarkar at yahoo.com
Mon Apr 8 18:09:24 CEST 2002


--- John Fox <jfox at mcmaster.ca> wrote:
> Dear R list members,
> 
> I'd like to produce rug plots at the bottom of panels in a trellis display 
> (using the lattice package), but par("usr") doesn't return user coordinates 
> for panels, and consequently rug fails, as the following example (suggested 
> to me by Georges Monette) illustrates:
> 
>      > x <- rnorm(50)
>      > y <- rnorm(50)
>      > f <- factor(sample(c('a','b','c'),size=50, replace=T))
>      > z <- xyplot(y~x|f,
>      +        panel = function(x,y,...) {
>      +                panel.xyplot(x,y,...)
>      +                rug(x)
>      +                print(par('usr'))
>      +        })
>      > z
>      [1] 0 1 0 1
>      [1] 0 1 0 1
>      [1] 0 1 0 1
>      Warning messages:
>      1: some values will be clipped in: rug(x)
>      2: some values will be clipped in: rug(x)
>      3: some values will be clipped in: rug(x)
> 
> (R Version 1.4.1 on a Windows 2000 PC.)
> 
> This code runs properly in S-PLUS, by the way, where par("usr") returns 
> user coordinates when invoked within a panel function.

The problem arises because lattice is based on grid graphics, and conventional
R graphics do not work under grid. The way around (to get the user 
coordinates) here would be to use current.viewport()$xscale and 
current.viewport()$yscale (both should be vectors of length 2).

> I don't see a way around the problem. If I could determine the minimum 
> value of y in a panel, I could make my own rug plot. Any help would be 
> greatly appreciated.

For this, you might want to use lsegments. (This may be slow now, but should
be faster in the next release.)


> 
> Thanks,
>   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


__________________________________________________

Yahoo! Tax Center - online filing with TurboTax

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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