interaction.plot<- function ( f1, f2, data, main = "Interaction Plot",
    			      xlab = deparse( substitute( f2 ) ),
                              ylab = paste( "Mean of", deparse( substitute( data ) ) ),
    			      legend = T, leg.order = 1:n1, ... ) {
    # f1,f2: factors. data: data vector
    # ( extraction from matrix or data.frame not implemented )
    
    cellmeans <- tapply( data, list( f1, f2 ), mean )
    n1 <- nlevels( f1 )
    n2 <- nlevels( f2 )
    xr <- c( 1, n2 )
    yr <- range( cellmeans )
    plot( 0, 0, type = "n", xaxt = "n", xlim = xr, ylim = yr,
          main = main, xlab = xlab, ylab = ylab )
    matlines( t( cellmeans ), lty = 1, col = 1:n1 )
    axis( 1, at = 1:n2, labels = as.character( levels( f2 ) ) )
    if( legend )    
        legend( locator( 1 ), legend = rownames( cellmeans )[leg.order],
                lty = 1, col = ( 1:n1 )[leg.order] )

    # locator( 1 ) waits for user to choose legend location
    # ( click marks upper left corner )
    # legend entries get ordered according to leg.order

    invisible( list( cellmeans = cellmeans ) )
    # cellmeans are returned
    
}