Open jon6295 opened 2 years ago
Ofc! I just called directly to the violin function, skipping the violinplot. Here goes an example of the code:
n= 4; % The original position, in this case 4 was Italy
vsl = Violin({MPG(strcmp(Origin, grouporder{n}))},... %Your data
n-0.05,... % 0.05 is the offset
'HalfViolin','left',... % just left side violin plot
'QuartileStyle','shadow',...
'DataStyle', 'scatter',...
'ShowNotches', false,...
'ShowMean', true,...
'ShowMedian', true);
% Same for the right violin
vsr = Violin({MPG(strcmp(Origin, grouporder{n}))*1.15},...
n+0.05,... % Note here that I add the offset
'HalfViolin','right',...
'QuartileStyle','shadow',...
'DataStyle', 'scatter',...
'ShowNotches', false,...
'ShowMean', true);
Hello,
When I try to replicate the above example, I get the following error:
Index in position 1 is invalid. Array indices must be positive integers or logical values.
Error in Violin (line 375)
ViolinColor{1} = args.ViolinColor{1}(pos,:);
Am I missing something?
Best,
Michael
Michael
Hi Michael,
I was having the same issue. I fixed it. Replace the following 2 lines in Violin.m code:
Original line in code: ViolinColor{1} = args.ViolinColor{1}(pos,:); Replace this line with: ViolinColor{1} = args.ViolinColor{1}(round(pos),:)
Also, right below it is another instance that you need to replace. Original line in code: ViolinColor{2} = args.ViolinColor{2}(pos,:) Replace this line with: ViolinColor{2} = args.ViolinColor{2}(round(pos),:)
These are around Line# 373 in the code. I hope this helps!
Thanks, Vivek
Thank you so much for the suggestion!
@mikelgg93, are you able to explain how one can get the text instead of values, as is shown in the original picture?
Using your example code, you get the position that you are explicitly putting down as n (which is 4). Using Violin (not violinplot), I cannot figure out how to use category labels as names for the individual violins and then allow for an offset. Violin's code explicitly requires scalar number inputs for each violin's 'ID'.
Hi! I might have used violinplot
if I recall it properly due to its flexibility. Unfortunately, I no longer have access to Matlab to test it.
For the labels, you can define xticks
and xticklabels
in Matlab posthoc
Hi
A short question. Would it be possible to
Would it be possible to tell us how you have managed to do the Italy vs Italy 1.5 of the second example. When I try to produce a violin plot which have different distributions in each half I can not make it so that they are separated.
Thanks!