I have a set of data, in the form of different values and the number of occurrences of each. I would like to do a box plot of the data, but I can't figure out how to do it. Is there some way to get the boxplot function to count each value times the frequency? Or is there a way to do a boxplot from a five number summary?
Thanks
To answer your second question: Yes, you can perform a boxplot on a 5-number summary.
Sort of. I mean, it just comes down to the fact that the min/Q1/median/Q3/max of your 5-number summary will be exactly those 5 numbers. So you can just call boxplot
on the summary statistics, though you'll want to disable the outlier detection (which is enabled by default)*:
boxplot(summary_stats, 'whisker',Inf)
Another approach may be to recreate the original data from your count data, if that isn't impractically large. Here is a somewhat-kludgy way of doing that:
OrigDataCells = arrayfun(@(val,reps) repmat(val, [reps 1]), Values, Counts, 'UniformOutput',false);
OrigData = vertcat(OrigDataCells{:});
where Values
and Counts
are the values and the number of occurrences.
*The default value for the 'whisker'
parameter is 1.5, which caps the whisker length at 1.5 IQR and causes any points beyond that to be displayed as an "outlier". Setting this to infinity will cause the whiskers to extend to the max/min of the data.