Search Locate Previous Next Contents

Some Basic Statistics (Frequency Plot)

Clearly, you can do simple statistical plotting with Rain – but this chart adds a little extra by interleaving two data sets (maybe one was “10% extra free”) to get a clear visual comparison.


The basic plotting code is quite simple, as the two histograms are interleaved automatically:

 R„Frequency;XX;YY 
© Test two-sample frequency plot 
 ch.Set('Style' 'boxed')('Classint' 10) 
 ch.Set('Head' 'Two-sample Frequency Plot')
   ('Key' 'Before,After') 
 XX„?115½67 ª XX„XX+?115½67 ª XX„XX+?115½67 
 YY„?115½72 ª YY„YY+?115½72 ª YY„YY+?115½72 ª YY„YY+20 
 XX„XX,[1.5]YY 
 ch.Set'Xcaption' 'Randomly generated data ...' 
 ch.Set('Ystyle' 'grid')('Patterns' 1 3) 
 ch.Freq XX ª BasicStats XX 
 PG„ch.Close 
 R„'View PG © To see it'

Have a closer look at BasicStats which does some enquiries about the current chart settings so that it can position the notes automatically. It also picks up the chart key (if any) and uses this.

You may like to skip this code and return to it later if you need to do this sort of thing!

 BasicStats  MAT;POS;DATA;MU;SD;M;STATS;lab;CT;KT;XT;YT;MI 
© Work out basic stats, then add to chart as a note. 
© 
 MAT„(2†(½MAT),1 1)½MAT 
 XT YT KT MI„ch.Query'XT' 'YT' 'KE' 'MI' 
© Add note to top left of chart space. 
 POS„(0.5×+/2†XT),(¯1†YT),0 
 STATS„'' ª KT„(¯1†½MAT)½KT 
Loop:…lab„1+((¯1†½MAT)½Loop),End,CT„1 
© Take cols one by one, and add to report 
 DATA„MAT[;CT]~MI ª …(½DATA)‡End 
 MU„(+/DATA)÷½DATA 
 M„(DATA-MU)*2 ª SD„((+/M)÷½M)*÷2 
© Use key if available ..... 
 …(' '^.=CTœKT)‡Key ª …(1=¯1†½MAT)†Count 
 STATS„STATS,'Population ',(•CT),': ' ª …Count 
Key:STATS„STATS,(CTœKT),': ' 
Count:STATS„STATS,'sample=',(•½DATA),', mean=',•4 ‘sigfig MU 
 …(2>½DATA)†Skip 
 STATS„STATS,', range=',(•˜/DATA),'-',•—/DATA 
 STATS„STATS,', S.Dev=',(•4 ‘sigfig SD) 
Skip:STATS„STATS,';' 
End:…lab[CT„CT+1] 
 …(½STATS)‡0 
 ch.Note(¯1‡STATS)POS

The key function here is ch.Query which reports the current chart settings for any parameters you are interested in. It requires a vector of 2-element mnemonics, which match the initial two letters of the chart property names.



Continue to: How to Construct a Boxplot
© Copyright Causeway Graphical Systems Ltd 2003