Re: [R] is there a way to create legends automatically?

About this list Date view Thread view Subject view Author view Other groups

Subject: Re: [R] is there a way to create legends automatically?
ben@zoo.ufl.edu
Date: Tue 24 Oct 2000 - 23:32:12 EST


Message-ID: <Pine.LNX.4.10.10010240922570.22944-100000@bolker.zoo.ufl.edu>

  Can you be a little more specific about what you want to do?
  To "automatically" create a legend you can write a small function that
plots your data and then generates a legend. An example is below: the
only slightly tricky thing is automatically generating the correct
placement of the legend. I've chosen here to put it in the upper
left-hand corner. It would be wonderful to be able to somehow know where
to put it that it wouldn't overlap any of the data, but short of expanding
the plot range beyond the range of the data I don't see that this is
possible to do automatically.

x <- as.data.frame(matrix(runif(200),ncol=5))
names(x) <- LETTERS[1:5]

plot.with.legend <- function(x,col=1:ncol(x),lty=1:ncol(x),...) {
## x should be a data frame with all numeric variables
   matplot(1:nrow(x),x,col=col,lty=lty,type="l",...)
   u <- par("usr")
   ## put an automatic legend in the upper left-hand corner of the plot
   legend(u[1],u[4],names(x),col=col,lty=lty)
}

On Tue, 24 Oct 2000 Pan_Yuming@aam.de wrote:

> Hi all,
>
> when plotting mutiple data series, i need to specify how one data series
> should be plotted. that s fine, but can i let the program automatically
> create legends afterwards? thanks very much.
>
>
> -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
> r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
> Send "info", "help", or "[un]subscribe"
> (in the "body", not the subject !) To: r-help-request@stat.math.ethz.ch
> _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
>
>

-- 
318 Carr Hall                                bolker@zoo.ufl.edu
Zoology Department, University of Florida    http://www.zoo.ufl.edu/bolker
Box 118525                                   (ph)  352-392-5697
Gainesville, FL 32611-8525                   (fax) 352-392-3704

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request@stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._


About this list Date view Thread view Subject view Author view Other groups

This archive was generated by hypermail 2b25 : Thu 01 Feb 2001 - 16:14:29 EST