我用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