[R] panel function in a conditioned lattice graphic

Deepayan Sarkar deepayan at stat.wisc.edu
Sat May 29 23:33:14 CEST 2004


On Saturday 29 May 2004 15:24, Anthony Darrouzet-Nardi wrote:
> I'm trying to use plotting character to encode the variable "block"
> from my dataset in a conditioned lattice graphic (R 1.9.0 on Mac OS
> 10.3.3). The data I'm using is the dataframe "dryoutcover" which is
> here (4k):
>
> http://anthony.darrouzet-nardi.net/downloads/dryoutcover.Rdata
>
> The code that generates my graphic almost correctly is as follows:
>
> xyplot(coversage ~ dryout | year,
> 	data=dryoutcover,
> 	panel = function(x,y) {
> 		panel.lmline(x,y)
> 		one <- dryoutcover$block==1
> 		two <- dryoutcover$block==2
> 		thr <- dryoutcover$block==3
> 		fou <- dryoutcover$block==4
> 		fiv <- dryoutcover$block==5
> 		six <- dryoutcover$block==6
> 		grid.points(x[one], y[one], pch=49)
> 		grid.points(x[two], y[two], pch=50)
> 		grid.points(x[thr], y[thr], pch=51)
> 		grid.points(x[fou], y[fou], pch=52)
> 		grid.points(x[fiv], y[fiv], pch=53)
> 		grid.points(x[six], y[six], pch=54)
> 		}
> 	)
>
> The only thing wrong is that this does not correctly encode blocks 5
> and 6, which only appear in the third year of the study, 2003 (the
> third panel of the graphic). It instead labels blocks 5 and 6 as
> blocks 1 and 2 as if another year had started over (but on the same
> panel). For example, the point farthest to the right in the third
> panel says "2" when I want it to say "6." When I do not condition by
> year, it correctly displays blocks 5 and 6.
>
> How can I correct this in the conditioned graphic?

This probably happens because things like `one <- dryoutcover$block==1` 
are logical vectors as long as the total number of rows in the data 
frame, whereas x and y (which you subset using x[one], y[one]) are 
shorter (only those rows for a particular year). Consequently, the 
vector you are indexing and the indexing vector are not comparable.

I would suggest you use the feature meant for this sort of display, 
namely as:

xyplot(coversage ~ dryout | year, 
       data=dryoutcover, groups = block, pch = c(49:54))

Hope that helps,

Deepayan




More information about the R-help mailing list