I\'m trying to make interaction plot with ggplot2
. My code is below:
library(ggplot2)
p <- qplot(as.factor(dose), len, data=ToothGrowth, geom
You can precalculate the values in their own data frame:
toothInt <- ddply(ToothGrowth,.(dose,supp),summarise, val = mean(len))
ggplot(ToothGrowth, aes(x = factor(dose), y = len, colour = supp)) +
geom_boxplot() +
geom_point(data = toothInt, aes(y = val)) +
geom_line(data = toothInt, aes(y = val, group = supp)) +
theme_bw()
Note that using ggplot
rather than qplot
makes the graph construction a lot clearer for more complex plots like these (IMHO).