Basic graph with programmatic customization

Introduction

Minimum GAUSS version: 14.0

In this tutorial, we will draw a scatter plot of some data from an Excel® file containing measurements of nuclear site exposure and cancer mortality for a few counties in Washington state. You can download the Excel® file here.

The contents of the data file look like this:

A

B

C

1

County

Exposure

Mortality

2

Umatilla

2.49

147.1

3

Morrow

2.57

130.1

4

Gilliam

3.41

129.9

5

Sherman

1.25

113.5

6

Wasco

1.62

137.5

7

HoodRiver

3.83

162.3

8

Portland

11.64

207.5

9

Columbia

6.41

177.9

10

Clatsop

8.34

210.3

Step 1: Load the data

We will start by loading the exposure and mortality columns into a GAUSS matrix. First save the hanford.xls file that you downloaded from the link above to your computer and set your GAUSS working directory to the folder in which you saved the Excel® file. Then load the data with the following command:

Now data should be a 9x2 GAUSS matrix where the first column is the exposure data and the second column is the mortality data. Let's create two new GAUSS matrices, one named exposure and one named mortality, to make the code more readable.

// Create a new matrix 'exposure' containing
// all observations from the first column of 'data'
exposure = data[.,1];
// Create a new matrix 'mortality' containing
// all observations from the second column of 'data'
mortality = data[.,2];

Step 2: Create a basic scatter plot

We are wondering if our data shows a relationship between nuclear exposure and cancer mortality. A scatter plot is a good way to attempt to visualize this relationship. We can create a simple scatter plot of our two variables like this:

// Create scatter plot
plotScatter(exposure, mortality);

After running the code above you should get an image that looks similar to this:

Step 3: Customize the plot

Our initial graph seems to show a relationship, which makes the data more interesting. Next, we need to customize this graph a bit so that when we share this graph with others, they can understand what it represents.

Our first graph used the default settings for scatter plots. You can view and modify those graphically by selecting Tools > Preferences > Graphics from the main GAUSS menu. It is often desirable, however, to customize your graph as part of a program so that it can be easily replicated. That is our focus for this tutorial.

The plotControl structure

A plotControl structure holds all of the settings for creating a GAUSS graph. To use a plotControl structure we need to:

Declare a variable to be an instance of a plotControl structure.

Fill this plotControl structure with the default values, using the function plotGetDefaults.

The plotSet functions

The plotSet functions modify the settings inside of the plotControl structure that you are using.

The first argument to each of the plotSet functions is going to be a pointer to your plotControl structure. This allows the internal elements of the plotControl structure to be modified inside of the plotSet function.

While a pointer to a structure may sound difficult or arcane&hyphen;&hyphen;all you need to know is that you need to place an ampersand & in front of the structure name. Fortunately, the function tooltips will remind you.

The remaining inputs should be more straightforward and will be documented in the Command Reference entry for each function. Let's use plotSetTitle as an example. It takes the following inputs:

&myPlot

A pointer to a plotControl structure.

title

String to display as the graph title.

font

Optional input. String, the name of the font to use for the title.

fontSize

Optional input. Scalar, the size of the font in points.

fontColor

Optional input. String, the name of font color.

Note that the inputs inside of the square brackets [] are optional inputs.

Conclusion

In this tutorial, we learned

How to draw a basic scatter plot, passing in only our X and Y vectors to plotScatter.

How to programmatically customize a scatter plot by using a plotControl structure.

Have a Specific Question?

Need Support?

Try GAUSS for 30 days for FREE

GAUSS is the product of decades of innovation and enhancement by Aptech Systems, a supportive team of experts dedicated to the success of the worldwide GAUSS user community. Aptech helps people achieve their goals by offering products and applications that define the leading edge of statistical analysis capabilities.