Resources

how to make single legend for the overlapping graphs

0

 

 

I am trying to combine two graphs into one (transparently) because the x-axis of the two graphs do not exactly match. If I draw a graph using below command I can have the graph that I want but the legend boxes are separate. I was wondering if it is possible to make the two legend boxes into one (or at least if I can get rid of the box frame around the legend). Thank you so much!

 

begwind;
window(1,1,1);

ylabel(“Empirical Rejection Rate”);
xlabel(“b”);
ytics(0,0.3,0.05,0.5);
xtics(0,1,0.05,0.5);
_pdate=0;
_plctrl = { 4,4,0 };
_pltype = { 6, 3,  4 };
_pstype = { 10, 8,  0 };
_plwidth=  {11,11, 10};
_pcolor=  {0,0,0};
_psymsiz={1.5,1.5};
_plegstr=
“AM_N(0,1)00
BM_N(0,1)00
0.05″;

_plegctl= { 2, 5, 1.5, 4 };

strl_1=ftocv(p[1],1,1);
strl_2=ftocv(tt[1],2,0);
str_r=ftocv(r1[1],1,0);
fonts(“simplex simgrma”);
string_title=” Non-random Bernoulli, Bartlett, p=”$+strl_1 $+ ” \202r\201=” $+ str_r $+  ” T=” $+ strl_2;
title(string_title);
strl_1=ftocv(p[1]*10,1,0);
strl_2=ftocv(tt[1],2,0);
str_r=ftocv(r1[1]*10,1,0);
prt_title=”-cf=” $+ “fixed_p_”$+strl_1 $+ “_r_” $+  str_r $+ “_T_” $+ strl_2 $+ “.eps” $+” -c=1 -q”;
//graphprt(prt_title);

setwind(1);
xy(x1,y1);

ytics(0,0.3,0.05,0.5);
xtics(0,1,0.05,0.5);
_pdate = “”; //not print date
_plctrl = { 1};
_pltype = { 6};
_pstype = { 5 };
_plwidth=  {11};
_pcolor=  {0};
_psymsiz={2};
_plegctl= { 2, 4, 1.7, 3};
_plegstr=
“ES_N(0,1)”;
setwind(1);
xy(x_es,y1_es);
endwind;

Tags: asked July 21, 2013

3 Answers

0

I think it will be simpler in many ways to draw just 1 graph. If the x’s for the different y’s have the same number of elements, you can just horizontally concatenate them and draw the overlapping graph, for example:

x = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
y1 = cos(x);
y2 = sin(x);

//horizontally concatenate y's
y_final = y1~y2;

xy(x, y_final);

Since you cannot concatenate matrices or vectors with incompatible dimensions, if the y’s have a different number of elements you will have to pad the shorter one with missing values. For example:

x1 = seqa(1,1,100);
x2 = seqa(1,1,10);

y1 = cos(x1);
y2 = sin(x2);

//create a 90x1 vector of missing values
pad = miss(zeros(90,1), 0);

//vertically concatenate the missing values on top of 'y2'
y2 = pad|y2;

//horizontally concatenate 'y1' and 'y2'
y_final = y1~y2;

xy(x1, y_final);
aptech
227
0

Thank you so much for the quick answer. I followed the way you suggested. My x1 and x2 do not have much in common other than that all the numbers for both  x1 and x2 lie between 0 and 1. When I draw the graph by padding with the missing values, the xy() gave me discontinuous lines(curves). It seems that  the curve ends when a missing value is encountered and a new curve begins plotting at the next non-missing value. I was wondering if there is anyway to connect these discontinuous curves smoothly. Thank you.

 

0

Yes, the line will be broken up by missing values. For a continuous curve, keep your data points contiguous. You can ensure this by vertically concatenating the vector of missing values that you are using for padding on top (or on bottom, either will work) of your data. Take a look at the second code snippet in the first response to see an example of this.

aptech
227