Main Content

interactionplot

Interaction plot for grouped data

Syntax

interactionplot(Y,GROUP)
interactionplot(Y,GROUP,'varnames',VARNAMES)
interactionplot(fig,___)
[h,AX,bigax] = interactionplot(...)

Description

interactionplot(Y,GROUP) displays the two-factor interaction plot for the group means of matrix Y with groups defined by entries in GROUP, which can be a cell array or a matrix. Y is a numeric matrix or vector. If Y is a matrix, the rows represent different observations and the columns represent replications of each observation. If Y is a vector, the rows give the means of each entry in GROUP. If GROUP is a cell array, then each cell of GROUP must contain a grouping variable that is a categorical variable, numeric vector, character matrix, string array, or single-column cell array of character vectors. If GROUP is a matrix, then its columns represent different grouping variables. Each grouping variable must have the same number of rows as Y. The number of grouping variables must be greater than 1.

The interaction plot is a matrix plot, with the number of rows and columns both equal to the number of grouping variables. The grouping variable names are printed on the diagonal of the plot matrix. The plot at off-diagonal position (i,j) is the interaction of the two variables whose names are given at row diagonal (i,i) and column diagonal (j,j), respectively.

interactionplot(Y,GROUP,'varnames',VARNAMES) displays the interaction plot with user-specified grouping variable names VARNAMES. VARNAMES is a character matrix, a string array, or a cell array of character vectors, one per grouping variable. Default names are 'X1', 'X2', ... .

interactionplot(fig,___) plots into the figure specified by fig instead of the current figure (gcf) using any of the input argument combinations in the previous syntaxes. (since R2024a)

[h,AX,bigax] = interactionplot(...) returns a handle h to the figure window, a matrix AX of handles to the subplot axes, and a handle bigax to the big (invisible) axes framing the subplots.

Examples

collapse all

Randomly generate data for a response variable y.

rng default;     % For reproducibility
y = randn(1000,1);

Randomly generate data for four three-level factors.

group = ceil(3*rand(1000,4));

Display the interaction plots for the factors and name the factors 'A', 'B', 'C', 'D'.

interactionplot(y,group,'varnames',{'A','B','C','D'})

Figure contains 16 axes objects. Axes object 1 contains an object of type text. These objects represent D = 1, D = 2, D = 3. Axes object 2 contains 3 objects of type line. Axes object 3 contains 3 objects of type line. Axes object 4 contains 3 objects of type line. Axes object 5 contains 3 objects of type line. Axes object 6 contains an object of type text. These objects represent C = 1, C = 2, C = 3. Axes object 7 contains 3 objects of type line. Axes object 8 contains 3 objects of type line. Axes object 9 contains 3 objects of type line. Axes object 10 contains 3 objects of type line. Axes object 11 contains an object of type text. These objects represent B = 1, B = 2, B = 3. Axes object 12 contains 3 objects of type line. Axes object 13 contains 3 objects of type line. Axes object 14 contains 3 objects of type line. Axes object 15 contains 3 objects of type line. Axes object 16 contains an object of type text. These objects represent A = 1, A = 2, A = 3.

Version History

Introduced in R2006b

expand all