Co-plot (condition plots, plot panels)

This document describes the coplot() xyplot() (lattice) functions.

coplot()

Example 1

coplot(infmor ~ urb | continent, data=world, rows=1)produces a scatterplot for each continent. continent, is a factor (categorical variable); rows=1 forces R to put the individual plots on a single row; otherwise several rows might be produced.

Example 2

coplot(infmor ~ urb | gnpcap*continent, data=world, number=3)A plot showing the relationship between infmor and urb is produced for the observations corresponding to the combined conditions specified by two condition variables. continent is a factor, but gnpcap is a continuous (metric) variable; number=3 means that R will create three intervals (roughly equal size); by default the intervals overlap by 0.5 (fraction of the number of observations. Overlap can be controlled using the overlap= argument; if it is 0, there will be no overlap, if it is negative, some observations are omitted.

xyplot()

This function is available in the lattice package.

xyplot(infmor ~ urb | equal.count(gnpserv,3)*equal.count(gnpcap,3), data=world)Produces a plot for each combination of gnpserv and gnpcap both converted into three classes of equal size.

You can determine the exact content of each plot panel by creating yourself the function that adds information the each panel. In the example below, we add both a resistant and a least squares line.

xyplot(infmor ~ urb | continent, data=world, panel= function(x,y) {panel.xyplot(x,y) panel.abline(line(x,y)) panel.abline(lsfit(x,y), col.line="red") })

The function argumentpanel= defines the function, here we add a xyplot, panel.ablinethen adds the two lines; the least.squares line drawn in red (col.line="red")