点击获取散点图坐标
假设我制作了一个包含数千个点的散点图:
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
我想添加“20个左右最极端点”的标签(在右上角和右下角)。它们很容易通过视觉识别。但以编程方式获取它们似乎有点负担。 (需要许多 if 语句)。
有什么方法可以点击R的图形输出来获取它们的精确坐标吗?
谢谢, 雅尼克
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
locator() 的网格模拟(ggplot2 包以及 Lattice 包都基于网格图形)是 grid.locator()。
感谢 Deepayan Sarkar 格子书!
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 !
不知道
ggplot
,但对于基本图形,您可以使用identify
:现在您可以使用鼠标单击点,R 将显示它们对应的观察结果。单击第一个以外的鼠标按钮会结束该过程,并且
identify
返回观察值作为其值。Don't know with
ggplot
, but with base graphics you can useidentify
: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.如果保存图像,则可以使用
digitize
包来提取点点击的坐标。If you save your image, you can use the
digitize
package to extract the coordinates of point clicks.