[R] xyplot: filtering out empty plots

Deepayan Sarkar deepayan.sarkar at gmail.com
Wed Jul 7 22:25:37 CEST 2010


On Tue, Jul 6, 2010 at 2:47 AM, Coen van Hasselt
<coenvanhasselt at gmail.com> wrote:
> Hello,
>
> I would like to know how I can filter out empty plots in xyplot, when
> stratifying on some variables.
>
> Example:
>
> I have a dataset in which I plot CONC ~ TIME, stratified for patient
> ID(1,2,..,100), FORM(1,2) and BOOST (1,2).
> Some patients (ID's) do not have values for all stratification
> conditions. I.e. one patient may have values for FORM=1 and BOOST=1,2,
> while others may have data on alle combinations.
>
> xyplot(CONC ~ TIME | ID + FORM + BOOST, dat=data)
>
> If I do this I also get empty plots for all the combinations for which
> I do not have data for. Is it possible for xyplot NOT to make plots
> for combinations of ID, FORM and BOOST that do not contain data ?

Lattice will only drop levels of conditioning variables that are
completely empty. For what you want, you need to create an
interaction; something like

xyplot(CONC ~ TIME | ID:FORM:BOOST, dat=data)

-Deepayan



More information about the R-help mailing list