Reputation: 105
I am trying to set the max of the y.domain in a boxplot in d3.js to the 90% quantile of all the data.
My code is at http://bl.ocks.org/cgdnorth/7218544.
I would like to change y.domain([min,max]);
to have the max equal to the 90th of all the data rather than the maximum point.
Thanks for your help.
Upvotes: 0
Views: 431
Reputation: 5323
D3 has a d3.quantile function that takes a sorted array of numbers and a quantile specifier and returns the value from the array that corresponds to that quantile. So in your case you'd use:
var ninetieth = d3.quantile(numbers, 0.9);
Upvotes: 2
Reputation: 109242
You can get this by sorting the array of all values and then indexing into it, something like
var values = [];
data.forEach(function(d) { values = values.concat(e); });
values.sort(d3.ascending);
var max = values[Math.round((values.length-1)*0.9)];
Upvotes: 0