-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Adding box plots drawn on std-deviation instead of quartiles #6698
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 19 commits
7241716
fe3d2d0
923df18
b0868e5
3e1319e
0e9d5a6
29c813f
6ea8d6d
c3f9ea7
d7e2f1b
4e4b486
b3812f8
505a14e
3a3b46c
44e1355
edfa543
a48f2ce
66dcba7
013f4d3
1668fe9
f84e93f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
- Add [1-6]-sigma (std deviations) box plots as an alternative to quartiles [[#6697](https://github.com/plotly/plotly.js/issues/6697)] |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -218,7 +218,30 @@ module.exports = { | |
'right (left) for vertical boxes and above (below) for horizontal boxes' | ||
].join(' ') | ||
}, | ||
|
||
sdmultiple: { | ||
valType: 'number', | ||
min: 0, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't the minimum be one instead of zero? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what if you want 0.5σ? Might be weird but I don't see a reason to prohibit it. |
||
editType: 'calc', | ||
dflt: 1, | ||
description: [ | ||
'Scales the box size when sizemode=sd', | ||
'Allowing boxes to be drawn across any stddev range', | ||
'For example 1-stddev, 3-stddev, 5-stddev', | ||
].join(' ') | ||
}, | ||
sizemode: { | ||
valType: 'enumerated', | ||
values: ['quartiles', 'sd'], | ||
editType: 'calc', | ||
dflt: 'quartiles', | ||
description: [ | ||
'Sets the upper and lower bound for the boxes', | ||
'quartiles means box is drawn between Q1 and Q3', | ||
'SD means the box is drawn between Mean +- Standard Deviation', | ||
'Argument sdmultiple (default 1) to scale the box size', | ||
'So it could be drawn 1-stddev, 3-stddev etc', | ||
].join(' ') | ||
}, | ||
boxmean: { | ||
valType: 'enumerated', | ||
values: [true, 'sd', false], | ||
|
@@ -378,6 +401,15 @@ module.exports = { | |
].join(' ') | ||
}, | ||
|
||
showwhiskers: { | ||
valType: 'boolean', | ||
editType: 'calc', | ||
description: [ | ||
'Determines whether or not whiskers are visible.', | ||
'Defaults to true for `sizemode` *quartiles*, false for *sd*.' | ||
].join(' ') | ||
}, | ||
|
||
offsetgroup: barAttrs.offsetgroup, | ||
alignmentgroup: barAttrs.alignmentgroup, | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -221,7 +221,7 @@ module.exports = function calc(gd, trace) { | |
cdi.min = boxVals[0]; | ||
cdi.max = boxVals[N - 1]; | ||
cdi.mean = Lib.mean(boxVals, N); | ||
cdi.sd = Lib.stdev(boxVals, N, cdi.mean); | ||
cdi.sd = Lib.stdev(boxVals, N, cdi.mean) * trace.sdmultiple; | ||
cdi.med = Lib.interp(boxVals, 0.5); | ||
|
||
if((N % 2) && (usesExclusive || usesInclusive)) { | ||
|
@@ -286,7 +286,9 @@ module.exports = function calc(gd, trace) { | |
q1: _(gd, 'q1:'), | ||
q3: _(gd, 'q3:'), | ||
max: _(gd, 'max:'), | ||
mean: trace.boxmean === 'sd' ? _(gd, 'mean ± σ:') : _(gd, 'mean:'), | ||
mean: (trace.boxmean === 'sd') || (trace.sizemode === 'sd') ? | ||
_(gd, 'mean ± σ:').replace('σ', trace.sdmultiple === 1 ? 'σ' : (trace.sdmultiple + 'σ')) : // displaying mean +- Nσ whilst supporting translations | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This line is getting too long. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Putting the code into a function would make the code less readable - if readability is the concern here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree - if it's only going to be used here, extracting to a function just means it takes another jump to read and understand the code. @archmoj if your concern is just line length we can break this onto more lines. Or leave it for now and sometime add |
||
_(gd, 'mean:'), | ||
lf: _(gd, 'lower fence:'), | ||
uf: _(gd, 'upper fence:') | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,156 @@ | ||
{ | ||
28raining marked this conversation as resolved.
Show resolved
Hide resolved
|
||
"data": [ | ||
{ | ||
"y": [ | ||
0.4995, 0.3786, 0.5188, 0.4505, 0.5805, 0.5539, 0.7341, 0.3303, 0.6202, 0.4754, 0.4814, 0.6103, 0.5157, 0.3841, 0.6166, 0.4917, 0.5646, 0.4532, 0.5983, | ||
0.5079, 0.5227, 0.5483, 0.3081, 0.5172, 0.4127, 0.3871, 0.4703, 0.5331, 0.4573, 0.6187, 0.5718, 0.4474, 0.5349, 0.4614, 0.3096, 0.4411, 0.7143, 0.5956, | ||
0.5171, 0.5515, 0.4234, 0.4589, 0.4289, 0.417, 0.4229, 0.5039, 0.4726, 0.5382, 0.261, 0.5326, 0.4472, 0.54, 0.4998, 0.5513, 0.3891, 0.4821, 0.5006, | ||
0.4362, 0.4184, 0.3632, 0.5182, 0.5229, 0.5493, 0.507, 0.4528, 0.4836, 0.5009, 0.49, 0.5757, 0.5408, 0.4246, 0.511, 0.5216, 0.3817, 0.4471, 0.4935, | ||
0.5668, 0.3187, 0.3633, 0.5964, 0.637, 0.4701, 0.4292, 0.4921, 0.439, 0.5846, 0.4502, 0.44, 0.3057, 0.4756, 0.4867, 0.502, 0.438, 0.6819, 0.2607, | ||
0.5233, 0.3291, 0.5555, 0.5397, 0.5068 | ||
], | ||
"line": { | ||
"color": "#1c9099" | ||
}, | ||
"type": "box", | ||
"boxpoints": "all", | ||
"pointpos": 0, | ||
"name": "1-sigma", | ||
"sizemode": "sd", | ||
"showwhiskers": false | ||
}, | ||
{ | ||
"y": [ | ||
0.4995, 0.3786, 0.5188, 0.4505, 0.5805, 0.5539, 0.7341, 0.3303, 0.6202, 0.4754, 0.4814, 0.6103, 0.5157, 0.3841, 0.6166, 0.4917, 0.5646, 0.4532, 0.5983, | ||
0.5079, 0.5227, 0.5483, 0.3081, 0.5172, 0.4127, 0.3871, 0.4703, 0.5331, 0.4573, 0.6187, 0.5718, 0.4474, 0.5349, 0.4614, 0.3096, 0.4411, 0.7143, 0.5956, | ||
0.5171, 0.5515, 0.4234, 0.4589, 0.4289, 0.417, 0.4229, 0.5039, 0.4726, 0.5382, 0.261, 0.5326, 0.4472, 0.54, 0.4998, 0.5513, 0.3891, 0.4821, 0.5006, | ||
0.4362, 0.4184, 0.3632, 0.5182, 0.5229, 0.5493, 0.507, 0.4528, 0.4836, 0.5009, 0.49, 0.5757, 0.5408, 0.4246, 0.511, 0.5216, 0.3817, 0.4471, 0.4935, | ||
0.5668, 0.3187, 0.3633, 0.5964, 0.637, 0.4701, 0.4292, 0.4921, 0.439, 0.5846, 0.4502, 0.44, 0.3057, 0.4756, 0.4867, 0.502, 0.438, 0.6819, 0.2607, | ||
0.5233, 0.3291, 0.5555, 0.5397, 0.5068 | ||
], | ||
"line": { | ||
"color": "#1c9099" | ||
}, | ||
"boxpoints": "all", | ||
"pointpos": 0, | ||
"type": "box", | ||
"name": "2-sigma", | ||
"sdmultiple" : 2, | ||
"sizemode": "sd", | ||
"showwhiskers": false | ||
}, | ||
{ | ||
"y": [ | ||
0.4995, 0.3786, 0.5188, 0.4505, 0.5805, 0.5539, 0.7341, 0.3303, 0.6202, 0.4754, 0.4814, 0.6103, 0.5157, 0.3841, 0.6166, 0.4917, 0.5646, 0.4532, 0.5983, | ||
0.5079, 0.5227, 0.5483, 0.3081, 0.5172, 0.4127, 0.3871, 0.4703, 0.5331, 0.4573, 0.6187, 0.5718, 0.4474, 0.5349, 0.4614, 0.3096, 0.4411, 0.7143, 0.5956, | ||
0.5171, 0.5515, 0.4234, 0.4589, 0.4289, 0.417, 0.4229, 0.5039, 0.4726, 0.5382, 0.261, 0.5326, 0.4472, 0.54, 0.4998, 0.5513, 0.3891, 0.4821, 0.5006, | ||
0.4362, 0.4184, 0.3632, 0.5182, 0.5229, 0.5493, 0.507, 0.4528, 0.4836, 0.5009, 0.49, 0.5757, 0.5408, 0.4246, 0.511, 0.5216, 0.3817, 0.4471, 0.4935, | ||
0.5668, 0.3187, 0.3633, 0.5964, 0.637, 0.4701, 0.4292, 0.4921, 0.439, 0.5846, 0.4502, 0.44, 0.3057, 0.4756, 0.4867, 0.502, 0.438, 0.6819, 0.2607, | ||
0.5233, 0.3291, 0.5555, 0.5397, 0.5068 | ||
], | ||
"line": { | ||
"color": "#1c9099" | ||
}, | ||
"type": "box", | ||
"boxpoints": "all", | ||
"pointpos": 0, | ||
"name": "3-sigma", | ||
"sdmultiple" : 3, | ||
"sizemode": "sd", | ||
"showwhiskers": false | ||
}, | ||
{ | ||
"y": [ | ||
0.4995, 0.3786, 0.5188, 0.4505, 0.5805, 0.5539, 0.7341, 0.3303, 0.6202, 0.4754, 0.4814, 0.6103, 0.5157, 0.3841, 0.6166, 0.4917, 0.5646, 0.4532, 0.5983, | ||
0.5079, 0.5227, 0.5483, 0.3081, 0.5172, 0.4127, 0.3871, 0.4703, 0.5331, 0.4573, 0.6187, 0.5718, 0.4474, 0.5349, 0.4614, 0.3096, 0.4411, 0.7143, 0.5956, | ||
0.5171, 0.5515, 0.4234, 0.4589, 0.4289, 0.417, 0.4229, 0.5039, 0.4726, 0.5382, 0.261, 0.5326, 0.4472, 0.54, 0.4998, 0.5513, 0.3891, 0.4821, 0.5006, | ||
0.4362, 0.4184, 0.3632, 0.5182, 0.5229, 0.5493, 0.507, 0.4528, 0.4836, 0.5009, 0.49, 0.5757, 0.5408, 0.4246, 0.511, 0.5216, 0.3817, 0.4471, 0.4935, | ||
0.5668, 0.3187, 0.3633, 0.5964, 0.637, 0.4701, 0.4292, 0.4921, 0.439, 0.5846, 0.4502, 0.44, 0.3057, 0.4756, 0.4867, 0.502, 0.438, 0.6819, 0.2607, | ||
0.5233, 0.3291, 0.5555, 0.5397, 0.5068 | ||
], | ||
"line": { | ||
"color": "#1c9099" | ||
}, | ||
"type": "box", | ||
"boxpoints": "all", | ||
"pointpos": 0, | ||
"name": "1-sigma + whiskers", | ||
"sizemode": "sd", | ||
"showwhiskers": true | ||
}, | ||
{ | ||
"y": [ | ||
0.4995, 0.3786, 0.5188, 0.4505, 0.5805, 0.5539, 0.7341, 0.3303, 0.6202, 0.4754, 0.4814, 0.6103, 0.5157, 0.3841, 0.6166, 0.4917, 0.5646, 0.4532, 0.5983, | ||
0.5079, 0.5227, 0.5483, 0.3081, 0.5172, 0.4127, 0.3871, 0.4703, 0.5331, 0.4573, 0.6187, 0.5718, 0.4474, 0.5349, 0.4614, 0.3096, 0.4411, 0.7143, 0.5956, | ||
0.5171, 0.5515, 0.4234, 0.4589, 0.4289, 0.417, 0.4229, 0.5039, 0.4726, 0.5382, 0.261, 0.5326, 0.4472, 0.54, 0.4998, 0.5513, 0.3891, 0.4821, 0.5006, | ||
0.4362, 0.4184, 0.3632, 0.5182, 0.5229, 0.5493, 0.507, 0.4528, 0.4836, 0.5009, 0.49, 0.5757, 0.5408, 0.4246, 0.511, 0.5216, 0.3817, 0.4471, 0.4935, | ||
0.5668, 0.3187, 0.3633, 0.5964, 0.637, 0.4701, 0.4292, 0.4921, 0.439, 0.5846, 0.4502, 0.44, 0.3057, 0.4756, 0.4867, 0.502, 0.438, 0.6819, 0.2607, | ||
0.5233, 0.3291, 0.5555, 0.5397, 0.5068 | ||
], | ||
"line": { | ||
"color": "#1c9099" | ||
}, | ||
"boxpoints": "all", | ||
"pointpos": 0, | ||
"type": "box", | ||
"name": "3-sigma + whiskers", | ||
"sdmultiple" : 3, | ||
"sizemode": "sd", | ||
"showwhiskers": true | ||
}, | ||
{ | ||
"y": [ | ||
0.4995, 0.3786, 0.5188, 0.4505, 0.5805, 0.5539, 0.7341, 0.3303, 0.6202, 0.4754, 0.4814, 0.6103, 0.5157, 0.3841, 0.6166, 0.4917, 0.5646, 0.4532, 0.5983, | ||
0.5079, 0.5227, 0.5483, 0.3081, 0.5172, 0.4127, 0.3871, 0.4703, 0.5331, 0.4573, 0.6187, 0.5718, 0.4474, 0.5349, 0.4614, 0.3096, 0.4411, 0.7143, 0.5956, | ||
0.5171, 0.5515, 0.4234, 0.4589, 0.4289, 0.417, 0.4229, 0.5039, 0.4726, 0.5382, 0.261, 0.5326, 0.4472, 0.54, 0.4998, 0.5513, 0.3891, 0.4821, 0.5006, | ||
0.4362, 0.4184, 0.3632, 0.5182, 0.5229, 0.5493, 0.507, 0.4528, 0.4836, 0.5009, 0.49, 0.5757, 0.5408, 0.4246, 0.511, 0.5216, 0.3817, 0.4471, 0.4935, | ||
0.5668, 0.3187, 0.3633, 0.5964, 0.637, 0.4701, 0.4292, 0.4921, 0.439, 0.5846, 0.4502, 0.44, 0.3057, 0.4756, 0.4867, 0.502, 0.438, 0.6819, 0.2607, | ||
0.5233, 0.3291, 0.5555, 0.5397, 0.5068 | ||
], | ||
"line": { | ||
"color": "#1c9099" | ||
}, | ||
"boxpoints": "all", | ||
"pointpos": 0, | ||
"type": "box", | ||
"name": "diamond 1-sigma", | ||
"boxmean": "sd", | ||
"showwhiskers": false | ||
}, | ||
{ | ||
"y": [ | ||
0.4995, 0.3786, 0.5188, 0.4505, 0.5805, 0.5539, 0.7341, 0.3303, 0.6202, 0.4754, 0.4814, 0.6103, 0.5157, 0.3841, 0.6166, 0.4917, 0.5646, 0.4532, 0.5983, | ||
0.5079, 0.5227, 0.5483, 0.3081, 0.5172, 0.4127, 0.3871, 0.4703, 0.5331, 0.4573, 0.6187, 0.5718, 0.4474, 0.5349, 0.4614, 0.3096, 0.4411, 0.7143, 0.5956, | ||
0.5171, 0.5515, 0.4234, 0.4589, 0.4289, 0.417, 0.4229, 0.5039, 0.4726, 0.5382, 0.261, 0.5326, 0.4472, 0.54, 0.4998, 0.5513, 0.3891, 0.4821, 0.5006, | ||
0.4362, 0.4184, 0.3632, 0.5182, 0.5229, 0.5493, 0.507, 0.4528, 0.4836, 0.5009, 0.49, 0.5757, 0.5408, 0.4246, 0.511, 0.5216, 0.3817, 0.4471, 0.4935, | ||
0.5668, 0.3187, 0.3633, 0.5964, 0.637, 0.4701, 0.4292, 0.4921, 0.439, 0.5846, 0.4502, 0.44, 0.3057, 0.4756, 0.4867, 0.502, 0.438, 0.6819, 0.2607, | ||
0.5233, 0.3291, 0.5555, 0.5397, 0.5068 | ||
], | ||
"line": { | ||
"color": "#1c9099" | ||
}, | ||
"boxpoints": "all", | ||
"pointpos": 0, | ||
"type": "box", | ||
"name": "diamond 3-sigma", | ||
"sdmultiple" : 3, | ||
"boxmean": "sd", | ||
"showwhiskers": false | ||
} | ||
], | ||
"layout": { | ||
"showlegend": false, | ||
"yaxis": { | ||
"title": { "text": "Random Variable" }, | ||
"type": "linear", | ||
"range":[-0.2, 1.2] | ||
}, | ||
"title": { "text": "Box plots drawn on std deviation instead of quartiles" }, | ||
"xaxis": { | ||
"type": "category" | ||
}, | ||
"height": 598, | ||
"width": 1080, | ||
"autosize": true | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In several cases adding new image tests are not necessary.
So this step should be optional and it could be part of
Step 6
.You may revert changes in
CONTRIBUTING.md
and possibly submit a separate PR to suggest improvements as well.Thank you!