[R] Lattice Cloud()-Plot with the same color for different groups

Charilaos Skiadas cskiadas at gmail.com
Tue May 27 12:14:33 CEST 2008


On May 27, 2008, at 3:10 AM, Hofert Marius wrote:

> Hi,
>
> Consider the following cloud()-plot consisting of two lines:
>
> library(lattice)
> mydata=data.frame(x=rep(1:4,2),y=rep(1:2,each=4),z=c(1,2,3,4,4,3,2,1))
> cloud(z~x*y,data=mydata,groups=y,type=rep("l",2))
>
> Now, I would like to change the color of the lines (still works fine):
>
> cloud(z~x*y,data=mydata,groups=y,type=rep("l",2),col=c(1,2))
>
> But when I change the color to be the same for each group, i.e. for  
> both lines, then the groups are "combined" by a line:
>
> cloud(z~x*y,data=mydata,groups=y,type=rep("l",2),col=c(2,2))
>
> How do I remove this group-combining line so that the cloud()-plot  
> looks like in the first plot above, but with the same colors for  
> each line? Assigning the color in the data.frame mydata also did  
> not help.

Interesting behaviour, I would consider it a bug. Try this:

cloud(z~x*y,data=mydata,groups=y,type=rep("l",2),par.settings=list 
(superpose.line=list(col=c(2,3))), panel=function(x,y,z,  
groups=groups, ...) {
	for (i in unique(groups)) {
	sb <- groups==i
	panel.cloud(x[sb],y[sb],z[sb], col=trellis.par.get("superpose.line") 
$col[i], ... )
	}
})

> Thanks!
>
> marius

Haris Skiadas
Department of Mathematics and Computer Science
Hanover College



More information about the R-help mailing list