lattice: problem with cex argument.

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

lattice: problem with cex argument.

ernesto-4
Hi,

I'm trying to plot a "bubbles" plot wich I do with the cex argument. The
problem is that it looks like it fails the conditioning and reuses the
first 100 elements of the cex vector. See the code

x <- rep(rep(1:10,10),2)
y <- rep(rep(c(1:10),rep(10,10)),2)
z <- rep(1:2,c(100,100))
w <- rpois(200,l=1)
xyplot(y~x|z, cex=w)

the plot has the same pattern in both sides but the data are different, see

> tapply(w,z,summary)
$"1"
   Min. 1st Qu.  Median    Mean 3rd Qu.    Max.
   0.00    0.00    1.00    0.99    1.00    4.00

$"2"
   Min. 1st Qu.  Median    Mean 3rd Qu.    Max.
   0.00    0.00    1.00    0.95    2.00    4.00

or the plots

par(mfrow=c(1,2))
tapply(w,z,hist)

and

xyplot(w~x|y*z)

Is this a feature or a bug ?

Regards

EJ

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Reply | Threaded
Open this post in threaded view
|

Re: lattice: problem with cex argument.

Deepayan Sarkar
On 3/31/06, ernesto <[hidden email]> wrote:

> Hi,
>
> I'm trying to plot a "bubbles" plot wich I do with the cex argument. The
> problem is that it looks like it fails the conditioning and reuses the
> first 100 elements of the cex vector. See the code
>
> x <- rep(rep(1:10,10),2)
> y <- rep(rep(c(1:10),rep(10,10)),2)
> z <- rep(1:2,c(100,100))
> w <- rpois(200,l=1)
> xyplot(y~x|z, cex=w)
>
> the plot has the same pattern in both sides but the data are different, see
>
> > tapply(w,z,summary)
> $"1"
>    Min. 1st Qu.  Median    Mean 3rd Qu.    Max.
>    0.00    0.00    1.00    0.99    1.00    4.00
>
> $"2"
>    Min. 1st Qu.  Median    Mean 3rd Qu.    Max.
>    0.00    0.00    1.00    0.95    2.00    4.00
>
> or the plots
>
> par(mfrow=c(1,2))
> tapply(w,z,hist)
>
> and
>
> xyplot(w~x|y*z)
>
> Is this a feature or a bug ?

Feature. The rule is simple: everything not relevant to the high level
function is sent to the panel function unchanged (this is normally
used to specify arguments of the panel function in the high level
call). Nothing outside the formula is `conditioned'. The panel
function will also be given, if requested, a 'subscripts' argument
that provides indices of the rows in the original data used in that
panel. Combining these you can condition anything you want inside the
panel function, e.g.

xyplot(y~x|z, cex = w,
       panel = function(x, y, ..., cex, subscripts) {
           panel.xyplot(x, y, ..., cex = cex[subscripts])
       })

which is probably what you wanted. It took me a while to figure this
out, but I think this feature of the Trellis design solves very
elegantly a problem that would have been very hard to tackle directly.

Deepayan

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Reply | Threaded
Open this post in threaded view
|

lattice, xyplot, lend=1, type="h"

Andy Bunn
Is there is a way to make square bars in xyplot with type="h"?

dat <- data.frame(foo = rep(1:10,2), bar = rep(1:10,2))
xyplot(foo~bar, data = dat, type="h",lwd=20)

Thanks! Andy

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Reply | Threaded
Open this post in threaded view
|

Re: lattice, xyplot, lend=1, type="h"

Sundar Dorai-Raj


Andy Bunn wrote:
> Is there is a way to make square bars in xyplot with type="h"?
>
> dat <- data.frame(foo = rep(1:10,2), bar = rep(1:10,2))
> xyplot(foo~bar, data = dat, type="h",lwd=20)
>
> Thanks! Andy
>


Hi, Andy,

I don't think lattice supports this since it uses
trellis.par.get("plot.line") to determine the drawing parameters.
However, you can use the grid package.

library(lattice)
library(grid)
dat <- data.frame(foo = rep(1:10,2), bar = rep(1:10,2))
xyplot(foo ~ bar, data = dat,
        panel = function(x, y, ...) {
         ## hacked from lattice::lplot.xy
         ylim <- current.viewport()$yscale
         zero <- if (ylim[1] > 0)
             ylim[1]
         else if (ylim[2] < 0)
             ylim[2]
         else 0
         gp <- gpar(lty = 1, col = "blue", lwd = 20,
                    alpha = 1, lineend = "square")
         grid.segments(x0 = x, x1 = x, y0 = y, y1 = zero,
                       gp = gp, default.units = "native")
        })

HTH,

--sundar

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Reply | Threaded
Open this post in threaded view
|

Re: lattice, xyplot, lend=1, type="h"

Deepayan Sarkar
On 3/31/06, Sundar Dorai-Raj <[hidden email]> wrote:

>
>
> Andy Bunn wrote:
> > Is there is a way to make square bars in xyplot with type="h"?
> >
> > dat <- data.frame(foo = rep(1:10,2), bar = rep(1:10,2))
> > xyplot(foo~bar, data = dat, type="h",lwd=20)
> >
> > Thanks! Andy
> >
>
>
> Hi, Andy,
>
> I don't think lattice supports this since it uses
> trellis.par.get("plot.line") to determine the drawing parameters.
> However, you can use the grid package.
>
> library(lattice)
> library(grid)
> dat <- data.frame(foo = rep(1:10,2), bar = rep(1:10,2))
> xyplot(foo ~ bar, data = dat,
>         panel = function(x, y, ...) {
>          ## hacked from lattice::lplot.xy
>          ylim <- current.viewport()$yscale
>          zero <- if (ylim[1] > 0)
>              ylim[1]
>          else if (ylim[2] < 0)
>              ylim[2]
>          else 0
>          gp <- gpar(lty = 1, col = "blue", lwd = 20,
>                     alpha = 1, lineend = "square")
>          grid.segments(x0 = x, x1 = x, y0 = y, y1 = zero,
>                        gp = gp, default.units = "native")
>         })

Right. R 2.3.0 should have better support for grid parameters (that
are not anticipated by lattice), where both of the following should
work:

xyplot(foo~bar, data = dat, type="h",lwd=20,
       par.settings = list(grid.pars = list(lineend = 1)))

xyplot(foo~bar, data = dat, type="h",lwd=20, lineend = 1)

The first solution should already work in the current alpha of R
2.3.0, I'm testing the second one now.

Deepayan

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html