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. (See Grouped Data.)

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, string array, or cell array of strings. 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 string array of colors recognized by the plot function. The default for clr is '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,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' (the default), to plot histograms, or 'variable', to write the variable names.

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 strings, 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 G. ax is a matrix of handles to the axes of the individual plots. If dispopt is 'hist', 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.

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. You can make scatter plots of the first three categories against the other four, grouped by the city size code:

load discrim
gplotmatrix(ratings(:,1:2),ratings(:,[4 7]),group) 

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 you specify colors and plotting symbols, label the axes with the rating categories, and move the legend off the graphs:

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

See Also

grpstats, gscatter, plotmatrix

  


 © 1984-2008- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS