Plotting multiple variables in boxchart
10 views (last 30 days)
Show older comments
I have a two datasets containing litter item counts for several rivers at multiple locations. Each value in the dataset represents the item count per location. For each river (having multiple locations each) I would like to plot a boxchart for their distribution (boxplot) in item counts in two different periods: spring and autumn.
My arrays (both for spring and for autumn) are structured like this:
river_1 river_2 river_3
353 412 643
389 124 123
352 645 333
.... .... ....
Running the following code produces the following graph:
riverorder = {'Grevelingen','Haringvliet','Lek','Maas','Vechte','Rijn','Schelde','Waal','Nieuwe Waterweg','IJssel','Type'};
load('items_boxchart_autumn.mat')
load('items_boxchart_spring.mat')
items_boxchart_autumn = [items_boxchart_autumn(:,1:4),NaN(209,1),items_boxchart_autumn(:,5:end)]; %fixing vechte: no data in autumn
close all; figure; set(gcf,'Position',[100 100 1000 500]); boxchart(items_boxchart_spring);
title('Statistieken per meetgebied (totaal)');ylabel('Items per meter (rivier)oever'); set(gca,'Yscale','log'); grid on
yticklabels({'0.01','0.1','1','10','100','1000'}); ylim([0 200])
xticklabels(riverorder)

How can I create a graph like this, where the blue boxplots would be the spring data, and the orange ones would be the autumn data?:

All the best,
Paolo
Answers (1)
Cris LaPierre
on 27 Jan 2022
Edited: Cris LaPierre
on 27 Jan 2022
Your desired plot comes straight from an example on the page VBBV linked to, complete with sample code and an explanation. You might find some of the comments in this answer insightful.
tbl = readtable('TemperatureData.csv')
monthOrder = {'January','February','March','April','May','June','July', ...
'August','September','October','November','December'};
tbl.Month = categorical(tbl.Month,monthOrder);
boxchart(tbl.Month,tbl.TemperatureF,'GroupByColor',tbl.Year)
ylabel('Temperature (F)')
legend
0 Comments
See Also
Categories
Find more on 2-D and 3-D Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!