Learn R Programming

plotrix (version 1.41)

legend.outside: Display a legend outside the plot.

Description

legend.outside displays a legend outside the plot, shrinking the plot to leave space.

Usage

legend.outside(side=1,x=NULL,y=NULL,look.for="plot",...)

Arguments

side
The side of the plot on which the legend will be displayed.
x,y
Top left corner of the legend in user units. The legend will be automatically placed if they are not supplied. If these are incompatible with side there will be trouble.
look.for
String to find last relevant plotting command.
...
Additional arguments passed to legend.

Value

  • The information returned from legend.

See Also

last.call

Examples

Run this code
test1<-rnorm(10)
 test2<-rnorm(10)
 testylim<-range(c(test1,test2))
 plot(test1,type="p",ylim=testylim,pch=2,col=2,main="Test legend on bottom")
 points(test2,pch=3,col=3)
 if(dev.interactive()) {
  par(ask=TRUE)
  # run the legend round the plot
  legend.outside(legend=c("Red","Green"),pch=c(2,3),col=c(2,3))
  plot(test1,type="p",ylim=testylim,pch=2,col=2,main="Test legend on left")
  points(test2,pch=3,col=3)
  legend.outside(side=2,legend=c("Red","Green"),pch=c(2,3),col=c(2,3))
  plot(test1,type="p",ylim=testylim,pch=2,col=2,main="Test legend on top")
  points(test2,pch=3,col=3)
  legend.outside(side=3,legend=c("Red","Green"),pch=c(2,3),col=c(2,3))
  plot(test1,type="p",ylim=testylim,pch=2,col=2,main="Test legend on right")
  points(test2,pch=3,col=3)
  legend.outside(side=4,legend=c("Red","Green"),pch=c(2,3),col=c(2,3))
 }
 par(ask=FALSE)

Run the code above in your browser using DataLab