我用D3做了散点图。我如何识别剧情中人口最多的地区,并用椭圆包围它们。例如,在波纹管图的右上角有2个人口稠密的点。有没有一个功能可以做到这一点?如果不是,我对两件事的建议感激:识别,包围或以任何方式标记它们。D3:散点图中人口最多的区域
Scater plot http://tetet.net/clusterLab/scatter.png
var width = 300,
height = 200;
var x = d3.scale.linear().range([0, width]),
y = d3.scale.linear().range([height, 0]);
var svg = d3.select("body")
.append("svg")
.attr("width", width)
.attr("height", height);
d3.tsv("data.tsv", function(error, data) {
if (error) console.warn(error);
x.domain(d3.extent(data, function(q) {return q.xCoord;}));
y.domain(d3.extent(data, function(q) {return q.yCoord;}));
svg.selectAll("circle")
.data(data)
.enter().append("circle")
.attr("r", 5)
.attr("cx", function(d) { return x(d.xCoord); })
.attr("cy", function(d) { return y(d.yCoord); })
});
数据
xCoord yCoord
0 0
5 3
2 1
4 7
7 4
5 2
9 9
3 4
1 6
5 4
8.1 6.2
8.4 6.6
8 6
8 7
7 8
6.8 8.3
6.4 8.4
6.2 8.3
一个简单的思考椭圆的方法,如果每个簇中没有多个点:遍历一个簇中的所有点对以找到彼此距离最远的一对点。在这两点之间的直线上构造一个具有焦点的椭圆的公式,例如,使用[这些答案](http://math.stackexchange.com/questions/426150/what-is-the-general-equation-of-the-ellipse-that-is-not-in-the-origin-and-旋转)。调整参数,使椭圆包括集群中的所有点,但不能变窄(从包含两个点的圆大到足够大)。 – Mars 2014-10-04 17:02:07