Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Click to get scatterplot coordinates

Tags:

r

ggplot2

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

like image 651
Yannick Wurm Avatar asked Dec 22 '22 03:12

Yannick Wurm


1 Answers

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 !

like image 98
Paolo Avatar answered Jan 19 '23 08:01

Paolo