Documentation

### This is machine translation

Translated by
Mouseover text to see original. Click the button below to return to the English version of the page.

# gplotmatrix

Matrix of scatter plots by group

## Syntax

``gplotmatrix(x,[],group)``
``gplotmatrix(x,y,group)``
``gplotmatrix(x,y,group,clr,sym,siz)``
``gplotmatrix(x,y,group,clr,sym,siz,doleg)``
``gplotmatrix(x,[],group,clr,sym,siz,doleg,dispopt)``
``gplotmatrix(x,[],group,clr,sym,siz,doleg,'variable',xnam)``
``gplotmatrix(x,y,group,clr,sym,siz,doleg,[],xnam,ynam)``
``[h,ax,bigax] = gplotmatrix(___)``

## Description

````gplotmatrix(x,[],group)` creates a matrix of scatter plots of the data in `x`, grouped by the grouping variable in `group`. Each individual set of axes in the resulting figure contains a scatter plot of a column of `x` against another column of `x`. It also plots the outlines of the grouped histograms in the diagonals.`gplotmatrix(x,y,group)` creates a matrix of scatter plots. Each individual set of axes in the resulting figure contains a scatter plot of a column of `x` against a column of `y`. All plots are grouped by the grouping variable `group`.`x` and `y` are matrices with the same number of rows. If `x` has p columns and `y` has q columns, the figure contains a p-by-q matrix of scatter plots. If you omit `y` or specify it as the empty matrix, `[]`, `gplotmatrix` creates a square matrix of scatter plots of columns of `x` against each other.`group` is a grouping variable that can be a categorical variable, vector, character array, string array, or cell array of character vectors. `group` must have the same number of rows as `x` and `y`. Points with the same value of `group` are placed in the same group, and appear on the graph with the same marker and color. Alternatively, `group` can be a cell array containing several grouping variables (such as ```{g1 g2 g3}```); in that case, observations are in the same group if they have common values of all grouping variables.`gplotmatrix(x,y,group,clr,sym,siz)` specifies the color, marker type, and size for each group. `clr` is a character array or string array of colors recognized by the `plot` function. `sym` is a character array or string array of symbols recognized by the `plot` command, with the default value `'.'`. `siz` is a vector of sizes, with the default value determined based on the number of observations. If you do not specify enough values for all groups, `gplotmatrix` cycles through the specified values as needed.`gplotmatrix(x,y,group,clr,sym,siz,doleg)` controls whether a legend is displayed on the graph (`doleg` is `'on'`, the default) or not (`doleg` is `'off'`).`gplotmatrix(x,[],group,clr,sym,siz,doleg,dispopt)` controls what appears along the diagonal of a plot matrix of `x` . Allowable values are `'none'`, to leave the diagonals blank, `'hist'`, to plot histograms, `'stairs'` to display the outlines of grouped histograms (default if there is more than one group), `'grpbars'` to plot grouped histogram bars.`gplotmatrix(x,[],group,clr,sym,siz,doleg,'variable',xnam)` displays the variable names along the diagonal of the plot matrix of `x` . It also uses these column names to label the x- and y-axes.`gplotmatrix(x,y,group,clr,sym,siz,doleg,[],xnam,ynam)` labels the x- and y-axes using the column names specified in `xnam` and `ynam`. `xnam` and `ynam` must be character arrays, string arrays, or cell arrays of character vectors, with one name for each column of `x` and `y`, respectively.`[h,ax,bigax] = gplotmatrix(___)` returns three arrays of handles for any of the previous input arguments. `h` is an array of handles to the lines on the graphs. The array's third dimension corresponds to groups in the input argument `group`. `ax` is a matrix of handles to the axes of the individual plots. If `dispopt` is `'hist'`, `'stairs'`, or `'grpbars'`, `ax` contains one extra row of handles to invisible axes in which the histograms are plotted. `bigax` is a handle to big (invisible) axes framing the entire plot matrix. `bigax` is fixed to point to the current axes, so a subsequent `title`, `xlabel`, or `ylabel` command will produce labels that are centered with respect to the entire plot matrix.```

## Examples

collapse all

`load discrim;`

The `ratings` array contains rating values for 329 U.S. cities in the nine different categories listed in the `categories` array. The `group` array contains a city size code that is equal to `2` for the 26 largest cities, and `1` otherwise.

Create a matrix of scatter plots to compare the first two categories, `climate` and `housing`, with categories 4 (`crime`) and 7 (`arts`). Specify `group` as the grouping variable to visually distinguish the data for large and small cities.

```figure; gplotmatrix(ratings(:,1:2),ratings(:,[4 7]),group);```

The figure displays a matrix of scatter plots for the specified comparisons, with each city size group represented by a different color.

For better clarity, you can adjust the appearance of the graphs by specifying colors and plotting symbols, and labeling the axes with the rating categories.

```figure; gplotmatrix(ratings(:,1:2),ratings(:,[4 7]),group,... 'br','.o',[],'on','',categories(1:2,:),... categories([4 7],:));```