From ggrothendieck at gmail.com  Thu Mar  2 14:28:07 2006
From: ggrothendieck at gmail.com (Gabor Grothendieck)
Date: Thu, 2 Mar 2006 08:28:07 -0500
Subject: [Rd] '...' passed to both plot() and legend()
In-Reply-To: <001a01c63df8$65d6d680$0540210a@www.domain>
References: <001a01c63df8$65d6d680$0540210a@www.domain>
Message-ID: <971536df0603020528g4556774di3af2caa63365af6f@mail.gmail.com>

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:
> 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?
>
> > version
>         _
> 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
>
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>



[Rd] '...' passed to both plot() and legend()
Gabor Grothendieck