Documentation

This is machine translation

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

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

gplotmatrix

Matrix of scatter plots by group

Syntax

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

Description

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, 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 of colors recognized by the plot function. sym is a character 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,y,group,clr,sym,siz,doleg,dispopt) controls what appears along the diagonal of a plot matrix of y versus 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. or 'variable', to write the variable names. gplotmatrix displays histograms along the diagonal only when there is only one variable (i.e., gplotmatrix(x,[],[],[],[],[],[],'hist').

gplotmatrix(x,y,group,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 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. 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 the sample data.

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],:));

Introduced before R2006a

Was this topic helpful?