Matrix of scatter plots by group
[h,ax,bigax] = gplotmatrix(...)
a matrix of scatter plots. Each individual set of axes in the resulting
figure contains a scatter plot of a column of
a column of
y. All plots are grouped by the grouping
y are matrices with
the same number of rows. If
x has p columns
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,
a square matrix of scatter plots of columns of
group is a grouping variable that can be
a categorical variable, vector, character array, or cell array of
group must have the same number
of rows as
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,
be a cell array containing several grouping variables (such as
g2 g3}); in that case, observations are in the same group
if they have common values of all grouping variables.
the color, marker type, and size for each group.
a character array of colors recognized by the
a character array of symbols recognized by the
with the default value
a vector of sizes, with the default value determined based on the
number of observations. If you do not specify enough values for all
gplotmatrix cycles through the specified
values as needed.
whether a legend is displayed on the graph (
'on', the default)
or not (
what appears along the diagonal of a plot matrix of
Allowable values are
'none', to leave the diagonals
'hist', to plot histograms,
display the outlines of grouped histograms (default if there is more
than one group),
'grpbars' to plot grouped histogram
'variable', to write the variable names.
histograms along the diagonal only when there is only one variable
the names of the columns in the
These names are used to label the x- and y-axes.
be character arrays or cell arrays of character vectors, with one
name for each column of
[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
a matrix of handles to the axes of the individual plots. If
ax contains one
extra row of handles to invisible axes in which the histograms are
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
ylabel command will produce labels that are
centered with respect to the entire plot matrix.
Load the sample data.
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
Create a matrix of scatter plots to compare the first two categories,
housing, with categories 4 (
crime) and 7 (
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],:));