Hold on command does not work for boxplot and additional plot

5 views (last 30 days)
Hello all,
I've got a boxplot (with horizontal orientation) with data:
a= [x1;x2;x3;x4;x5;x6;x7;x8;x9;x10;x11;x12;x13;x14;x15]
and the boxplot groups are defined by vector b, where b is:
b = [0*ones(size(x1)); 0.1*ones(size(x2)); 0.2*ones(size(x3)); 0.3*ones(size(x4)); 0.4*ones(size(x5)); 0.5*ones(size(x6)); 0.6*ones(size(x7)); 0.7*ones(size(x8)); 0.8*ones(size(x9)); 0.9*ones(size(x10)); 1.0*ones(size(x11)); 1.1*ones(size(x12)); 1.2*ones(size(x13)); 1.5*ones(size(x14)); 1.6*ones(size(x15))];
where, the positions 0, 0.1, 0.2, 0.3, 0.4......., 1.6 are the positions that my horizontal boxplots are taking on the y axis.
----------
I want to overlap a plot with 5 points say c=[0.3, 0.4, 0.5, 0.6, 0.7] at y=2.
------------
So, when I'm typing
figure
boxplot(a,b,'orientation','horizontal')
hold on
plot(c,2*ones(size(c)),'g.')
it does not work and only the boxplots are shown, but not my 5 points (that are above the highest y value of the boxplots, which is 1.6).
Any ideas of how I could resolve this?

Answers (1)

Walter Roberson
Walter Roberson on 25 May 2015
"hold on" affects the xlim and ylim.
  3 Comments
Walter Roberson
Walter Roberson on 25 May 2015
Edited: Walter Roberson on 25 May 2015
I do not have the Stats toolbox so I cannot test this.
You are passing in your b in G, the grouping variables. Grouping variables designate only groupings, not positions. And I think you are passing in the wrong size of grouping variables unless your x* values are all column vectors.
I think what you are wanting is the 'positions' option:
Box positions specified as a numeric vector with one entry per group or X value. The default is 1:numGroups, where numGroups is the number of groups.
Your grouping variable might as well be integer valued,
[1 * ones(size(x1,1),1); 2 * ones(size(x2,1),1); ... ]
and then your 'positions' would be 0:.1:1.6
and then you would be able to meaningfully plot at y=2 and not have it show up near the bottom of your plot.
I suggest, by the way, that instead of using
hold on
that you use line() to draw the line instead of using plot() to draw it. line() is a graphics primitive object that does not erase anything.
Christina
Christina on 26 May 2015
Hi Walter,
Thank you for your reply.
I think I resolved the first part with plotting boxplots correctly.
-------------
So, when I've got
Xpos = [0 0.1 0.2] (just for three boxplots and not for 15)
group = [repmat(Xpos(1),[size(x1),1]); repmat(Xpos(2),[size(x2)],1); repmat(Xpos(3),[size(x3)],1)]
dataset3 = [x1;x2;x3];
---------
figure
boxplot(dataset3, group,'positions', Xpos,'orientation','horizontal')
hold on
scatter(0.5,2,'g.') (just for one additional point and not for 5 that I want)
------------
my point is still not visible.
I do understand that hold on is restraining the ylimits, but what can I use instead?
Many thanks

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!