How many times have you placed the legend in R plot to discover it is being overrun by some points or lines in the chart? Usually what comes next is a trial-and-error phase where you adjust the location, changing the arguments of the x and y coordinates, and re-drawing the plot again to check if the legend or text are now positioned such that they are fully readable.
With the locator function you can do that more efficiently. Usually I have some charts at this point, but due to the interactive nature of this function I had to make short youtube.
How to use the locator
function? (click play)
:
Code used:
1 2 3 4 5 6 7 8 9 10 11 |
plot(runif(100)) legends_coord <- locator(1) print(legends_coord) legend(x= legends_coord[1], y= legends_coord[2], legend= "First Legend") plot(runif(100)) legends_coord <- locator(3) print(legends_coord) legend(x= legends_coord$x[1], y= legends_coord$y[1], legend= "some text", bty="n") legend(x= legends_coord$x[2], y= legends_coord$y[2], legend= "more text", bty="n") legend(x= legends_coord$x[3], y= legends_coord$y[3], legend= "even more text", bty="n") |