Scatter plot by group
h = gscatter(...)
a scatter plot of
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,
be a cell array containing several grouping variables (such as
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 and appear on the graph with the same marker and color.
specifies the color, marker type, and size for each group.
either a character array of colors recognized by the
plot function or a three-column matrix
of color specifications.
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
gscatter cycles through the specified values
whether a legend is displayed on the graph (
'on', the default)
or not (
the name to use for the x-axis and y-axis
labels. If the
are simple variable names and
gscatter labels the axes with the variable
h = gscatter(...) returns
an array of handles to the lines on the graph.
Load the sample data.
The sample data contains ratings of cities according to nine factors such as climate, housing, education, and health in the matrix
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.
figure; gscatter(ratings(:,1),ratings(:,2),group,'br','xo') xlabel('climate'); ylabel('housing');