Description Usage Arguments Value Examples
This function allows a templated plot in which the legend is nicely placed outside the plot region.
1 2 |
func |
any plotting function. |
legend.func |
any non-independent function (usually legend). By non-independent, I mean that it requires a pre-existing plot call such as plot.new(). The coordinates of this function is already defined to be (0,1) for both x and y. x=0 and y=1 is a good start for the legend coordinate. |
plt |
this defines the plot (box) region and the legend region together. plt=c(x1,x2,y1,y2). e.g. Increase plt[3] if you run out of space for the x labels. Decrease plt[4] if you run out of space for the plot title. Defaults to c(0.2,0.95,0.4,0.9). |
legend.plt.x |
The plt x value that separates between the plot and legend regions. Decrease this if you run out of space for the legend. |
a list of the returned values from the two functions, if they exist.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | # example 1
template1(
function(){
plot(1:10,1:10,type="o",pch=22, xlab="x",ylab="y")
points(1:10,10:1,col=2,pch=19)
points(1:10,c(9:5,5:9),col=3,pch=19)
},
function(){
legend(0,1,c("haha"),bty="n",pch=22,lty=1,lwd=1)
legend(0,0.8,c("lala","baba"),bty="n",pch=19, col=c(2,3))
}
)
# example 2
template1(
function(){
plot(1:10,1:10,type="o",pch=22, xlab="x",ylab="y")
points(1:10,10:1,col=2,pch=19)
points(1:10,c(9:5,5:9),col=3,pch=19)
},
function(){
legend(0,1,c("haha"),bty="n",pch=22,lty=1,lwd=1)
legend(0,0.8,c("lala","baba"),bty="n",pch=19, col=c(2,3))
},
plt=c(0.2,0.95,0.2,0.9),legend.plt.x=0.8
)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.