点击获取散点图坐标

发布于 2024-08-31 13:47:12 字数 473 浏览 2 评论 0原文

假设我制作了一个包含数千个点的散点图:

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

晚风撩人 2024-09-07 13:47:12

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 !

指尖上的星空 2024-09-07 13:47:12

不知道ggplot,但对于基本图形,您可以使用identify

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

现在您可以使用鼠标单击点,R 将显示它们对应的观察结果。单击第一个以外的鼠标按钮会结束该过程,并且 identify 返回观察值作为其值。

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.

_失温 2024-09-07 13:47:12

如果保存图像,则可以使用 digitize 包来提取点点击的坐标。

If you save your image, you can use the digitize package to extract the coordinates of point clicks.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文