<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
Ko-Kang Wang wrote:
<blockquote TYPE=CITE>Is there a function to do interaction plots in R?
<br>I know in Splus I can simply use interaction.plot()
<p>Thanks.</blockquote>
I don't think there's such a function, so I wrote one some time ago. It
takes two factors f1, f2 and a response variable data. I wanted to add
error bars but dropped that due to lack of time. If you're interested in
that, I can send you what I prepared (mainly a function to plot error bars).
<p>Here's the code; use it at your own risk :-)
<p>Kaspar
<p>BTW, due to the infamous "xaxt" bug in par, the axis will not be labelled
correctly in R 1.0.0. Version 1.0.0.1 corrects it, just upgrade if you
still use 1.0.0.
<br>
<p>int.plot <- function (f1, f2, data, main = "Interaction Plot", xlab
= deparse(substitute(f2)),
<br> ylab = deparse(substitute(f1)), ...)
<br>{
<br> cellmeans <- tapply(data, list(f1, f2), mean)
<br> if (any(is.na(cellmeans)))
<br> stop("Incomplete combinations
of factors!")
<br> xr <- c(1, nlevels(f2))
<br> yr <- range(cellmeans)
<br> o.par <- par(xaxt = "n")
<br> on.exit(par(o.par))
<br> plot(0, 0, type = "n", xlim = xr, ylim = yr, main
= main,
<br> xlab = xlab, ylab = ylab)
<br> apply(cellmeans, MARGIN = 1, function(x) {
<br> lines(x)
<br> invisible()
<br> })
<br> text(xr[2], cellmeans[, ncol(cellmeans)], rownames(cellmeans),
<br> pos = 4)
<br> invisible(list(cellmeans = cellmeans))
<br>}
<br>
<pre>--
Kaspar Pflugshaupt
Geobotanisches Institut ETH Zurich
mailto: pflugshaupt@geobot.umnw.ethz.ch</pre>
</html>