Stacked bar chart is in alphabetical order instead of date.

4 vues (au cours des 30 derniers jours)
Gage Moran
Gage Moran le 21 Nov 2022
Commenté : Gage Moran le 21 Nov 2022
So for example, my code looks like this:
figure
Date6 = categorical({'aNovember 2017', 'bMarch 2018', 'cApril 2018', 'dJuly 2018', 'eNovember 2018'});
Dover6 = [232 215 60 2400 990; 0 0 0 48 13.7; 0 0 0 5.26 3.09; 0 0 0 6.88 10.71; 3.54 1.88 0 37.3 15];
bar(Date6, Dover6,'stacked');
title('198705022BR2SW Station – Bellamy River (Madbury)')
xlabel('Date');
ylabel('Concentration (ng/L)');
legend('PFHPA','PFHXS','PFNA','PFOS','PFOA');
My issue is, I want the order of Date 6 to be how I have it written, but instead it wants to to do it alphebetically, so I have to add a,b, c, d, etc to the start of each one to make it in the proper order. How can I get around this and make the stacked bar graphs in the order I have them written without using the letters? Thank you in advance!
The screenshot attached shows what is happening for context.

Réponse acceptée

Cris LaPierre
Cris LaPierre le 21 Nov 2022
Your dates are categoricals, which by default get stored in alphanumeric order. Use 'reordercats' to place them in your desired order.
figure
Date6 = categorical({'November 2017', 'March 2018', 'April 2018', 'July 2018', 'November 2018'});
Date6 = reordercats(Date6,{'November 2017', 'March 2018', 'April 2018', 'July 2018', 'November 2018'});
Dover6 = [232 215 60 2400 990; 0 0 0 48 13.7; 0 0 0 5.26 3.09; 0 0 0 6.88 10.71; 3.54 1.88 0 37.3 15];
bar(Date6, Dover6,'stacked');
title('198705022BR2SW Station – Bellamy River (Madbury)')
xlabel('Date');
ylabel('Concentration (ng/L)');
legend('PFHPA','PFHXS','PFNA','PFOS','PFOA');

Plus de réponses (0)

Produits


Version

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by