panel.box: Panel functions for predicted values and SE box

View source: R/gpanel.R

panel.boxR Documentation

Panel functions for predicted values and SE box

Description

With 'layer' and 'glayer' in 'latticeExtra', these functions can be used to easily generate fitted values and error boxes that have a reasonable appearance whether a plot uses 'groups' or not.

Usage

panel.box(
  x,
  y,
  se,
  lower = y - se,
  upper = y + se,
  width = if (is.numeric(x)) max(diff(sort(x)))/2 else 1/2,
  subscripts,
  ...,
  type,
  group.number,
  alpha = 0.9,
  alpha.fit = alpha,
  alpha.box = 0.3,
  col,
  col.line,
  col.symbol,
  border = F,
  font,
  fontface
)

Arguments

x, y

arguments passed by 'layer'

lower, upper

FIXME

subscripts

FIXME

group.number

FIXME

alpha

FIXME

col

FIXME

col.symbol

is used to control color when using 'groups'

border

default = FALSE for panel.band.

font

FIXME

fontface

FIXME

data

data frame to be used to add additional values of numeric variable

form

formula evaluated in data. The first term defines the variable with values to be filled in and the remaining terms define the variables to be used for grouping determining the minima and maxima within which values are added.

xpd

expansion factor to add points beyond minima and maxima. Default 1.0.

fit

fitted values of a model, generally passed through 'layer' from a call to 'xyplot': e.g. xyplot( y ~ x, data, groups = g, fit = data$yhat, lower = with(data, yhat - 2*se), upper = with(data, yhat + 2*se), subscripts = T)

dots

FIXME

Value

The 'panel.bands', 'panel.fit', and 'panel.labels' functions are invoked for their graphical effect.

Author(s)

Georges Monette georges@yorku.ca

Examples

## Not run: 
  library(spida2)
  library(latticeExtra)
  library(car)
  Prestige$Education <- cut(Prestige$education,
         breaks = c(-Inf,8,12,+Inf), labels = c('< HS','some HS','some PS'))
  Prestige$Gender <- cut(Prestige$women, breaks = c(-Inf, 10, 50, +Inf),
         labels = c('Male','Mixed','Female'))

  fit <- lm(income ~ Gender * Education, Prestige,
      na.action = na.exclude)
  pred <- with(Prestige, expand.grid(Education = levels(Education),
           Gender = levels(Gender)))
  pred <- cbind(pred, predict(fit, newdata = pred, se = TRUE))
  pred
  (p <- xyplot( fit ~ Education | Gender , pred,  
                subscripts = T, width = .5,
                fit = pred$fit,
                labels = pred$Education,
                lower = with(pred, fit - 2*se.fit),
                upper = with(pred, fit + 2*se.fit)))
  gd(3,pch = 16)
  p + layer(panel.fit(...))
  (p <- update(p + layer(panel.box(...)), ylim = c(0, 15000), 
         auto.key = list(columns= 3)))
  ###### Need to fix handling of width with factor predictor   
  p + layer(panel.labels(...))
  
# NOTE: with groups use 'glayer' instead of 'layer' 

## End(Not run)

gmonette/spida2 documentation built on Aug. 11, 2024, 7:52 p.m.