Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Two half violinplot #49

Open
jon6295 opened this issue Jun 16, 2022 · 6 comments
Open

Two half violinplot #49

jon6295 opened this issue Jun 16, 2022 · 6 comments
Labels

Comments

@jon6295
Copy link

jon6295 commented Jun 16, 2022

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!

@mikelgg93
Copy link
Collaborator

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);

@GrimmSnark
Copy link

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

@vk-vivek-kumar
Copy link

vk-vivek-kumar commented Sep 13, 2022

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

@GrimmSnark
Copy link

Thank you so much for the suggestion!

@EitNickS
Copy link

@mikelgg93, are you able to explain how one can get the text instead of values, as is shown in the original picture?

Screen Shot 2022-12-12 at 3 53 42 PM

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'.

Screen Shot 2022-12-12 at 3 53 20 PM

@mikelgg93
Copy link
Collaborator

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants