Plotting multiple variables in boxchart
9 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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
Réponses (1)
Cris LaPierre
le 27 Jan 2022
Modifié(e) : Cris LaPierre
le 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 commentaires
Voir également
Catégories
En savoir plus sur 2-D and 3-D Plots dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
