Scatterplot

Created:6/18/2002
Description:

This sample includes a command to generate a scatterplot and a command to generate a scatterplot matrix.

The Scatterplot

A scatterplot is a graph where two data values for an individual in a dataset are used to plot a point in two dimensional space. The result is a scattering of points (see below). A scatterplot is useful for visually determining the correlation between two variables, or finding distinct clusters of individuals in the dataset. This sample also provides a correlation coefficient (in the lower right-hand corner), and a regression line estimated using least squares. Furthermore, a density surface can be added to help visualize clusters when there are many overlapping points in the scatterplot (the blue shading in the background of the scatterplot below).

The scatterplots that this sample creates are simply dataframes with point feature layers and rasters for the density surfaces. Therefore, you can do anything with these scatterplots that you can with any other data set (in terms of symbolization and analysis functions). The feature data used in the scatterplot is stored in a personal GeoDatabase, which the user interface for both the scatterplot and the matrix allows you to specify. If the specified GeoDatabase does not already exist, the sample will automatically create it.

The user interface for the scatterplot consists of a context command that can be placed in the Feature Layer context menu. Executing that command opens a form that allows you to specify the following parameters: the fields that will be used for the X and Y axes of the scatterplot, a "null" value that can be excluded from each field, whether or not to generate a density surface, whether or not to exclude zero values, the directory and personal GeoDatabase name for storing the scatterplot point features, and the name for the scatterplot data frame in the map document. The scatterplot form is pictured below.

The Scatterplot Matrix

A scatterplot matrix is a matrix of scatterplots where each column contains the same X axis and each row the same Y axis (see below). A scatterplot matrix is useful for visualizing how a dataset is distributed through multiple variables. By symbolizing all of the scatterplots in the matrix the same way, you can see how the same clusters of points change shape from one scatterplot to another.

The user interface for the scatterplot matrix is similar to that of the scatterplot. It consists of a context command that can be placed in the Feature Layer context menu. When executed, that command opens a form that allows you to specify the following parameters that are the same as the scatterplot UI: A list of fields to be used for generating the scatterplot matrix, a "null" value that can be excluded from all fields, whether or not to generate a density surface, whether or not to exclude records with zero values in any field, and the directory and personal GeoDatabase name for storing the scatterplot point features. Unlike the scatterplot UI, you cannot specify the name for each scatterplot dataframe. The algorithm automatically assigns a name to each scatterplot based on the X and Y field names. In addition, this form allows you to specify the position of the scatterplot in the layout, and the overall width and height of the scatterplot matrix (it is square). The scatterplot matrix form is pictured below.

Additional Information

This sample consists of two forms and five classes (listed below). It also requires that you install the Correlation sample, which is used to calculate the correlation coefficient and plot the regression curve. The Correlation sample can be found in the group of Analysis and Visualization samples.

Note: In order to generate the density surfaces in a scatterplot or scatterplot matrix, you must have the Spatial Analyst extension installed and activated. If you do not have the Spatial Analyst extension installed and activated, and you check the density surface option in the user interface, the sample will return an error.


How to use:
  1. Install the Correlation sample, which contains functionality necessary for this sample to run. You can find it by searching on "Correlation"
  2. Ensure that you have a copy of the DLL on your local machine (Either compile the project or use the DLL provided)
  3. In ArcMap, open the Customize dialog by selecting Tools: Customize...
  4. In the Tool Bars tab make sure Context Menus is checked
  5. In the Commands tab select the Add from file... button, and add the Scatterplots.dll file in the subsequent dialog.
  6. You should now be in the Analysis Samples category in the left pane of the Commands tab. Select the either the Scatterplot or Scatterplot Matrix command from the right pane, and drag and drop it into the Feature Layer context menu. Close the customization dialog.
  7. To apply the either command, right-click on a feature layer, and select it from the context menu.

Application:
ArcMap

Requires: An ArcMap session with a feature layer.

Difficulty: Intermediate


Visual Basic
File Description
SPUI.cls Implements the ICommand interface to add the scatterplot tool to the UI. This class is affectionately referred to as "spewey".
SPGenUI.cls Implements the ICommand interface to add the scatterplot matrix tool to the UI.
SPGenDensitySurface.cls Generates a density surface from the points in a scatterplot.
Scatterplot.cls Manages the creation of the GeoDatabase and feature class containing the points in the scatterplot.
SPGenerator.cls Creates the scatterplot dataframe and calls the Scatterplot class and the SPGenDensity class
Scatterplots.vbp Visual Basic project file.
Scatterplots.dll The compiled component.
frmMakeSP.frm Dialog box for allowing the user to set parameters for, and generate, a scatterplot.
frmMakeSPM.frm Dialog box for allowing the user to set parameters for, and generate, a scatterplot matrix.


Key CoClasses: AccessWorkspaceFactory, PropertySet, Fields, LineElement, FeatureCursor, Row, RasterDensityOp, Row
Key Interfaces: ICommand, ITable, IDensityOp, IRasterClassifyColorRamp, IRasterRenderer, IFeatureCursor, IFieldsEdit, IFeatureCursor, IRow
Key Members: KernalDensity, Create