[R] Bug or feature in xyplot?

Hans Gardfjell hans at eg.umu.se
Wed Jul 31 19:57:39 CEST 2002


Thanks Deepayan,

I should of course have RTFM (or in this case RTFHP). So after looking thru
your examples under ?xyplot and ?panel.xyplot I understood what you meant,
and it was easy to write a new panel function. So here is my panel function
that gives different colors for each level of (a second) group variable (and
if the levels in fact are color names it uses them):

"panel.xycol" <-
function(x,y,subscripts,groups,...){
#Panel that plots symbols with different colors for different levels of
group
#Check if the levels are color codes - if so, use them.
cc<-all(tolower(levels(groups)) %in% colors())
for (i in 1:length(levels(groups))) {
if (cc) {
lpoints(x[groups[subscripts]==levels(groups)[i]],y[groups[subscripts]==level
s(groups)[i]],col=as.character(levels(groups)[i])) }
else {
lpoints(x[groups[subscripts]==levels(groups)[i]],y[groups[subscripts]==level
s(groups)[i]],col=i)
}}}

/hans

-----Original Message-----
From: Deepayan Sarkar [mailto:deepayansarkar at yahoo.com]
Sent: Monday, July 29, 2002 1:26 AM
To: Hans Gardfjell; r-help at stat.math.ethz.ch
Subject: Re: [R] Bug or feature in xyplot?



--- Hans Gardfjell <hans at eg.umu.se> wrote:
> Hi,
>
> Can someone of you tell me why these two simple examples works as
> "expected",
>
>   plot(c(1,1,2,2)~c(1,2,1,2),col=c(1,2,3,4),pch=c(1,2,3,4))
>
>
coplot(c(1,1,2,2)~c(1,2,1,2)|c("A","A","B","B"),col=c(1,2,3,4),pch=c(1,2,3,4
> ))
>
> but when I try it with xyplot in the lattice package it fails.
>
>
>
xyplot(c(1,1,2,2)~c(1,2,1,2)|c("A","A","B","B"),col=c(1,2,3,4),pch=c(1,2,3,4
> ))
>
> Do I have to specify colors and symbol types differently with lattice
> functions or
> is this a bug?

Depends on which part you think is unexpected. Both panels should use pch 1
and
2 (and not 3 and 4 for the second panel like coplot), which seems reasonable
enough; it starts afresh for each panel. The col isn't vectorized because
grid
doesn't support vectorized graphical parameters yet (but will do so from the
next version).

That said, from a design perspective, col and pch should not be vectors at
all
in your example. S-Plus would actually ignore vectorized col/pch etc (with a
warning) and use only the first values. Multiple graphical symbols are
supposed
to be achieved via the groups argument and panel.superpose.

Deepayan



__________________________________________________




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