Skip to content

'...' passed to both plot() and legend()

3 messages · Dimitris Rizopoulos, Brian Ripley, Gabor Grothendieck

#
Dear R-devels,

I'd like to create a plot method for a class of objects that passes 
the '...' argument to both plot() and legend(), e.g.,

x <- list(data = rnorm(1000))
class(x) <- "foo"
plot.foo <- function(x, legend = FALSE, cx = "topright", cy = NULL, 
...){
    dx <- sort(x$data)
    plot(dx, dnorm(dx), type = "l", ...)
    if (legend)
        legend(cx, cy, "Gaussian density", bty = "n", ...)
    invisible()
}
#####################
plot(x)
plot(x, legend = TRUE, cex = 1.1)


However, and as expected, if I use an argument of plot() that is not 
an argument of legend() an error occurs, e.g.,

plot(x, legend = TRUE, cex.lab = 1.1)


Is there any (efficient and appropriate) way that I could use the 
'...' argument in this case?
_
platform i386-pc-mingw32
arch     i386
os       mingw32
system   i386, mingw32
status
major    2
minor    2.1
year     2005
month    12
day      20
svn rev  36812
language R


Thanks in advance for any hints,
Dimitris

----
Dimitris Rizopoulos
Ph.D. Student
Biostatistical Centre
School of Public Health
Catholic University of Leuven

Address: Kapucijnenvoer 35, Leuven, Belgium
Tel: +32/(0)16/336899
Fax: +32/(0)16/337015
Web: http://www.med.kuleuven.be/biostat/
     http://www.student.kuleuven.be/~m0390867/dimitris.htm 


Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm
#
See e.g. graphics:::plot.POSIXct, which contains

     axisInt <- function(x, type, main, sub, xlab, ylab, col,
         lty, lwd, xlim, ylim, bg, pch, log, asp, axes, frame.plot,
         ...) axis.POSIXct(1, x, ...)

You could use such as wrapper for legend, in your case probably to pick 
out just the arguments you want.
On Thu, 2 Mar 2006, Dimitris Rizopoulos wrote:

            

  
    
#
You can remove the legend names, assuming there are none
that are also plot names, like this (untested):

args <- list(...)
legnams <- intersect(names(args), names(formals(legend))]
do.call("plot", replace(args, legnams, NULL))
On 3/2/06, Dimitris Rizopoulos <dimitris.rizopoulos at med.kuleuven.be> wrote: