| Search Locate Previous Next | Contents |
As we saw in the last example, it is possible within RainPro to place more than one chart on the page. To begin each chart, you use the command ch.New to declare the plotting region to be used, giving 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 would 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.
This is the job of the chart property ch.Set 'Trellis'. It automatically carves up the available space for you into a grid, and allows you to step from cell to cell with ch.NewCell as shown by:
ch.Set 'trellis' 2 3 ¨6½'ch.NewCell ª ch.Plot 1 2 3,[1.5]2 1 3' View ch.Close
which gives you six identical scatterplots in each of the cells.
You can test this 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 120 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
[1] © Multiscatter (from Alan Sykes - APL99 tutor)
[2] ch.Set'xyplot,nolines,marker'
[3] n½utype
[4] :For c :In ¼n
[5] ch.Plot(u[c]=type)data
[6] :EndFor
Now we embed this in the function BarleyPlot which draws a single chart, with the varieties of barley on the y-axis (range 0 to 10 with tick-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.
BarleyPlot f;b;un;yield;type;year;farm
[1] © barley plot for farm = f (1 to 6) (Alan Sykes from APL99)
[2] © b is eventually a matrix of results for the farm
[3] © cols=yield type year farm
[4] ch.NewCell
[5] bbarley ª b(((b[;4])[f])¨b[;4])b
[6] (yield type year farm)[1]b
[7] ch.Set('style' 'boxed')('head'(b[1;4]))
[8] ch.Set'Vmar' 55 10
[9] ch.Set('xrange' 10 70)('yrange' 0 10)('ytic' 1)
[10] ch.Set('xcap' 'Yield')('key'(¨year))
[11] ch.Set'ylab'((''),untype)
[12] year MultiScat yield,[1.5]un¼type
[13] ch.WriteKey Ð
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:
BarleyPlot 1 View PGch.Close
In this case, the call to ch.NewCell does nothing there is only one cell! To produce all six charts:
ch.Set 'Trellis' 2 3 BarleyPlot¨¼6 View PGch.Close
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!