Reorder x-axis bar graph categorical
22 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Mark Crook-Rumsey
el 27 de Nov. de 2019
Hi all,
I have viewed some of the other suggestions on here, but none have worked for me and I'm unsure where I am going wrong. I am trying to reorder a bar graph to be in the order I have specified in my variable cats.
errlow_ERP = [young_mid_parietal_PMconcept_stderr_ERP old_mid_parietal_PMconcept_stderr_ERP MCI_mid_parietal_PMconcept_stderr_ERP];
ERP_mean = [young_mid_parietal_PMconcept_mean_ERP old_mid_parietal_PMconcept_mean_ERP MCI_mid_parietal_PMconcept_mean_ERP];
errhigh_ERP = [young_mid_parietal_PMconcept_stderr_ERP old_mid_parietal_PMconcept_stderr_ERP MCI_mid_parietal_PMconcept_stderr_ERP];
cats = categorical({'Young','Older adult','MCI'});
subplot(3,4,12)
hold on;
p = bar(cats,ERP_mean,...
'FaceColor',[0.75,0.75,0.75],...
'EdgeColor','k',...
'LineWidth',1.5,...
'BaseValue',0);
baseline = p.BaseLine;
er = errorbar(cats,ERP_mean,errlow_ERP,errhigh_ERP,'.','vertical');
set(gca,'LineWidth',1,'FontSize',14)
ylim([0 8.5])
er.LineWidth = 1.5;
er.Color = 'k';
er.MarkerSize = 1;
xlabel('Group','FontSize',16)
ylabel('Amplitude in \muV','FontSize',16)
Any advice is greatly appreciated!
0 comentarios
Respuesta aceptada
Adam Danz
el 27 de Nov. de 2019
Editada: Adam Danz
el 20 de Sept. de 2023
Starting in MATLAB R2023b, bar accepts string arrays in addition to categoricals in the x-argument. The bar order will maintain the string order.
str = ["Young","Older adult","MCI"];
y = 1:3;
bar(str, y)
I know it doesn't look intuitive because the order specified by reordercats is the same as the original order but this sets that order in stone.
figure
cats = categorical({'Young','Older adult','MCI'});
cats = reordercats(cats,{'Young','Older adult','MCI'});
p = bar(cats, y);
0 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Labels and Annotations en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!