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