%let gpath='C:\Work\Blogs\Graphically Speaking\2014\Post_Nov_17_AxisBreak'; %let dpi=200; ods html close; ods listing gpath=&gpath image_dpi=&dpi; data break; label x='Stimulus' y='Response'; zero=0; do x=2 to 3 by 0.2; y=1+2*ranuni(2); output; end; x=10.7; y=1.4; output; run; /*proc print;run;*/ ods graphics / reset width=5in height=3in imagename='Bar_NoBreak3'; ods listing style=htmlblue; title 'Break = Full'; proc sgplot data=break noautolegend; highlow y=y low=zero high=x / group=y lineattrs=(thickness=3); xaxis integer offsetmin=0; yaxis min=0 max=4; run; ods graphics / reset width=5in height=3in imagename='Bar_Break3'; ods listing style=htmlblue; title 'Break = Full'; proc sgplot data=break noautolegend; highlow y=y low=zero high=x / group=y lineattrs=(thickness=3);; xaxis ranges=(1 - 3.5 9.75-11) integer offsetmin=0; yaxis min=0 max=4; run; /*--Macro for X or Y axis breaks--*/ %macro AxisBreak (Axis=X, low=, high=, dataout=ANNO, type=BRACKET, back=BACKGROUND, aspect=1.333); data &dataout; length function $10 drawspace $12; /*--Break is on the X axis--*/ %if %upcase(&axis) eq X %then %do; if &low > 0 then lfac=0.996; else lfac=1.002; if &high > 0 then hfac=1.002; else hfac=0.996; lo=&low*lfac; hi=&high*hfac; /*--Erase the full break indicator--*/ drawspace='datavalue'; anchor='bottomleft'; display='Fill'; x1space='datavalue'; y1space='wallpercent'; fillstyleelement='graphbackground'; %if %upcase(&back) eq WALL %then %do; fillstyleelement='graphwalls'; %end; if &low > 0 then lfac=0.998; else lfac=1.002; if &high > 0 then hfac=1.002; else hfac=0.996; function='Polygon'; x1=lo; y1=-0.25; output; function='Polycont'; x1=lo; y1=100; output; function='Polycont'; x1=hi; y1=100; output; function='Polycont'; x1=hi; y1=-0.25; output; /*--Draw bracket--*/ %if %upcase(&type) eq BRACKET %then %do; function='line'; linestyleelement='Graphaxislines'; x1space='datavalue'; y1space='wallpercent'; y2space='wallpercent'; x1=lo; y1=-2; x2=x1; y2=+2; output; x1=hi; y1=-2; x2=x1; y2=+2; output; %end; /*--Draw Z--*/ %if %upcase(&type) eq Z %then %do; function='line'; linestyleelement='Graphaxislines'; x1space='datavalue'; y1space='wallpercent'; y2space='wallpercent'; x1=lo; y1=0; x2=x1; y2=+3; output; x1=x2; y1=y2; x2=hi; y2=-3; output; x1=x2; y1=y2; x2=hi; y2= 0; output; %end; %end; /*--Break is on the Y axis--*/ %else %do; if &low > 0 then lfac=0.990; else lfac=1.003; if &high > 0 then hfac=1.003; else hfac=0.990; lo=&low*lfac; hi=&high*hfac; /*--Erase the full break indicator--*/ drawspace='datavalue'; anchor='bottomleft'; display='Fill'; y1space='datavalue'; x1space='wallpercent'; fillstyleelement='graphbackground'; %if %upcase(&back) eq WALL %then %do; fillstyleelement='graphwalls'; %end; function='Polygon'; y1=lo; x1=0; output; function='Polycont'; y1=lo; x1=100; output; function='Polycont'; y1=hi; x1=100; output; function='Polycont'; y1=hi; x1=0; output; /*--Draw bracket--*/ %if %upcase(&type) eq BRACKET %then %do; function='line'; linestyleelement='Graphaxislines'; y1space='datavalue'; x1space='wallpercent'; x2space='wallpercent'; y1=lo; x1=-2; y2=y1; x2=+2; output; y1=hi; x1=-2; y2=y1; x2=+2; output; %end; /*--Draw Z--*/ %if %upcase(&type) eq Z %then %do; function='line'; linestyleelement='Graphaxislines'; y1space='datavalue'; x1space='wallpercent'; x2space='wallpercent'; y1=lo; x1=0; y2=y1; x2=+3/&aspect; output; y1=y2; x1=x2; y2=hi; x2=-3/&aspect; output; y1=y2; x1=x2; y2=hi; x2= 0; output; %end; %end; run; %mend; /*--X axis Break with Symbol=Bracket -ive data--*/ %let type=Bracket; %let style=Listing; %let back=Wall; %let low=3.5; %let high=9.75; ods listing image_dpi=&dpi style=&style; %AxisBreak (Axis=X, low=&low, high=&high, dataout=anno, back=&back type=&type); ods graphics / reset width=5in height=3in imagename="X_AxisBreak_&type._&back._&style"; title "X Axis Break Symbol=&type"; proc sgplot data=break noborder sganno=anno; scatter x=x y=y; xaxis ranges=(1 - &low &high - 11) integer; yaxis min=0 max=4; run; /*--Negative Data--*/ data break2; label x='Stimulus' y='Response'; zero=0; do x=-10 to 10 by 2; y=1+2*ranuni(2); output; end; x=-107; y=1.4; output; run; /*proc print;run;*/ /*--Y axis Break with Symbol=Z -ive data--*/ %let type=Z; %let style=Analysis; %let back=Wall; %let low=-97; %let high=-15; ods listing image_dpi=&dpi style=&style; %AxisBreak (Axis=Y, low=&low, high=&high, dataout=anno, type=&type, back=&back, aspect=1.667); ods graphics / reset width=5in height=3in imagename="Y_AxisBreak_&type._&style._&back"; title "Break = Axis, Symbol=&type Style=&style &back"; proc sgplot data=break2 noborder sganno=anno; scatter x=y y=x; yaxis ranges=(-110 - &low &high - 10) integer values=(-110 to 10 by 10); xaxis min=0 max=4; run;