Re: [R] Centering a legend

From: Marc Schwartz <>
Date: Mon, 07 May 2007 13:06:39 -0500

On Mon, 2007-05-07 at 19:44 +0200, Erich Neuwirth wrote:
> Using layout I am plotting 5 boxplots on top of each other,
> all of them using colored boxes in different order.
> In a 6th box below I want to give the legend explaining the box colors,
> and I want this box to be centered in an otherwise empty plot.
> I am creating this plot by
> plot(0:1,0:1,type="n")
> Is there an easy way to find the parameters x and y for calling legend
> which will center the legend in this plot?


legend() has positional arguments to enable you to do what you require.

Something along the lines of the following:

# Do your plot
plot(0:1, 0:1, type = "n", ann = FALSE, axes = FALSE)

# Do the legend, centered
legend("center", "This is a test legend")

See the Details section of ?legend, third paragraph. Also, the last set of examples there.

HTH, Marc Schwartz mailing list PLEASE do read the posting guide and provide commented, minimal, self-contained, reproducible code. Received on Mon 07 May 2007 - 18:11:40 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Mon 07 May 2007 - 18:31:24 GMT.

Mailing list information is available at Please read the posting guide before posting to the list.