How does the Boxplot 'grouporder' parameter work?
15 views (last 30 days)
Show older comments
I am making a boxplot with grouping based on two categorical string/cell variables.
How do I use the 'grouporder' parameter to reorder the second level grouping (m.case) so that vertical order is Case 1, Case 2, Case 1, Case 2.... instead of Case 2, Case 1, Case 2, Case 1, ... ?
Ideally, I'd like to control the first level group order ( 'AV/AVW CHL1', 'GSM CHL1', 'MERIS CHL2') too instead of using 'ydir'.
Here's the existing code:
h = boxplot(m.bias, {m.types, m.case}, 'plotstyle', 'traditional', ... 'labelorientation', 'inline','notch', 'on', 'orientation', 'horizontal',... 'colorgroup', {m.case}, 'colors', [1 0 0 ; 0 .7 0]); set(gca, 'ydir', 'reverse'); ylm = ylim; hold on; plot([0 0], ylm, 'k:');
>> unique(m.types)
ans =
'AV/AVW CHL1'
'GSM CHL1'
'MERIS CHL2'
>> unique(m.case)
ans =
'Case 1'
'Case 2'
0 Comments
Answers (1)
liomsi liomsi
on 24 Jan 2019
You can convert your m.case to categories, then it should keep the order you gave during the definition of the categories, and you don't need the 'grouporder' option.
m.case = categorical(m.case,{'Case 1','Case 2'}, 'Ordinal',true).
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!