ScienceSuit
×

# Scatter Chart

Scatter charts are very useful to show the relationship between different sets of values.

## 1) Plotting Simple Chart

There are different strategies that can be followed to plot a chart. Here, a few possible strategies will be presented.

### A) Existing Selection

Let's assume you have the following time and temperature data:

1. Enter the data to a worksheet.
2. Select the data as shown in the following figure:
3. Click on any of the "Scatter Plots" button to plot the chart.

Done! A chart window will be shown with the data points.

Please note that the name of the series will be "temperature". However, if the selection has not included the headers, a name would be assigned automatically, which in this case would be "Series 1".

Furthermore, if you click on any of the marker, information about the data point will be shown as shown below:

Here, "temperature" is the series name, x and y are values corresponding to the horizontal and the vertical axis, respectively. Moreover, we see that, this particular series was generated by a selection such that x-data has come from "ThermalProc! A1:A8" and y-data from "ThermalProc! B1:B8". If the series was generated via commands, "... generated by std.scatter" information would have been shown.

### B) Using Commands

Depending on the nature of the process, it can be significantly more convenient to generate data points using commands and to plot them on the fly than using the above-described steps.

Suppose you are to inspect the plot F-distribution for degrees of freedom of 3 and 5. Using commands this can be achieved quickly by typing the following commands:

>>x=std.sequence(0, 4, 0.1)
>>y=std.df{x=x, df1=3, df2=5}

>>std.plot(x,y)

### C) Add Selection as New Series

The steps described for existing selection immediately plots the chart on a new plot window. However, when the chart window is already shown a new selection can be added to the already existing plot window. Click any of the plot buttons on the "Home" ribbon page to show an empty chart window as shown below:

At this stage, all menus are disabled. The only option available is to right-click and then select the "Add New Series" menu.

Selecting "Add New Series" will show the following dialog:

• Type: The type of the series to be plotted. Note that on the same chart, different type of series can be plotted.
• Name: Name of the series. This field cannot be blank.
• X and Y Data: The range where X- and Y-data are located.

Once the "OK" button is clicked with the above-shown options, the chart window will be displayed.

The following is doable as well:

1. Click any of the plot buttons on the "Home" ribbon page to show an empty chart window.
2. Right-click and if there is already a selection, the context-menu will offer "Add Visible Selection" option.
1. Click on the "Add Visible Selection As Scatter" and if there is a valid selection, a chart will be displayed.

## 2)Updating and Deleting Series

### A) Updating Series

Updating a series simply means that changing its name and its data. However, in order to change the data, the series must be plotted via a selection. The data of the series generated by commands cannot be updated.

For example, in the following figure, the series was generated by a selection, therefore it is possible to change both its data and name. However, if the series was generated via a command then only the name can be changed.

### B) Deleting Series

When there are more than one series on the same plot window you will have the option to delete any of them should you wish to do so.

1) Right-click on the series to be deleted (this will also select the series).

2) Simply select the Delete option.

## 3) Customizing the Chart

### A) Formatting Series

1) Right-click on the series to be formatted (this will also select the series).

2) Select the Format option. This will show the following dialog.

The Format dialog has two pages to be able to format Line and Markers. If a series has only markers, then all but the line thickness will be disabled. Similar rationale holds for Markers.

Line Properties:

 Color: Color of the line Thickness: Thickness of the line (in pixels). If thickness of the line is 0, then the line will disappear and all controls except the line thickness will be disabled. Smooth line: When the thickness of the line is greater than zero, straight lines will connect each data point. If a smooth line is desired, "Smooth lines" should be checked.

Marker Properties:

 Marker Type: Shape of the marker to be displayed. Currently, circle, square and triangular markers exist. Size: Size of the marker. For example, for a circle, it is the radius of the circle in terms of pixels. Line Color: Color of the line that forms the boundaries of the shape. Line Thickness: Thickness of the line (in pixels) that forms the boundaries of the shape. Note that, line thickness upper limit is bound by the size of the shape. Fill Color: Interior of the shape, excluding the boundaries.

Each time a property is changed, the effects will immediately be seen on the chart. Therefore, it is very convenient to format the chart to a desired style.

### B) Changing Chart Type

Switching between different scatter chart types is rather convenient too:

• Setting line thickness to zero will make lines disappear and setting it greater than zero will make lines appear.
• Checking “Smooth line” option, will apply smoothing algorithm to the existing lines.
• Setting marker thickness to zero will make markers disappear and setting it greater than zero will make markers appear.

Please note that, it is not possible to set line thickness and marker size to zero at the same time. The rationale for this is that a series must be represented at any time either by a marker or a line or both.

### C) Axis Options

The plotter allows changing axis options (horizontal or vertical). Here, changing the properties of the horizontal axis will be presented. Similar steps are followed to modify the properties of the vertical axis.

1) Right-click on the horizontal axis and select "Format Horizontal Axis..."

2) A dialog similar to the following will be shown (note that minimum value has already been changed to 0):

The bounds (minimum, maximum), major unit and the value at which horizontal axis crosses vertical axis are shown.

Let's modify as follows:

Bounds: Minimum: 2    Maximum: 5
Major: 0.5

It is seen that the data is "filtered" to contain only the points between the newly chosen scale.

If you right-click on the horizontal axis again and select the "Format Horizontal Axis...", the dialog will be shown as follows:

It is seen that, the "Reset" buttons are now active for properties which have been manually changed. Clicking on the "Reset" button will reset the bound to its value that had been calculated automatically.

Two different context-menu will be shown: i) Series, ii) Chart.

#### i) Series

To be able to access the series options, just right-click on the particular series and the context-menu will offer the necessary options as shown below:

Updating, formatting and deleting series have already been presented. Adding trendlines is presented in the next section.

#### ii) Chart

To be able to access the rest of the options, just right-click on the chart and the context-menu will offer the necessary options as shown below:

For example, to format the horizontal gridlines, just select "Format Horizontal Gridlines..." option and a dialog will be shown

Color: Color of the gridlines.

Thickness: If thickness if equal to zero, then the gridlines will not be displayed, otherwise, it changes the thickness of the gridline.

Style: Solid, dotted or long-dashed lines.

By using the context-menu, it is also possible to add chart title, vertical and horizontal axes titles and legend as shown below:

Once the mouse cursor is on a title, the shape of the mouse cursor will change indicating that an interaction can take place:

A) When dragged with the mouse, the title will move to a desired location,
B) When clicked, the title will switch to the edit mode and will allow you to type and change the text. To close the edit mode, simply click somewhere out of the shown text editor.

Right-clicking on a title will show the following menu:

A) "Font..." to be able to change the format of the font, covered here.
B) "Delete" to be able to delete the title. Once the title is deleted, its allocated space will be claimed back by the plot area.

After some minor formatting and changing the initial default titles:

Right-clicking on the legend will show the following context-menu, details of which is covered here.

## 4) Plotting Multiple Series

There are different ways to plot multiple series on the same plot window. Here, the most common approaches will be presented.

### A) Selection

Assume you have made the following selection in a worksheet:

Note that, when more than 2 columns are selected, the first column is assumed to be the x-component and the second, third and nth columns are assumed to be the y-components of the data sets. Therefore, the data sets are made of [x, y1], [x,y2]… and each data set generates a different series.

After the selection, once any of the any scatter plot button is clicked a chart comprised of two series will be displayed as shown below:

### B) Using Only Commands

In order to plot multiple series using only commands, you can use hwnd property of std.scatter command. Suppose you want to plot F- and normal distribution on the same plot window. The command sequence that will generate the chart with multiple series:

>>x=std.sequence(0, 4, 0.1)
>>y=std.df{x=x, df1=3, df2=5}

>>hwnd=std.scatter{x=x, y=y, name="f dist"}

>>std.scatter{x=x, y=std.dnorm(x), name="normal dist", hwnd=hwnd}

### C) Selection & Command

Whether the chart window is generated via a selection or through a command, after then either selection or command can be used to add another series on the generated chart window.

1) Obtain a chart first using commands:

>>x=std.tovector{0, 1, 2, 3}
>>y=x^2

>>std.plot(x, y, "y=x^2")
1

2) After clicking "Add New Series", Add Series dialog will appear. As described in how to plot a simple chart make the necessary selections.

3) Click "OK" button and a new series will be added to the same plot window as shown below.

Please note that, it is also possible to use "Add Visible Selection" option, to add another series to an existing chart.

## 5) Trendlines

A trendline is a line of best fit to the data. It can be very helpful when analyzing data as it can be used to forecast future values based on current values and can be used for interpolation within the current values. The available trendlines are:

1. Exponential: y = a·exp(b·x)
2. Linear: y = a·x + b
3. Logarithmic: y = a·ln(x) + b
4. Polynomial: y = an·xn + an-1xn-1 + ... + a0
5. Power: y = a·xn

When possible, the intercept can be set to a custom value. Based on the selected trendline, the R2 (goodness of fit) and equation can be displayed on the chart.

1) Right-click on a series and select the "Add Trendline..." menu item.

2) As shown below, a trendline (shown with blue color), by default linear trendline, will be added to chart.

Please note that a series can only have 1 trendline. Therefore, upon adding a trendline, right clicking the series will not offer the "Add Trendline..." option until the existing trendline is deleted.

### B) Changing Trendline Type

1) Right click on the trendline (or on the series) and select "Format trendline..." as shown below.

2) This will show the following dialog:

Note that:

1. The "Trendline Type" page shows the current trendline type and if any other options applied on the trendline.
2. For the data set: x = [0, 1, 2, 3, 4, 5, 6] and y = [75, 105, 125, 140, 135, 120, 100] which generated the series, only exponential, linear and polynomial type trendlines can be chosen and logarithmic and power cannot be, therefore they were automatically disabled.
3. If polynomial trendline is chosen, the degree of the polynomial can be minimum 2 and maximum 7. However, the maximum degree also depends on the number of data points available.

Below, a polynomial trendline with degree 2 is shown (blue colors)

### C) Changing Line Properties

1) Right click on the trendline and select "Format trendline...".

2) From the "Format Trendline" dialog, select the "Line Properties" tab as shown below:

Note that, initially, the Line Properties page will show the properties of the current trendline. Color, thickness and style of the trendline can be changed.

### D) Displaying R2 and Equation

1) Right click on the trendline and select "Format trendline...". The Format Trendline dialog will be shown.

2) Check the boxes for "Display Equation on Chart" and "Display R-squared Value on Chart". As you check or uncheck the boxes, the related information will be displayed on the chart as seen below:

### Changing the format of the displayed info

1) Right click on the textbox and select "Font..." menu item.

2) Following dialog will be shown:

3) After some minor formatting:

### E) Changing Intercept

A trendline equation is the best fit for the data set under consideration. However, every now and then, we might want to change the intercept. If available, then the intercept can be manually entered. For the equation shown at the previous section, if we change the intercept from 74.2857, which was calculated, to a manual value of 60, then the equation and most likely the R2 will also be changed.

Notice that the intercept, y(0)=60 and R2 changed from 0.992 to 0.905.

### F) Exporting the Equation

In the previous sections, the equation was just shown on the chart. However, we did not use the equation as a function, say for example for interpolation or for forecasting. In order to use the equation as a function:

1) Right-clicking on the trendline will show the following menu:

2) Select "Export Equation as Lua Function" and type a valid function name as shown below:

Here, arbitrarily the function name is chosen as func. Note that the name func conforms with Lua standards and does not exist in the global table.

3) Switch to command editor:

>>type(func)
table

>>func
y = -6.65179x^2+46.0268*x+60

--interpolation
>>func(1.1)
102.581

--forecasting
>>func(7)
56.2499

As a technical detail, please note that, func itself is a Lua table with metamethods __tostring and __call implemented as evidenced below:

>>getmetatable(func)
__tostring=function
__call=function

Therefore, it was possible use the exported table, namely func, to print the equation of the trendline and also as a function.