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
Oh yes, that does indeed help. I should have thought of using "groups". And more importantly, thanks for explaining why the indexing method was not working.
I have a followup question. Suppose I want to encode two different variables within a panel: one variable encoded by plotting character and one variable encoded by symbol color (as if I could use two "groups" variables). The dataframe I discussed above also includes a variable called treatment. If I start with the existing code modified with your suggestions:
xyplot(coversage ~ dryout | year,
data = dryoutcover,
groups = block,
panel = function(x,y, ...) {
panel.lmline(x,y)
panel.superpose(x,y,
pch = 49:54,
cex = rep(2,6),
col = rep("black", 6), ...)
}
)how could I make all of the symbols of one treatment red and all of the symbols of the other black while maintaining the encodings of block by plotting character? This would be a superbly useful technique as it would allow 4 dimensional data on a single panel (maybe even 5 using a point cloud!).
Anthony
______________________________________________ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
