This document explains the pairs() splom()[lattice] functions.
pairs() displays a scatterplot matrix, draftman's plot) and expects a data matrix as argument; for instance pairs(world) produces a large scatterplot matrix with all variables in world.
The first command line creates a smaller matrix (extracting columns 19-23 from world, followed by pairs without any option.
colcont = c("red","green","blue","brown","yellow","black") [continent] pairs(mat1, bg=colcont, pch=21)
The second command colours the continents differently, and used a different marker. (details on this are explained here).
pairs() is a high level graphical function calling many lower level functions taking care of the details (scatterplot style, legends, etc). As R is a programming environment you have the possibility to change every detail you wish to change to produce a scatterplot matrix that looks exactly the way you want it. For the details you will have to look up the documentation; here we will illustrate several aspects using some examples.
The scatterplot matrix shown here has histograms of the variables in the diagonal, and correlation coefficients in the upper part of the matrix. This has been produced with the following command line:
If you execute the command as such it will not work as the panel.cor and panel.hist functions are not defined. You can find them in the example section of help(pairs) (copy-paste them into the console window (or run example(pairs) first; after examples have been executed the two functions will be defined.)
Note that panel.cor and panel.hist are user defined functions and you can use your own function and place the results into the scatterplot matrix.
Generally speaking the functions found in the lattice library are somewhat more advanced, especially when it comes to produce publication quality graphics and trellis plots (panel plots). See the documentation for details; let us just present an example that pairs() is unable to produce, i.e. a scatterplot matrix for each continent in the same graphic.
splom( ~ mat1 | continent)