Hi all, I am trying to produce some panels with dots in an X/Y plane where the diameter of the dots indicates a Z value (like e.g. earthquake maps where dot sizes indicate magnitudes and X/Y the location). This works fine with xyplot, e.g.: xyplot(1:3~1:3,cex=1:3,pch=16) However, when I do this with a panel variable, e.g.: x<-rep(1:3,5) y <- rep(1:3,5) sz <- rep(1:5,each=3) grp <- factor(rep(1:5,each=3)) xyplot(y~x | grp , cex=sz) then sz in the cex argument is not applied per group as I would expect. Same for other arguments like col. Is this really the intended behaviour? How can I achieve what I want, i.e., that the cex argument is different for the different levels of grp? Thank you for your help Pascal Niklaus
Is this what you want?
xyplot(y~x | grp,
panel = function(x, y, ...){
panel.xyplot(x, y, cex = 1:3, pch = 19, col = 2:5)
})
On Tue, Sep 23, 2008 at 10:27 AM, Pascal A. Niklaus <pniklaus at ethz.ch>
wrote:> Hi all,
>
> I am trying to produce some panels with dots in an X/Y plane where the
> diameter of the dots indicates a Z value (like e.g. earthquake maps where
dot
> sizes indicate magnitudes and X/Y the location).
>
> This works fine with xyplot, e.g.:
>
> xyplot(1:3~1:3,cex=1:3,pch=16)
>
> However, when I do this with a panel variable, e.g.:
>
> x<-rep(1:3,5)
> y <- rep(1:3,5)
> sz <- rep(1:5,each=3)
> grp <- factor(rep(1:5,each=3))
> xyplot(y~x | grp , cex=sz)
>
> then sz in the cex argument is not applied per group as I would expect.
Same
> for other arguments like col.
>
> Is this really the intended behaviour?
>
> How can I achieve what I want, i.e., that the cex argument is different for
> the different levels of grp?
>
> Thank you for your help
>
> Pascal Niklaus
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
--
Henrique Dallazuanna
Curitiba-Paran?-Brasil
25? 25' 40" S 49? 16' 22" O
> I am trying to produce some panels with dots in an X/Y plane where the > diameter of the dots indicates a Z value (like e.g. earthquake mapswhere dot> sizes indicate magnitudes and X/Y the location). > > This works fine with xyplot, e.g.: > > xyplot(1:3~1:3,cex=1:3,pch=16) > > However, when I do this with a panel variable, e.g.: > > x<-rep(1:3,5) > y <- rep(1:3,5) > sz <- rep(1:5,each=3) > grp <- factor(rep(1:5,each=3)) > xyplot(y~x | grp , cex=sz) > > then sz in the cex argument is not applied per group as I would expect.Same> for other arguments like col. > > Is this really the intended behaviour? > > How can I achieve what I want, i.e., that the cex argument is differentfor> the different levels of grp?Within a panel function, packet.number tells you what the levels of each conditioning factor are. Try something like this: #x,y,grp as above mypanelfn <- function(...) panel.xyplot(cex=packet.number(), ...) xyplot(y~x | grp , panel=mypanelfn) Regards, Richie. Mathematical Sciences Unit HSL ------------------------------------------------------------------------ ATTENTION: This message contains privileged and confidential inform...{{dropped:20}}
xyplot will pass a vector of indices through the subscripts argument
to the panel so try this:
xyplot(y ~ x | grp, panel = function(x, y, subscripts, ...) {
panel.xyplot(x, y, cex = sz[subscripts], ...)
}
)
On Tue, Sep 23, 2008 at 9:27 AM, Pascal A. Niklaus <pniklaus at ethz.ch>
wrote:> Hi all,
>
> I am trying to produce some panels with dots in an X/Y plane where the
> diameter of the dots indicates a Z value (like e.g. earthquake maps where
dot
> sizes indicate magnitudes and X/Y the location).
>
> This works fine with xyplot, e.g.:
>
> xyplot(1:3~1:3,cex=1:3,pch=16)
>
> However, when I do this with a panel variable, e.g.:
>
> x<-rep(1:3,5)
> y <- rep(1:3,5)
> sz <- rep(1:5,each=3)
> grp <- factor(rep(1:5,each=3))
> xyplot(y~x | grp , cex=sz)
>
> then sz in the cex argument is not applied per group as I would expect.
Same
> for other arguments like col.
>
> Is this really the intended behaviour?
>
> How can I achieve what I want, i.e., that the cex argument is different for
> the different levels of grp?
>
> Thank you for your help
>
> Pascal Niklaus
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
On 9/23/08, Pascal A. Niklaus <pniklaus at ethz.ch> wrote:> Hi all, > > I am trying to produce some panels with dots in an X/Y plane where the > diameter of the dots indicates a Z value (like e.g. earthquake maps where dot > sizes indicate magnitudes and X/Y the location). > > This works fine with xyplot, e.g.: > > xyplot(1:3~1:3,cex=1:3,pch=16) > > However, when I do this with a panel variable, e.g.: > > x<-rep(1:3,5) > y <- rep(1:3,5) > sz <- rep(1:5,each=3) > grp <- factor(rep(1:5,each=3)) > xyplot(y~x | grp , cex=sz) > > then sz in the cex argument is not applied per group as I would expect. Same > for other arguments like col. > > Is this really the intended behaviour?Yes. Graphical arguments like 'cex' get passed to the panel function directly, which needs to deal with it appropriately.> How can I achieve what I want, i.e., that the cex argument is different for > the different levels of grp?Write your own panel function that extracts the appropriate subset of 'cex'. xyplot(y~x | grp , cex=sz, panel = function(x, y, cex, subscripts, ...) { panel.xyplot(x, y, cex = cex[subscripts], subscripts = subscripts, ...) }) -Deepayan
On Tue, Sep 23, 2008 at 8:27 AM, Pascal A. Niklaus <pniklaus at ethz.ch> wrote:> Hi all, > > I am trying to produce some panels with dots in an X/Y plane where the > diameter of the dots indicates a Z value (like e.g. earthquake maps where dot > sizes indicate magnitudes and X/Y the location). > > This works fine with xyplot, e.g.: > > xyplot(1:3~1:3,cex=1:3,pch=16) > > However, when I do this with a panel variable, e.g.: > > x<-rep(1:3,5) > y <- rep(1:3,5) > sz <- rep(1:5,each=3) > grp <- factor(rep(1:5,each=3)) > xyplot(y~x | grp , cex=sz) > > then sz in the cex argument is not applied per group as I would expect. Same > for other arguments like col. > > Is this really the intended behaviour?You might find this easier to do with ggplot2: install.packages("ggplot2") library(ggplot2) qplot(x, y, size = sz, facets = . ~ grp) ggplot2 also automatically scales the size and provides a legend. Hadley -- http://had.co.nz/