Borrar filtros
Borrar filtros

How to display sample size on each box of a boxplot? Many boxes have different sample sizes.

11 visualizaciones (últimos 30 días)
Say I graph a boxplot figure with 4 boxes. I would like to display the sample size, n, for each of the individual boxes on the figure. How do I do this?
Thanks!

Respuestas (1)

Star Strider
Star Strider el 1 de Oct. de 2012
Editada: Star Strider el 5 de Oct. de 2012
I suggest text. You'll likely have to experiment with it a bit to get the effect you want.
An example:
D = normrnd(0, 1, 10, 4) + repmat([0 1 2 3]*0.5,10,1);
M = mean(D);
G = {'A' 'B' 'C' 'D'};
N = [12 5 8 10];
figure(1)
boxplot(D,G)
for k1 = 1:size(D,2)
text(k1-0.15,M(k1)*1.2, sprintf('N = %d', N(k1)), 'FontSize',8);
end
  2 comentarios
George McFadden
George McFadden el 23 de Oct. de 2012
Thanks Star Strider. Text solves many questions like this one. I am surprised that boxplot does not have a built-in option for this. Its a common feature of boxplots in publications.
Star Strider
Star Strider el 23 de Oct. de 2012
Editada: Star Strider el 24 de Oct. de 2012
It's always my pleasure to help — especially a fellow 'Hoo!

Iniciar sesión para comentar.

Community Treasure Hunt

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

Start Hunting!

Translated by