Link Search Menu Expand Document (external link)

How to plot interaction effects of treatments (in R, using ggpubr)

See all solutions.

Task

When there are multiple treatment conditions with multiple levels and you wish to undertsand the interaction effects of each of them, a plot can be useful. How can we create the right kind of plot for that situation?

Solution

The solution below uses an example dataset about the teeth of 10 guinea pigs at three Vitamin C dosage levels (in mg) with two delivery methods (orange juice vs. ascorbic acid). (See how to quickly load some sample data.)

1
df <- ToothGrowth

To plot the interaction effects among tooth length, supplement, and dosage, we can use the ggline function in the ggpubr package. You can change the x and color inputs below depending on your goals, but the y input should always be the dependent variable.

1
2
3
# install.packages("ggpubr") # If you have not already installed it
library(ggpubr)
ggline(df, x="dose", y="len", color="supp", add=c("mean"))
1
Loading required package: ggplot2

Looking at the output, we first see that there is an interaction effect because the two supp lines intersect. We also see that there is a difference in length when giving 0.5mg and 1mg dosage of either of the two delivery methods. However, there is barely any difference between the delivery methods when the dosage level is 2mg.

Content last modified on 24 July 2023.

See a problem? Tell us or edit the source.

Contributed by Krtin Juneja (KJUNEJA@falcon.bentley.edu)