How can I scale symbol size by a data attribute in R lattice?

32 Views Asked by At

I would like to scale symbol size by a data attribute using Lattice. In the example, I am conditioning on Month. There are two groups ('Ellipse'), each has three x-y observations made at Hours 1,2, and 3. It's a point & line graph, and I want to make the symbols for each Ellipse increment in size according to Hour, to indicate the direction in which time is incrementing. In the xyplot code below, I have added 'cex=d$Hour', but this just assigns different symbol sizes to the two Ellipses.

d <- data.table(expand.grid(Hour=1:3, Month=1:3, Ellipse=1:2))
d[, x := c(rnorm(9, mean=1, sd=1),rnorm(9, mean=2, sd=1.5))]
d[, y := c(rnorm(9, mean=1, sd=1),rnorm(9, mean=2, sd=2))]

xyplot(y ~ x|Month, d, type=c('l','p'), group = Ellipse,
    cex = d$Hour,
    auto.key=list(title="Ellipse", corner=c(0.8,0.8)))

Example showing symbol size scaled by Ellipse instead of Hour

0

There are 0 best solutions below