BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
DGrint
Obsidian | Level 7

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;

 

Layout griddedLayout griddedLayout latticeLayout lattice

1 ACCEPTED SOLUTION

Accepted Solutions
DanH_sas
SAS Super FREQ

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

2 REPLIES 2
DanH_sas
SAS Super FREQ

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

DGrint
Obsidian | Level 7

You wonderful person! Thank you very much!

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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