Plotting legend outside plot in R

See the help for legend:

The location may also be specified by setting x to a single keyword from the list “bottomright”, “bottom”, “bottomleft”, “left”, “topleft”, “top”, “topright”, “right” and “center”. This places the legend on the inside of the plot frame at the given location.

So you can place the legend outside the plotting region by giving its coordinates manually:

legend(-0.2, 0.3, legend = c("apple", "orange", "tree"),
       bty = "n", xpd=TRUE, mar=c(7,7,7,7), cex = 1, pch = c(10, 15, 1))

Leave a Comment