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.


Scatter plot by group


h = gscatter(...)


gscatter(x,y,group) creates a scatter plot of x and y, grouped by group. x and y are vectors of the same size. group is a grouping variable in the form of a categorical variable, vector, character array, or cell array of character vectors. Alternatively, group can be a cell array containing several grouping variables (such as {g1 g2 g3}), in which case observations are in the same group if they have common values of all grouping variables. Points in the same group appear on the graph with the same marker and color.

gscatter(x,y,group,clr,sym,siz) specifies the color, marker type, and size for each group. clr is either a character array of colors recognized by the plot function or a three-column matrix of color specifications. 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, gscatter cycles through the specified values as needed.

gscatter(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').

gscatter(x,y,group,clr,sym,siz,doleg,xnam,ynam) specifies the name to use for the x-axis and y-axis labels. If the x and y inputs are simple variable names and xnam and ynam are omitted, gscatter labels the axes with the variable names.

h = gscatter(...) returns an array of handles to the lines on the graph.


collapse all

Load the sample data.

load discrim

The sample data contains ratings of cities according to nine factors such as climate, housing, education, and health in the matrix ratings .

Plot the relationship between the ratings for climate (first column) and housing (second column) grouped by city size in the matrix group. Choose different colors and plotting symbols for each group.


Introduced before R2006a

Was this topic helpful?