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.
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.
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
-----------------------------------------------------
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Deepayan Sarkar
2002-Apr-08 16:09 UTC
[R] user coordinates and rug plots in lattice graphics
--- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Dear Deepayan,
Using current.viewport()$yscale does the trick -- for example:
x <- rnorm(50)
y <- rnorm(50)
f <- factor(sample(c('a','b','c'),size=50,
replace=T))
par(tck = 0.03)
z <- xyplot(y~x|f,
panel = function(x,y,...) {
panel.xyplot(x,y,...)
ymin <- current.viewport()$yscale[1]
lpoints(x, rep(ymin, length(x)), pch="|",
col='black')
})
z
Thank you very much,
John
At 09:09 AM 4/8/2002 -0700, Deepayan Sarkar wrote:
>--- 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.)
-----------------------------------------------------
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._