Plotting multiple variables in boxchart

10 次查看(过去 30 天)
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

回答(1 个)

Cris LaPierre
Cris LaPierre 2022-1-27
编辑:Cris LaPierre 2022-1-27
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')
tbl = 565×4 table
Year Month Day TemperatureF ____ ___________ ___ ____________ 2015 {'January'} 1 23 2015 {'January'} 2 31 2015 {'January'} 3 25 2015 {'January'} 4 39 2015 {'January'} 5 29 2015 {'January'} 6 12 2015 {'January'} 7 10 2015 {'January'} 8 4 2015 {'January'} 9 20 2015 {'January'} 10 16 2015 {'January'} 11 19 2015 {'January'} 12 31 2015 {'January'} 13 20 2015 {'January'} 14 15 2015 {'January'} 15 23 2015 {'January'} 16 22
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

类别

Help CenterFile Exchange 中查找有关 2-D and 3-D Plots 的更多信息

产品


版本

R2021b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by