[R] barplot legend

Marc Schwartz MSchwartz at mn.rr.com
Fri Jul 1 14:41:39 CEST 2005

On Fri, 2005-07-01 at 14:04 +0200, Navarre Sabine wrote:
> Hi,
> Is it possible ti put the legend out of a barplot?
> tanks
> Sabine

I presume that you mean outside the plot region?

If so, you can use something like the following:

# Adjust the plot margins to make room for the 
# legend on the right side. See ?par
par(mar = c(5, 4, 4, 10) + 0.1)


# Set xpd to allow legend placement outside
# plot region. See ?par
par(xpd = TRUE)

# Left click on the right side of the window where you want
# the legend. See ?locator
l <- locator(1)

# Now put the legend where you clicked
# See ?legend
legend(l$x, l$y, legend = "Legend Here")


Marc Schwartz

More information about the R-help mailing list