Using label in violin plot using gramm
4 views (last 30 days)
Show older comments
I'm using gramm to draw a violin plot.
a = cell(1, 5);
a(:) = {'exp'};
b = cell(1, 4);
b(:) = {'con'};
data_x = [a b];
data_y = randi([1 10],1, 9);
data_colors = data_x;
obj_plot = gramm('x', data_x(:), 'y', data_y(:), 'color', data_color(:));
% other relevant code %
handle_fig = figure('Position', [0 0 600 300]);
rng('default');
obj_plot.draw();
The above plot would create two violins. I need to add the number of datapoints (5 in this case) on top of the violins.
gramm (documentation) suggests passing the data in the name-value pair 'label', something like the line below
obj_plot = gramm('x', data_x(:), 'y', data_y(:), 'color', data_color(:), 'label', value);
However, I'm not sure what to pass as the value of 'label'.
If I pass,
obj_plot = gramm('x', data_x(:), 'y', data_y(:), 'color', data_color(:), 'label', [5, 5]);
it throws the error - Data inputs have different lengths !
I guess, it is expecting a label for each datapoint in y, but that is not what I'm looking for.
I've also tried using the text() function, but that didn't work either.
a = cell(1, 5);
a(:) = {'exp'};
b = cell(1, 4);
b(:) = {'con'};
data_x = [a b];
data_y = randi([1 10],1, 9);
data_colors = data_x;
obj_plot = gramm('x', data_x(:), 'y', data_y(:), 'color', data_color(:));
% other relevant code %
handle_fig = figure('Position', [0 0 600 300]);
rng('default');
obj_plot.draw();
text([1 2], [5 5], {'5' '5'});
It doesn't throw any error, but it doesn't print any value either.
What am I doing wrong, and how to fix the problem?
2 Comments
Mario Malic
on 12 Feb 2021
What's showing on xlim in your graph? If it's 1 you won't be able to see the text.
text([1 2], [5 5], ['5' '5']);
If you do text like this, it will show '55' on both points. If you want it to specify text for each point, use cell array for it.
{'5', '5'}
Answers (0)
See Also
Categories
Find more on Genomics and Next Generation Sequencing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!