Learn R Programming

agridat (version 1.12)

desplot: Plot the layout/data of a field experiment

Description

Plot the layout/data of a field experiment

Usage

desplot(form=formula(NULL ~ x + y), data,
  num, col, text, out1, out2,
  col.regions=RedGrayBlue, col.text=NULL, text.levels=NULL,
  out1.gpar=list(col = "black", lwd = 3),
  out2.gpar=list(col = "yellow", lwd = 1, lty = 1),
  at, ticks=FALSE, flip=FALSE, main, xlab, ylab,
  shorten="abb", show.key=TRUE, key.cex, cex=0.4, strip.cex=0.75, ...)

Arguments

form

A formula like yield~x*y|location

data

A data frame

num

The column of the data to use for plotting numbers

col

Column of the data for the color of the number

text

Column to use for text labels

out1

Column to use for outlining

out2

Column to use for outlining

col.regions

Colors for regions

col.text

Colors for text strings

text.levels

Character strings to use instead of default 'levels'

out1.gpar

A list of graphics parameters for outlining. Can either be an ordinary list() or A call to gpar() from the grid package.

out2.gpar

Second level of outlining.

at

Breakpoints for the color ribbon

ticks

If TRUE, show tick marks row/column

flip

If TRUE, vertically flip the image

main

Main title

xlab

Label for x axis

ylab

Label for y axis

shorten

Method for shortening text in the key

show.key

If TRUE, show the key

cex

Expansion factor for text/number in each cell

key.cex

Left legend cex

strip.cex

Strip cex

...

Other

Details

Note, not all lattice parameters are passed down to xyplot, but it is possible to make almost any change to the plot by assigning the desplot object to a variable and then edit the object by hand or use update to modify the object. Then print it manually. See the first example below.

Ryder (1981) discusses the need to examine the layout of the experiment design, and not just the data. This function provides a a tool for plotting the layout of a field experiment and also the observed data.

Use col.regions to specify fill colors. This can either be a vector of colors or a function that produces a vector of colors. If the response variable is a factor and col.regions is a function, it will be ignored and the cells are filled with default light-colored backgrounds and a key is placed on the left. If the response variable is numeric, the cells are colored according to col.regions, and a ribbon key is placed on the right.

The default shorten='abb' will shorten the cell text using the abbreviate function. Other choices include shorten='sub' to use a 3-character substring, and shorten='no' for no shortening.

Note that two sub-plots with identical levels of the split-plot factor can be adjacent to each other by virtue of appearing in different whole-plots. To correctly outline the split-plot factor, simply concatenate the whole-plot factor and sub-plot factor together.

To call this function inside another function, you can hack thusly: vr <- "yield"; vx <- "x"; vy <- "y" eval(parse(text=paste("desplot(", vr, "~", vx, "*", vy, ", data=yates.oats)")))

References

K. Ryder (1981). Field plans: why the biometrician finds them useful, Experimental Agriculture, 17, 243--256.

Examples

Run this code
# NOT RUN {
# Show how to customize any feature.  In this case, make the strips bigger.
data(besag.met)
d1 <- desplot(yield ~ col*row|county, besag.met, main="besag.met",
        out1=rep, out2=block, out2.gpar=list(col="white"), strip.cex=3)
d1 <- update(d1, par.settings = list(layout.heights=list(strip=2)))
print(d1)
# Or: d1$par.settings = list(layout.heights=list(strip=2))


# Show experiment layout
data(yates.oats)
desplot(yield ~ x+y, yates.oats, out1=block, out2=gen)

desplot(block ~ x+y, yates.oats, col=nitro, text=gen, cex=1, out1=block,
        out2=gen, out2.gpar=list(col = "gray50", lwd = 1, lty = 1))

# Example from Ryder.
data(ryder.groundnut)
gnut <- ryder.groundnut
m1 <- lm(dry~block+gen, gnut)
gnut$res <- resid(m1)
# Note largest positive/negative residuals are adjacent
desplot(res ~ col + row, gnut, text=gen, cex=1,
        main="ryder.groundnut residuals from RCB model")

# }

Run the code above in your browser using DataLab