| Locate Previous Next | Contents |
As we saw in the last example, it is possible within RAIN to place more than one chart on the page. To begin each chart, use the command ch.New to declare the plotting region to be used, using as right argument the co-ordinates of the bottom-left and top-right of the rectangle. The co-ordinate system works in points, with each point equal to 1/72 and with a default chart area of 6 by 4.5. (Hence x co-ordinates vary from 0 to 432 and y co-ordinates 0 to 324.) So if you wanted to fill the plotting area with a 2 by 3 array of charts, then you need the commands:
ch.New 144 162 288 324
ch.New 288 162 432 324
ch.New 0 0 144 162
ch.New 144 0 288 162
ch.New 288 0 432 162
separated by appropriate plotting commands for each of the six charts. (Do not include the command View PGch.Close with the individual charts, so that the graphics content is allowed to accumulate until all charts are included.)
This is the job of the utility function MbyN. The commands required for each chart are assumed to be contained in each line of the text matrix right argument. Hence the command:
2 3 MbyN 6 24½'ch.Plot 1 2 3,[1.5]2 1 3'
gives you identical scatterplots in each of the six charts.
We put this to test by constructing what S-PLUS calls a Trellis Graphics Chart. This is an attempt to deal with more than two-dimensional data by creating more than one chart as appropriate. There is a famous set of Barley data, analysed by many statisticians from Fisher onwards. Here are just three of the lines of the Barley data (there are 72 in all).
barley[¼3;]
27 Manchuria 1931 University Farm
48.87 Manchuria 1931 Waseca
27.43 Manchuria 1931 Morris
½barley
120 4
½¨¨[1]barley
114 10 2 6
The columns are yields of barley, type of barley (10 types) year of sowing (2 different years) and farms (six different farms)
Lets plan to produce a 2 by 3 set of charts (one for each farm) with yield on the x-axis, type of barley on the y-axis, representing the different years by different markers.
The first small function we need (call it MultiScat) will produce scatterplots of x-y data using different symbols according to a third column.
type MultiScat data;u;n;c
ch.Set'xyplot,nolines,marker'
n½utype
:For c :In ¼n
ch.Plot(u[c]=type)data
:EndFor
Now we embed this in the function bp which draws a single chart, with the varieties of barley on the y -axis (range 0 to 10 with tic-marks spaced 1 apart and with labels given by the names of the barley) and with x-axis of sufficient size to cope with the full range of the yields (10 to 70). The function uses as right argument the numbers 1 to 6 for each farm.
bp f;b;un;yield;type;year;farm
©barley plot for farm = f (1 to 6)
© b is eventually a matrix of results for the farm
© cols=yield type year farm
bbarley ª b(((b[;4])[f])¨b[;4])b
yield type year farm[1]b
ch.Set('style' 'boxed')('head'(b[1;4]))
ch.Set'Vmar' 55 10
ch.Set('xrange' 10 70)('yrange' 0 10)('ytic' 1)
ch.Set('xcap' 'Yield')('key'(¯1,(year),','))
ch.Set'ylab'(' ,',¯1,(untype),',')
year MultiScat yield,[1.5]un¼type
ch.Key Ð
Note that we have had to set an extra wide left-hand margin to leave room for the labels the command ch.Set 'Vmar' 55 10 gives a vertical left-margin of 55 points. We have also included a key to indicate the years. Because we want this on all charts, it has to be flushed out at the end of each individual chart.
This program can be run once, and viewed as usual by using the ch.Close command:
bp 1
View PGch.Close
To produce all six charts:
2 3 MbyN(6 3½'bp '),6 1½¼6
The interesting point to notice about the result is that for all farms except Morris, the yield for 1932 is greater than that for 1931 a mistake in recording the figures? Apparently so!