Creating Violin Plots how to reorder categories in custom order.

8 ビュー (過去 30 日間)
Sean Byrne
Sean Byrne 2020 年 8 月 31 日
コメント済み: Adam Danz 2020 年 8 月 31 日
Hi,
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.
subplot(3,1,1)
violinplot(T.PeakFlexMom,T.Task,'Width',0.1,...
'ViolinAlpha',0.1,'EdgeColor',[1 0 0],...
'ShowData',false,'ShowMean',true)
xlabel('Flexion')
subplot(3,1,2)
violinplot(T.PeakValMom, T.Task,'Width',0.1,...
'ViolinAlpha',0.1,'EdgeColor',[0 1 0],...
'ShowData',false,'ShowMean',true)
xlabel('Valgus')
subplot(3,1,3)
violinplot(T.PeakIntRotMom,T.Task,'Width',0.1,...
'ViolinAlpha',0.1,'EdgeColor',[0 0 1],...
'ShowData',false,'ShowMean',true)
xlabel('Internal Rotation')

採用された回答

Adam Danz
Adam Danz 2020 年 8 月 31 日
編集済み: Adam Danz 2020 年 8 月 31 日
Use B = reordercats(A,neworder) to change the order of your categorical variables.
Use C = categories(A) to see the current categorical order.
  2 件のコメント
Sean Byrne
Sean Byrne 2020 年 8 月 31 日
Thank you for your comment.
With a little digging I figured out what i needed to do to create the data data into a categorical array.
valueset = {'RUN' 'Planned SS' 'Unplanned SS'};
T.Task = categorical(T.Task,valueset);
T.Task = reordercats(T.Task,{'RUN','Planned SS','Unplanned SS'});
Adam Danz
Adam Danz 2020 年 8 月 31 日
Looks good!
From your title, I assumed your data were already categorical.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeHypothesis Tests についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by