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 !
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.
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.
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;
Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.
If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website.
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.