panel.subgroups: Panel function to display subgroups within groups within...

Description Usage Arguments Details See Also Examples

Description

This function is designed to be used as the argument to panel.groups in xyplot. It effectively adds another level of subgrouping to that implemented by the groups argument in xyplot. Useful mainly to display data and fitted lines in groups within panels.

Usage

1
2
panel.subgroups(x, y, subscripts, subgroups, subgroups.type = c("p", "l"),
  type, panel.subgroups = panel.xyplot, ...)

Arguments

x, y

coordinates of the points to be displayed

subscripts

subscripts giving indices in original data frame

subgroups

a subgrouping variable. Use a full reference, e.g. data$subvar

subgroups.type

plotting type, typically 'p' or 'l', for each level of the variable passed through the subgroups argument

panel.subgroups

function use to plot data within in each group referring to the levels of the variable passed by subgroups. Define a panel.subgroups argument in the call to xyplot and it will be used to plot the groups. See the examples below.

...

any other arguments to be passed to the panel plotting function

Details

This function is designed to be used as the argument to 'panel.groups' in 'xyplot'. It allows the plotting of points versus lines within subgroups of the data identified by the 'groups' argument in xyplot. It requires a variable to identify the subgroups. Points or lines are used within subgroups depending on 'subgroups.type' where the order is that of the levels of the 'subgroups' argument coerced as a factor, if necessary. See the examples below.

See Also

link[lattice]{panel.superpose}, link[lattice]{panel.superpose.2}, link[lattice]{panel.xyplot}

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
## Not run: 
library(car)
data(Prestige)
fit <- lm( prestige ~ (education +I(education^2)) * type, Prestige, na.action = na.omit)
pred <- expand.grid( education = seq( 6, 18, .5), type = levels( Prestige$type))
pred$prestige <- predict( fit, newdata = pred )

Prestige$what <- 'data'
pred$what <- 'fit'         # this works because 'fit' follows 'data' lexicographically

combined <- merge( Prestige, pred, all = T)

xyplot( prestige ~ education, combined,
          groups = type,
          subgroups = combined$what,  # note that a full reference to the variable is needed
          panel = panel.superpose,    # might not be necessary in future version of lattice
          panel.groups = panel.subgroups)  # uses the default of points for the first level of 'what'
                                           # and lines for the second level

## Using the argument 'panel.subgroups' instead of the default 'panel.xyplot'
## Note that panel.subgroups is a function (this one) and also an argument that
## is a function passed to the function. The argument defines the action to
## be taken within each level of 'what'

xyplot( prestige ~ education, combined,
        groups = type,
        subgroups = combined$what,  # note that a full reference to the variable is needed
        panel = panel.superpose,    # might not be necessary in future version of lattice
        panel.groups = panel.subgroups,
        panel.subgroups = function( x, y, subgroup, type, ...) {
             # note that you need to include 'type' among the arguments
             # if you need to prevent it from being passed through '...'
             # When called, this function will be passed arguments
             # subgroup, subgroup.number, subscripts, and type from
             # subgroups.type.
       if ( subgroup == 'data' ) {
              panel.xyplot( x, y, ...)
              panel.lines( dell(x,y), ...)
       } else {
              panel.lines( x,y, ...)
       }
   })

## End(Not run)

gmonette/yscs documentation built on May 17, 2019, 7:28 a.m.