Nested Axes labels and Data Plotting

6 vues (au cours des 30 derniers jours)
Michael Shagam
Michael Shagam le 21 Juil 2022
Réponse apportée : Sayan le 30 Août 2023
Does anyone know any tricks for doing nested catagorical grouping of plotted data? In the example below of a swarmchart(), I would like to group the categorical names on the x-axis by Group A, B , C, etc.
It would be nice if matlab had a general grouping or stacking function of arbitrary plotted data from tables. In excel, you can easily nest plotted tabular data with pivot table plots like this example. And jmp makes it very easy to group axes or entire plots with thegraph builder. Is anyone aware of built-in functions or tips to achieve my desire?

Réponses (1)

Sayan
Sayan le 30 Août 2023
My understanding of the question is that multiple categories in a table need to be merged into one category. In MATLAB categories can be merged with "margecats" function. Here is an example of how this can be done.
T = table([1; 2; 3;4;5], {'A'; 'B'; 'C';'D';'E'}, 'VariableNames', {'NumericColumn', 'CategoricalColumn'});
T.CategoricalColumn = categorical(T.CategoricalColumn);
T.CategoricalColumn = mergecats(T.CategoricalColumn, {'A', 'B','C'}, 'ABC');
%% Use the plot function to plot the data with the merged categories column
Further information can be found in the following MATLAB documentation: https://www.mathworks.com/help/releases/R2021a/matlab/ref/categorical.mergecats.html
Hope this helps resolve the query.

Catégories

En savoir plus sur Tables dans Help Center et File Exchange

Produits


Version

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by