Statistics Toolbox    
gplotmatrix

Plot matrix of scatter plots by group

Syntax

Description

gplotmatrix(x,y,g) 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 g.

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.

g is a grouping variable that can be a vector, string array, or cell array of strings. g must have the same number of rows as x and y. Points with the same value of g are placed in the same group, and appear on the graph with the same marker and color. Alternatively, g 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,g,'clr','sym',siz) specifies the color, marker type, and size for each group. clr is a string array of colors recognized by the plot function. The default is 'clr' = 'bgrcmyk'. 'sym' is a string array of symbols recognized by the plot command, with the default value '.'. siz is a vector of sizes, with the default determined by the 'defaultlinemarkersize' property. If you do not specify enough values for all groups, gplotmatrix cycles through the specified values as needed.

gplotmatrix(x,y,g,'clr','sym',siz,'doleg') controls whether a legend is displayed on the graph ('doleg' = 'on', the default) or not ('doleg' = 'off').

gplotmatrix(x,y,g,'clr','sym',siz,'doleg','dispopt') controls what appears along the diagonal of a plot matrix of x versus x. Allowable values are 'none' to leave the diagonals blank, 'hist' (the default) to plot histograms, or 'variable' to write the variable names.

gplotmatrix(x,y,g,'clr','sym',siz,'doleg','dispopt','xnam','ynam') specifies the names of the columns in the x and y arrays. These names are used to label the x- and y-axes. 'xnam' and 'ynam' must be character arrays with one row for each column of x and y, respectively.

[h,ax,bigax] = gplotmatrix(...) returns three arrays of handles. h is an array of handles to the lines on the graphs. ax is a matrix of handles to the axes of the individual plots. bigax is a handle to big (invisible) axes framing the entire plot matrix. These are left as the current axes, so a subsequent title, xlabel, or ylabel command will produce labels that are centered with respect to the entire plot matrix.

Example

Load the cities data. The ratings array has ratings of the cities in nine categories (category names are in the array categories). group is a code whose value is 2 for the largest cities. We can make scatter plots of the first three categories against the other four, grouped by the city size code.

The output figure (not shown) has an array of graphs with each city group represented by a different color. The graphs are a little easier to read if we specify colors and plotting symbols, label the axes with the rating categories, and move the legend off the graphs.

See Also

grpstats, gscatter, plotmatrix


  gname grpstats