An interaction plot is a visual representation of the interaction between the effects of two factors, or between a factor and a numeric variable. It is suitable for experimental data.
You can create an interaction plot with the
interaction.plot function. The command takes the general form:
var2 are the names of the explanatory variables and
response is the name of the response variable.
If one of the explanatory variables is numeric and the other is a factor, list the numeric variable first and the factor second. This way the numeric variable is displayed along the x-axis and the factor is represented by separate lines on the plot.
Example: Interaction plot with
ToothGrowth dataset, which is included with R. The dataset gives the results of an experiment to determine the effect of two supplements (Vitamin C and Orange Juice), each at three different doses (0.5, 1 or 2 mg) on tooth length in guinea pigs. The
len variable gives the tooth growth, the
supp variable gives the supplement type and the
dose variable gives the supplement dose. You can view more information about the
ToothGrowth dataset by entering
To create an interaction plot illustrating the interaction between supplement type and supplement dose, use the command:
> interaction.plot(ToothGrowth$dose, ToothGrowth$supp, ToothGrowth$len)
The results are shown below.
Interaction plot for the ToothGrowth data