简体   繁体   English

如何在散点图中圈出一组点并获取其行?

[英]How to encircle a set of points in a scatterplot and get their rows?

I generated some plots with ggplot and colored them by the magnitude of variable x. 我用ggplot生成了一些图,并用变量x的大小对其进行了着色。

I would like to know the identity of the cells that form the main purple cloud in the plot seen below. 我想知道在下面的图中形成紫色主云的细胞的身份。

Is there a way to encircle this area and return a list of rows from the dataframe that are in the circle? 有没有一种方法可以包围该区域并从数据框中返回圆圈中的行的列表?

在此处输入图片说明

In principle one could use ggmap::gglocator() to select a bunch of points, construct a polygon, then use spatial tools to find points in the polygon, but it would take a lot of work to put those pieces together. 原则上,可以使用ggmap::gglocator()选择一堆点,构造一个多边形,然后使用空间工具在多边形中查找点,但是将这些部分放在一起需要大量的工作。 If it were me I would (1) select all points with x>(-15) & y>0 (2) from that set, select all points where y>40-(4/3)*x (eyeballing the intercept slope of a line that forms the lower left boundary of the cluster). 如果是我,我将(1)从该集合中选择x>(-15) & y>0 (2)的所有点,然后选择y>40-(4/3)*x所有点(眼球拦截斜率)形成簇的左下边界的线的线)。 (In fact, step #2 would probably work by itself without running step #1 first.) (实际上,第2步可能会自行工作,而无需先运行第1步。)

With a little bit more work one could write a tool to generalize this that would define bounding lines from pairs of gglocator() points ... 经过更多的工作,人们可以编写一种工具来概括这一点,该工具将从gglocator()点对中定义边界线...

I realize this is an old post - but I've found a nice bit of code here to deal with the first part of the question (see "Scatterplot With Encircling"): 我意识到这是一篇过时的文章-但我在这里找到了很多代码来处理问题的第一部分(请参阅“带圈的散点图”):

http://r-statistics.co/Top50-Ggplot2-Visualizations-MasterList-R-Code.html http://r-statistics.co/Top50-Ggplot2-Visualizations-MasterList-R-Code.html

UPDATE: Link context - someone wiser and more experienced than me has documented that there is a function (geom_encircle) which provides a solution to the first part of the question. 更新:链接上下文-比我更睿智和更有经验的人证明,有一个函数(geom_encircle)可为问题的第一部分提供解决方案。 This function integrates nicely into ggplot2 syntax. 此函数很好地集成到ggplot2语法中。 I just happened to notice both this SO question and the linked website at the same time, and thought it would be useful for future reference for folks looking for the same thing (and didn't want to make it seem like i should get credit). 我只是碰巧同时注意到了这个SO问题和链接的网站,并认为这对于将来寻找相同事物的人们很有用(并且不想让我觉得自己应该得到荣誉) 。 geom_encircle requires the ggalt package. geom_encircle需要ggalt软件包。

The full link to take you directly to the relevant place on the page: http://r-statistics.co/Top50-Ggplot2-Visualizations-MasterList-R-Code.html#Scatterplot%20With%20Encircling 完整链接将您直接带到页面上的相关位置: http : //r-statistics.co/Top50-Ggplot2-Visualizations-MasterList-R-Code.html#Scatterplot%20With%20Encircling

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM