Locate Previous Next Contents

Getting Started – A Simple Pie Chart

For the first part of our presentation, I will use a set of daily demand data for three types of bread, The demands, for 154 consecutive days, are for three types of loaves – sliced bread for toasting, un-sliced bread, and a new range of organic bread.

The demands are contained in a 154 by 3 matrix called demand and the dates of the days are contained in the vector time in their Julian format. Our first task is to produce a simple pie-chart conveying the proportion of the total demand attributable to the three types of bread.

      total„+šdemand
      slices„total÷+/total
      chPie slices
      psView chClose

A few words of explanation. The functions ch are embedded in your workspace in a namespace. The totality of ch functions form the bedrock of the Rain facilities. With them you are able to construct the chart you want! To see the chart, the command psView chClose must be executed. More about that later.

Your pie-chart picture is deficient as it is – they say a picture is worth a thousand words, but without a few words of explanation, it is impossible even to begin to guess what those thousand words might be! We need a title and an explanation of what the different slices (of the pie chart!) represent.

       chSet 'head' 'Total Demand for the Three Breads'
       chSet 'xlab' 'Sliced,Un-sliced,Organic'
       chPie slices
       psView chClose

Despite their popularity in business presentations, pie-charts are not the be-all and end-all of graphical plots. You may prefer a simple bar-chart.

       chBar total
       psView chClose

Again we require some annotations, and we also need to influence the default choice of the scale on the vertical axis to include zero. This can be done (as below) by specifying the 'yrange' or by setting the attributes of the y-axis with a command chSet 'xstyle' 'forcezero'.

       chSet 'head' 'Total Demand for the Three Bread Products'
       chSet 'style' 'boxed'
       chSet 'yrange' (0 1200000)
       chSet 'xlab' 'Sliced,Un-Sliced,Organic'
       chBar total
       psView chClose

You should note that the function chSet will be the most-used function in Rain if you really want to control the form of the resulting graph – it is used to set most of the chart attributes – here we have used it to place a box around the graph, to set the range of the y-axis and also to label the bars on the x-axis.

As a final graph in this introductory section, let us explore how the total demand for the three bread products vary across the days of the week.

       dailytot„+š22 7 3½demand
       chSet 'head' 'Total Demand for the Three Bread Products'
       chSet 'style' 'boxed'
       chSet 'xlab' 'Monday,Tuesday,Wednesday,Thursday,Friday,Saturday,Sunday'
       chBar dailytot
       psView chClose

All that is required to complete the picture is a ‘key’ which indicates the different bread-products – insert the command chSet 'key' 'sliced,un-sliced,organic'

Summary
First you compute the data, then set up any chart properties you require, then make the plot. You can view the completed plot on screen, copy it to the clipboard, print it and so on.


Continue to: Time-Series and Scatterplots
© Copyright Alan Sykes and Adrian Smith 1999