legend.position | R Documentation |
This function assesses four corners of an x vs y plot to find the one with the fewest points. It does so by iterating counting from outward to the middle, performing a sparseness-weighted average across corners.
legend.position(x,y,xlim=NULL,ylim=NULL,start=.05, end=.5, incr=.01)
x |
x values of the plot |
y |
y values of the plot |
xlim |
range of the x values |
ylim |
range of the y values |
start |
starting percentage for incremental counting from corner |
end |
ending percentage for incremental counting (middle=0.5) |
incr |
incremental step between each point counting iteration |
one of four values ('bottom'/'top' + 'right'/'left') corresponding to the optimal [most white space] position of the legend.
Hmisc's largest.empty function
par(mfrow=c(3,3))
for(i in 1:9){
x <- rnorm(50)
y <- rlnorm(50)
clrs <- c('red','blue')
plot(x,y, col=clrs)
legend(x=legend.position(x,y), legend = c('x','y'), pch=1, col=clrs, inset=.1)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.