Use of grouping variables in gplotmatrix

I have 1 y variable to plot against 3 x variables. If I use gplotmatrix(x,y), it works just fine. I want to change the marker size and color. How do I structure the gplotmatrix command to do this? What do I enter for group? Better yet, what is a group variable in this situation?

Answers (1)

Oleg Komarov
Oleg Komarov on 13 Feb 2011

The help of gplotmatrix is:

" 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."

So I would use it as:

gplotmatrix(x,y,group,'grc','vos',[9,8,7])

See LineSpec for line style, color and marker specifiers.

More importantly, I would use gscatter instead of gplotmatrix, because you actually want to plot y against the three x, i.e. using grouping on the same scatter, you would see different clouds for the three combinations:

% Fake data
y = (1:10).';
x = bsxfun(@plus,rand(10,3),[1,5,9]);
% Adapt inputs:
szX   = size(x);
y     = repmat(y,szX(2),1);
group = reshape(repmat(1:szX(2),szX(1),1),[],1);
x = x(:);
% Gscatter
gscatter(x,y,group,'grc','vos',[11,9,7])

Oleg

Categories

Tags

Asked:

on 13 Feb 2011

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!