Click to get scatter plot coordinates

Say I'm making a scatter chart 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 β€œ20 or so of the most extreme points” (in the upper right and lower right corners). They are easy to identify visually. But getting them programmatically seems a bit of a burden. (many if statements are required).

Is there any way to click on the graphical output R to get their exact coordinates?

Thanks, Yannick

+4
source share
2 answers

The grid analog (ggplot2 package, as well as the lattice package is based on the grid graph) of the locator () - grid.locator ().

Thanks Book of Deepayan of the Sarkar Lattice !

+7
source

I don't know with ggplot , but with basic graphics you can use identify :

 plot(length,coverage,type='p') identify(length,coverage) 

Now you can use the mouse to click on the points, and R will show which observation they correspond. Pressing a mouse button other than the first completes the process, and identify returns the case numbers as a value.

+3
source

Source: https://habr.com/ru/post/1308644/


All Articles