-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathqqplot.js
58 lines (50 loc) · 1.19 KB
/
qqplot.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
//qqplot.js is part of mathbiol.js; please find documentation and examples there
//Dependencies: csquantiles.js; interp1.js
//Helena F. Deus ([email protected])
//09-08-20
function qqplot(x,y,ctx) {
if(!ctx)
{ctx=document.createElement('canvas');
ctx.width='400';
ctx.height='400';
document.body.appendChild(ctx);
}
if(!y){
alert('Please input y');
}
else {
var ctx2d = ctx.getContext('2d');
m = x.length;
n = y.length;
x=x.sort();max_x=x[x.length-1];
y=y.sort();max_y=y[y.length-1]
if(m==n){
for (var i=0; i<m; i++) {
var x_point = ctx.width-(x[i]*ctx.width/max_x);
var y_point = y[i]*ctx.height/max_y;
var radius = 3;
var startAngle = 0;
var endAngle = Math.PI*2;
var clockwise = true;
ctx2d.arc(x_point,y_point,radius,startAngle,endAngle,true);
ctx2d.stroke();
}
}
else {
//build p with the associated quantiles using the larger one
if(m>n) {
var larger = x;
var smaller = y;
}
else {
var larger = y;
var smaller = x;
}
p=[];
for (var l=1; l<=smaller.length; l++) {
p.push((l-0.5)/smaller.length);
}
xs=csquantiles(larger,p);
}
}
}