The Art of R Programming

(WallPaper) #1

Figure 12-6: Placing text


12.1.9 Pinpointing Locations: The locator() Function.......................


Placing text exactly where you wish can be tricky. You could repeatedly try
differentx- andy-coordinates until you find a good position, but thelocator()
function can save you a lot of trouble. You simply call the function and then
click the mouse at the desired spot in the graph. The function returns thex-
andy-coordinates of your click point. Specifically, typing the following will
tell R that you will click in one place in the graph:


locator(1)


Once you click, R will tell you the exact coordinates of the point you
clicked. Calllocator(2)to get the locations of two places, and so on. (Warn-
ing: Make sure to include the argument.)
Here is a simple example:



hist(c(12,5,13,25,16))
locator(1)
$x
[1] 6.239237



$y
[1] 1.221038


Graphics 271
Free download pdf