Creating Violin Plots how to reorder categories in custom order.

9 views (last 30 days)
I am trying to take data from a table and generate violin plots. below is the script i am using and the results Im getting.
I have read the data directly in from an excel file is a 180x7 structured table.
I have 3 colums of Data in my table (T). Which are T.PeakFlexMom, T.PeakValMom T.PeakIntRotMom. And One column (T.Task) which Described the type of test used.
I want the values to be plotted on the table as 'RUN', 'Planned SS', 'Unplanned SS' however it always defaults to alphebetical order ('Planned SS', 'RUN', 'Unplanned SS')
Any help would be much appreciated.
'ViolinAlpha',0.1,'EdgeColor',[1 0 0],...
violinplot(T.PeakValMom, T.Task,'Width',0.1,...
'ViolinAlpha',0.1,'EdgeColor',[0 1 0],...
'ViolinAlpha',0.1,'EdgeColor',[0 0 1],...
xlabel('Internal Rotation')

Accepted Answer

Adam Danz
Adam Danz on 31 Aug 2020
Edited: Adam Danz on 31 Aug 2020
Use B = reordercats(A,neworder) to change the order of your categorical variables.
Use C = categories(A) to see the current categorical order.
Adam Danz
Adam Danz on 31 Aug 2020
Looks good!
From your title, I assumed your data were already categorical.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!