[R] panel function in a conditioned lattice graphic

Anthony Darrouzet-Nardi anthony at darrouzet-nardi.net
Mon May 31 02:55:53 CEST 2004


>On Saturday 29 May 2004 20:18, Anthony Darrouzet-Nardi wrote:
>
>>  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!).
>
>I would use the same construct, forming a new grouping variable and
>using suitably modified pch and col arguments:
>
>xyplot(coversage ~ dryout | year, data=dryoutcover, cex = 2,
>        groups = interaction(block, treatment),
>        pch = rep(49:54, 2),
>        col = rep(c('red', 'black'), each = 5))
>
>(2 and 5 being the nlevels() of treatment and block respectively). You
>would also probably prefer factor(year) rather than year.
>
>Deepayan

Bravo! That works wonderfully. I foresee myself using this method a 
lot. For the record, nlevels(block) is 6, so each = 6 in the col 
argument for the final version. Makes sense to switch to factor(year) 
as well (like the barley data).

Thanks for your help,

Anthony




More information about the R-help mailing list