MATLAB Answers

Sharah
0

Why isn't there any simple command to create a grouped boxplot in MATLAB yet?

Asked by Sharah
on 9 Oct 2016
Latest activity Edited by Massimo Zanetti on 9 Oct 2016
I am trying to plot a grouped boxplot on MATLAB but surprisingly Excel can do better!Can anyone suggest the best way to create a grouped boxplot as easy as making one for barchart?

  0 Comments

Sign in to comment.

Tags

1 Answer

Answer by Massimo Zanetti on 9 Oct 2016
Edited by Walter Roberson
on 9 Oct 2016
 Accepted Answer

Sure, there is matlab function specific for this: http://www.mathworks.com/help/stats/boxplot.html
load carsmall
boxplot(MPG,Origin)
title('Miles per Gallon by Vehicle Origin')
xlabel('Country of Origin')
ylabel('Miles per Gallon (MPG)')

  4 Comments

Show 1 older comment
Inspect the help page of the boxplot function, by using CELL input arguments (e.g., for "grouping variables" argument) you can easily obtain the results that you are showing.
Just as an example:
data = rand(20,24);
month = repmat({'jan' 'feb' 'mar' 'apr' 'may' 'jun' 'jul' 'aug' 'sep' 'oct' 'nov' 'dec'},1,2);
simobs = [repmat({'sim'},1,12),repmat({'obs'},1,12)];
boxplot(data,{month,simobs},'colors',repmat('rb',1,12),'factorgap',[5 2],'labelverbosity','minor');
Does the data needs to be the same size? What if we have different size?
According to what I know, yes they must have the same size. The reason is that, the boxplot helps visualizing different feature distributions of the same dataset of samples. Assume you have 100 observed animals, and for any of them you observe height, weigth. Then your data will be 100x2 matrix.
However, if you really need to explain different sized data, here is how to do it: https://it.mathworks.com/matlabcentral/answers/60818-boxplot-with-vectors-of-different-lengths

Sign in to comment.