Data visualization with SAS programming

Layout lattice independent x axes across cells

Accepted Solution Solved
Reply
Contributor
Posts: 22
Accepted Solution

Layout lattice independent x axes across cells

I'm trying to produce a rather complicated lattice plot stacking 3 forest plots on top of each other. When I do this with layout gridded the horizontal distribution of each cell is fine, but the top graph is bigger than the bottom two, so gets squashed.

 

Using layout lattice and setting rowweights gets round the vertical squashing, but when i do this the horizontal distribution is messed up in each cell. It seems like layout lattice is lining up the scatter plots so they appear above each other. From the documentation, I thought the default was rowdatarange=data which should make each cell independent, but it isn't working. See images below for example.

 

Can anyone advise?

proc template;
define statgraph panel_forest;
   begingraph / collation=binary subpixel=on axisLineExtent=data;

   		layout lattice / rows=3 rowgutter=5 rowweights=(0.5 0.25 0.25) rowdatarange=data columndatarange=data;

		*Top;
	      layout overlay / walldisplay=none xaxisopts=(display=(ticks tickvalues
	         line) labelFitPolicy=Split offsetmin=0 offsetmax=0 type=linear)
	         yaxisopts=(reverse=true display=none offsetmin=0 offsetmax=0.01 type=
	         linear);
	         ReferenceLine Y=REF / clip=true Lineattrs=(Color=CXF0F0F7 Thickness=30
	            );
	         InnerMargin / align=left;
	            AxisTable Value=VAR_FORM Y=ORDER / labelPosition=min ValueAttrs=(
	               Size=9pt) ValueJustify=Left LabelJustify=Left Display=(Label);
	         EndInnerMargin;
	         InnerMargin / align=left;
	            AxisTable Value=RISK1 Y=ORDER / labelPosition=min ValueAttrs=(Size=
	               9pt) ValueJustify=Center Display=(Label);
	         EndInnerMargin;
	         InnerMargin / align=left;
	            AxisTable Value=RISK2 Y=ORDER / labelPosition=min ValueAttrs=(Size=
	               9pt) ValueJustify=Center Display=(Label);
	         EndInnerMargin;
	         InnerMargin / align=right;
	            AxisTable Value=COUNT Y=ORDER / labelPosition=min ValueAttrs=(Size=
	               9pt) ValueJustify=Center Display=(Label);
	         EndInnerMargin;
	         InnerMargin / align=right;
	            AxisTable Value=PVAL2 Y=ORDER / labelPosition=min ValueAttrs=(Size=
	               9pt) ValueJustify=Center Display=(Label);
	         EndInnerMargin;
	         InnerMargin / align=right;
	            AxisTable Value=PROB_INT2 Y=ORDER / labelPosition=min ValueAttrs=(
	               Size=9pt) ValueJustify=Center Display=(Label);
	         EndInnerMargin;
	         DrawText "" / X=31 Y=98 DRAWSPACE=graphpercent WIDTH=
	            20;
	         ScatterPlot X=ESTIMATE Y=ORDER / subpixel=off Group=GROUP Markerattrs=
	            (Color=CX2A25D9 Symbol=SQUAREFILLED Size=4) LegendLabel="order"
	            NAME="SCATTER";
	         HighLowPlot Y=ORDER High=UPPERLRCL Low=LOWERLRCL / primary=true Group=
	            GROUP Lineattrs=(Color=CX2A25D9 Pattern=1) LegendLabel="order" NAME
	            ="HIGHLOW" highCap=serif lowCap=serif;
	         ReferenceLine x=0 / clip=true Lineattrs=(Color=CX000000);

	      endlayout;

		*Middle;
	      layout overlay / walldisplay=none xaxisopts=(display=(ticks tickvalues
	         line) offsetmin=0 offsetmax=0 type=linear linearopts=(tickvaluelist=(0
	         1 2 3 4) viewmin=0 viewmax=4)) y2axisopts=(labelFitPolicy=Split)
	         yaxisopts=(reverse=true display=none labelFitPolicy=Split offsetmin=0
	         offsetmax=0.01 type=linear linearopts=(viewmin=0.5 viewmax=7))
	         y2axisopts=(labelFitPolicy=Split);
	         ReferenceLine Y=REF_s / clip=true Lineattrs=(Color=CXF0F0F7 Thickness=30
	            );
	         InnerMargin / align=left;
	            AxisTable Value=VAR_s Y=ORDER_s / labelPosition=min ValueAttrs=(Size=
	               9pt) ValueJustify=Left LabelJustify=Left Display=(Label);
	         EndInnerMargin;
	         InnerMargin / align=left;
	            AxisTable Value=RISK1_s Y=ORDER_s / labelPosition=min ValueAttrs=(Size=
	               9pt) ValueJustify=Center Display=(Label);
	         EndInnerMargin;
	         InnerMargin / align=left;
	            AxisTable Value=RISK2_s Y=ORDER_s / labelPosition=min ValueAttrs=(Size=
	               9pt) ValueJustify=Center Display=(Label);
	         EndInnerMargin;
	         InnerMargin / align=right;
	            AxisTable Value=COUNT_s Y=ORDER_s / labelPosition=min ValueAttrs=(Size=
	               9pt) ValueJustify=Center Display=(
	               Label);
	         EndInnerMargin;
	         InnerMargin / align=right;
	            AxisTable Value=PVAL2_s Y=ORDER_s / labelPosition=min ValueAttrs=(Size=
	               9pt) ValueJustify=Center Display=(Label);
	         EndInnerMargin;
	         ScatterPlot X=ESTIMATE_s Y=ORDER_s / subpixel=off Markerattrs=(Color=
	            CX2A25D9 Symbol=SQUAREFILLED Size=4) LegendLabel="order_s" NAME=
	            "SCATTER_s";
	         HighLowPlot Y=ORDER_s High=UPPERLRCL_s Low=LOWERLRCL_s / primary=true
	            Lineattrs=(Color=CX2A25D9 Pattern=1) LegendLabel="order_s" NAME=
	            "HIGHLOW_s" highCap=serif lowCap=serif;
	         ReferenceLine x=1 / clip=true Lineattrs=(Color=CX000000);

	      endlayout;

		*Bottom;
	      layout overlay / walldisplay=none x2axisopts=(labelFitPolicy=Split)
	         xaxisopts=(display=(ticks tickvalues line) labelFitPolicy=Split
	         offsetmin=0 offsetmax=0 type=linear linearopts=(tickvaluelist=(0.5 1
	         1.5 2) viewmin=0.5 viewmax=2)) yaxisopts=(reverse=true display=none
	         offsetmin=0 offsetmax=0.01 type=linear linearopts=(viewmin=0.5 viewmax
	         =7)) x2axisopts=(labelFitPolicy=Split);
	         ReferenceLine Y=REF_h / clip=true Lineattrs=(Color=CXF0F0F7 Thickness=30
	            );
	         InnerMargin / align=left;
	            AxisTable Value=VAR_h Y=ORDER_h / labelPosition=min ValueAttrs=(Size=
	               9pt) ValueJustify=Left LabelJustify=Left Display=(Label);
	         EndInnerMargin;
	         InnerMargin / align=left;
	            AxisTable Value=RISK1_h Y=ORDER_h / labelPosition=min ValueAttrs=(Size=
	               9pt) ValueJustify=Center Display=(Label);
	         EndInnerMargin;
	         InnerMargin / align=left;
	            AxisTable Value=RISK2_h Y=ORDER_h / labelPosition=min ValueAttrs=(Size=
	               9pt) ValueJustify=Center Display=(Label);
	         EndInnerMargin;
	         InnerMargin / align=right;
	            AxisTable Value=COUNT_h Y=ORDER_h / labelPosition=min ValueAttrs=(Size=
	               9pt) ValueJustify=Center Display=(
	               Label);
	         EndInnerMargin;
	         InnerMargin / align=right;
	            AxisTable Value=PVAL2_h Y=ORDER_h / labelPosition=min ValueAttrs=(Size=
	               9pt) ValueJustify=Center Display=(Label);
	         EndInnerMargin;
	         ScatterPlot X=HAZARDRATIO Y=ORDER_h / subpixel=off Markerattrs=(Color=
	            CX2A25D9 Symbol=SQUAREFILLED Size=4) LegendLabel="order_h" NAME=
	            "SCATTER_h";
	         HighLowPlot Y=ORDER_h High=PLUPPER Low=PLLOWER / primary=true Lineattrs=
	            (Color=CX2A25D9 Pattern=1) LegendLabel="order_h" NAME="HIGHLOW_h"
	            highCap=serif lowCap=serif;
	         ReferenceLine x=1 / clip=true Lineattrs=(Color=CX000000);

	      endlayout;

		endlayout;

   endgraph;
end;
run;

 

Gridded.pngLayout griddedLattice.pngLayout lattice


Accepted Solutions
Solution
‎01-17-2018 09:50 AM
SAS Super FREQ
Posts: 1,044

Re: Layout lattice independent x axes across cells

In a lattice, the margins of the plot are always lined up, regardless of the data range setting. However, there is a trick to disabling the alignment. Try wrapping each of your LAYOUT OVERLAY blocks with a LAYOUT GRIDDED. The extra level layout disconnects the LAYOUT OVERLAYs from the alignment negotiations. Let me know if that works for you.

 

Thanks!
Dan

View solution in original post


All Replies
Solution
‎01-17-2018 09:50 AM
SAS Super FREQ
Posts: 1,044

Re: Layout lattice independent x axes across cells

In a lattice, the margins of the plot are always lined up, regardless of the data range setting. However, there is a trick to disabling the alignment. Try wrapping each of your LAYOUT OVERLAY blocks with a LAYOUT GRIDDED. The extra level layout disconnects the LAYOUT OVERLAYs from the alignment negotiations. Let me know if that works for you.

 

Thanks!
Dan

Contributor
Posts: 22

Re: Layout lattice independent x axes across cells

You wonderful person! Thank you very much!

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 2 replies
  • 97 views
  • 0 likes
  • 2 in conversation