Reputation: 3708
Say I make a scatterplot with thousands of points:
ggplot(head(data, n=2000), aes(length, coverage))+
geom_point(alpha = 0.5, color = 'navyblue') + coord_trans(x='log', y='log')
alt text http://fourmidable.unil.ch/temp/scatterplot.png
I want to add the labels of "the 20 or so most extreme points" (in the upper right and bottom right corners). They are easy to identify visually. But getting at them programatically seems a bit of a burden. (requiring many if statements).
Is there any way I can click on R's graphic output to obtain their precise coordinates?
Thanks, yannick
Upvotes: 4
Views: 10487
Reputation: 3403
If you save your image, you can use the digitize
package to extract the coordinates of point clicks.
Upvotes: 0
Reputation: 2815
The grid analogue (the ggplot2 package as well as the Lattice package are based on grid graphics) of locator() is grid.locator().
Thanks to Deepayan Sarkar Lattice Book !
Upvotes: 8
Reputation: 9587
Don't know with ggplot
, but with base graphics you can use identify
:
plot(length,coverage,type='p')
identify(length,coverage)
Now you can use your mouse to click on points and R will show which observation they correspond to. Clicking a mouse button other than the first ends the process and identify
returns the observation numbers as its value.
Upvotes: 3