[R] legend position in interaction.plot

David Winsemius dwinsemius at comcast.net
Thu Aug 11 14:23:04 CEST 2011


On Aug 11, 2011, at 3:38 AM, Peter Maclean wrote:

> How do I move the legend from default position (right and within the  
> plot) to the "bottomleft" of the plot?
>
> interaction.plot(YEAR, ID GROWTH, legend=TRUE, col = 2:7,xlab="Year",
>        ylim=c(0,2), ylab="Growth",leg.bty = "o")

You display the code from interaction.plot, make a new function, and  
hack the location code for the legend x and y legend arguments which  
are created as the 'xleg' and 'yleg' arguments internally for  
positioning of the legend() and the text(...trace.label) pringint ....  
and then you make the call again with your new function. Out of the  
box the function adds extra xlim space on the basis of the value of  
the 'legend' argument to interaction.plot to make sure the legend does  
not get over-run by the the lines. The y positioning is determined  
entirely by the ylim. There is no provision that I see for user- 
supplied positioning arguments. It would be cleaner to add such named  
arguments after the ,... in the argument list, since attempting to  
pass named arguments directly to legend will generate a bunch of  
warnings.

-- 

David Winsemius, MD
West Hartford, CT



More information about the R-help mailing list