BookmarkSubscribeRSS Feed
Vams8899
Calcite | Level 5

I would like to create a broken line having Y-axis and Y2-axis using Proc sgplot. Could someone please share the sample code. I am attaching the sample layout of the figure to be displayed.

 

Thanks in advance !

7 REPLIES 7
Jagadishkatam
Amethyst | Level 16

You can try the below link for an example , however i am not sure if we plot y2 axis we can break the axis , only with y axis we can get the broken axis, I hope someone will shed light on the possibility.

 

http://support.sas.com/kb/55/683.html 

Thanks,
Jag
Vams8899
Calcite | Level 5
Hi Jagadish,
Thanks for your reply.
I already tried using ranges to plot the broken axis,but it won't allow to create broken for Y and Y2 axes.
RichardDeVen
Barite | Level 11

The documentation states:

 

Restrictions This option is valid for linear and time axes only.
Only one axis can be broken. If this option is specified for both axes, then it is honored for the vertical axis and ignored for the horizontal axis.
If this option is specified for both axes in the same direction (X and X2 or Y and Y2), then only the primary axis is broken.
When plots are associated with both the X and X2 axes or with both the Y and Y2 axes, neither axis can be broken.
Vams8899
Calcite | Level 5

Yes Richard, this won't work non-linear intervals.Just looking for the alternate solution such scenarios.

 

RichardDeVen
Barite | Level 11
What kind of plot, SCATTER, SERIES ? I can't imagine a VBAR with a Y2.
Vams8899
Calcite | Level 5

I am looking this current scenario for Series plots.

BrunoMueller
SAS Super FREQ

You could go with the approach outlined here https://blogs.sas.com/content/graphicallyspeaking/2012/05/31/broken-y-axis/ this technique was used when the RANGES= option was not available.

 

See a sample using SERIESPLOT below:

data broken_axis;
  infile cards;
  x = _n_;
  input y y2;
  cards;
100 8
120 15
655 70
688 69
180 08
120 15
655 70
688 73
180 12
;

/*
 * just to get basic graph and GTL
 */
proc sgplot data=broken_axis tmplout="c:\temp\sgplot.sas";
  series x=x y=y;
  series x=x y=y2 / y2axis;
run;

/*--Full Panel Break--*/
proc template;
  define statgraph Panel_Break;
    begingraph;
      entrytitle 'Example broken axis';
      layout lattice / rows=2 columndatarange=union rowweights=(0.35 0.65) rowgutter=2;
        columnaxes;
          columnaxis / display=(ticks tickvalues) tickvalueattrs=(size=7);
        endcolumnaxes;

        /* upper part */
        layout overlay / cycleattrs=true 
          yaxisopts=(griddisplay=on display=(ticks tickvalues) 
          tickvalueattrs=(size=7)
          offsetmin=0 linearopts=(viewmin=650 viewmax=750
          tickvaluelist=(650 700 750)))
          y2axisopts=(griddisplay=on display=(ticks tickvalues) 
          tickvalueattrs=(size=7)
          offsetmin=0 linearopts=(viewmin=65 viewmax=75
          tickvaluelist=(65.0 70.0 75.0)));
          seriesplot x=x y=y / datalabel=y;
          seriesplot x=x y=y2 / yaxis=y2 datalabel=y2;
        endlayout;
        /* lower part */
        layout overlay / cycleattrs=true 
          yaxisopts=(griddisplay=on display=(ticks tickvalues) 
          tickvalueattrs=(size=7)
          offsetmin=0 linearopts=(viewmin=0 viewmax=210
          tickvaluelist=(0 100 200)))
          y2axisopts=(griddisplay=on display=(ticks tickvalues) 
          tickvalueattrs=(size=7)
          offsetmin=0 linearopts=(viewmin=0 viewmax=21
          tickvaluelist=(0 10 20)));
          seriesplot x=x y=y / name="y" datalabel=y;
          seriesplot x=x y=y2 / yaxis=y2 name="y2" datalabel=y2;
          DiscreteLegend "y" "y2";
        endlayout;
      endlayout;
    endgraph;
  end;
run;

proc sgrender data=broken_axis template=Panel_Break;
run;

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 7 replies
  • 1940 views
  • 0 likes
  • 4 in conversation