Data visualization with SAS programming

Graphics Template: How to line up when using different y-axis values?

Reply
New Contributor
Posts: 3

Graphics Template: How to line up when using different y-axis values?

I currently have a graphics template that produces the attached graphic. However, the last plot is slightly thinner than the other plots due to the y-axis values. Is there a way to keep update the figure so all of the plots are the same size regardless of the y-axis values? Playing around with the columngutter has not helped. Also, changing the tickvaluelist for the other plots to have decimals has not helped either. Below is the code I have:

%let xopts=display=(line ticks tickvalues) label=" " type=linear linearopts=(viewmin=0 viewmax=145 tickvaluelist=(0 48 96 144)) tickvalueattrs=(size=&tickvalues_size.pt);

%let yopts=display=(line ticks tickvalues) type=linear linearopts=(viemin=0.00 viewmax=7.00 tickvaluelist=(0.00 2.00 4.00 6.00)) tickvalueattrs=(size=&tickvalues_size.pt);

proc template;

    define statgraph mygraphs.scatter_4x2;

        begingraph;

            layout lattice / columns=4 rows=2 columngutter=5 rowgutter=10 border=false opaque=true;

            %let suffix=_overall;

                /* First plot (top-left) */           

                layout lattice / columns=1 backgroundcolor=&overall_color opaque=true;

                    cell;

                        /* Necessary for label of first plot (top-left) */

                        cellheader;

                            entry "A. Plot 1 " {sup " "} / border =false textattrs=(size=&title_size.pt);

                        endcellheader;

                        /* Necessary for plot of first plot (top-left) */

                        layout overlay / x2axisopts=(display=(line)) xaxisopts=(&xopts) yaxisopts=(display=(line ticks tickvalues) type=linear linearopts=(viemin=0.00 viewmax=5.5 tickvaluelist=(1 3 5)) tickvalueattrs=(size=&tickvalues_size.pt) display=(line ticks tickvalues));

                            /* Includes the Logrank information in the first plot (top-left) */

                            entry &p_lt_001 / location=inside autoalign=(TopLeft) border=false textattrs=(size=&p_value_size.pt);

                            /* Plot the first plot (top-left) */

                            *stepplot x=x1_axis y=y1_axis  / markerattrs=(symbol=circlefilled ) group=Group name='pts';

                            scatterplot y=meananthro_wt&suffix x=re_wk / yerrorlower=lo_wt&suffix yerrorupper=up_wt&suffix group=trt_lng ERRORBARATTRS=(thickness=&errorbar_size.px);

                            seriesplot  y=meananthro_wt&suffix x=re_wk / group=trt_lng name='pts' lineattrs=(thickness=&linethickness_size.px);

                               

                        endlayout; /* Close of layout overlay for first plot (top-left) */

                    endcell; /* Close of cell for first plot (top-left) */

                endlayout; /* Close of layout lattice for first plot (top-left) */

           

                /* second plot (top-middle) */               

                layout lattice / columns=1 backgroundcolor=&overall_color opaque=true;

                    cell;

                        /* Necessary for label of second plot (top-middle) */

                        cellheader;

                            entry "B. Plot 2" {sup " "} / border =false textattrs=(size=&title_size pt);

                        endcellheader;

                        /* Necessary for plot of second plot (top-middle) */

                        layout overlay / x2axisopts=(display=(line)) xaxisopts=(&xopts tickvalueattrs=(size=&tickvalues_size.pt)) yaxisopts=(display=(line ticks tickvalues) type=linear linearopts=(viewmin=0 viewmax=2.2 tickvaluelist=(0 1 2)) display=(line ticks tickvalues) tickvalueattrs=(size=&tickvalues_size.pt));

                            /* Includes the Logrank information in the second plot (top-middle) */

                            entry &p_lt_001 / location=inside autoalign=(TopLeft) border=false  textattrs=(size=&p_value_size.pt);

                            /* Plot the second plot (top-middle) */

                            *stepplot x=x2_axis y=y2_axis  / markerattrs=(symbol=circlefilled ) group=Group;

                            scatterplot y=meananthro_bmi_w&suffix x=re_wk / yerrorlower=lo_bmi_w&suffix yerrorupper=up_bmi_w&suffix group=trt_lng ERRORBARATTRS=(thickness=&errorbar_size.px);

                            seriesplot  y=meananthro_bmi_w&suffix x=re_wk / group=trt_lng lineattrs=(thickness=&linethickness_size.px);

                        endlayout; /* Close of layout overlay for second plot (top-middle) */

                    endcell; /* Close of cell for second plot (top-middle) */

                endlayout; /* Close of layout lattice for second plot (top-middle) */

                /* third plot (top-right) */               

                layout lattice / columns=1 backgroundcolor=&overall_color opaque=true;

                    cell;

                        /* Necessary for label of second plot (top-right) */

                        cellheader;

                            entry "C. Plot 3" {sup " "} / border =false textattrs=(size=&title_size pt);

                        endcellheader;

                        /* Necessary for plot of second plot (top-right) */

                        layout overlay / x2axisopts=(display=(line)) xaxisopts=(&xopts tickvalueattrs=(size=&tickvalues_size.pt)) yaxisopts=(display=(line ticks tickvalues) type=linear linearopts=(viewmin=0 viewmax=0.045 tickvaluelist=(0 .01 .02 .03 .04)) display=(line ticks tickvalues) tickvalueattrs=(size=&tickvalues_size.pt));

                            /* Includes the Logrank information in the second plot (top-right) */

                            entry &p_029 / location=inside autoalign=(TopLeft) border=false  textattrs=(size=&p_value_size.pt);

                            /* Plot the second plot (top-right) */

                            *stepplot x=x2_axis y=y2_axis  / markerattrs=(symbol=circlefilled ) group=Group;

                            scatterplot y=meananthro_whr&suffix x=re_wk / yerrorlower=lo_whr&suffix yerrorupper=up_whr&suffix group=trt_lng ERRORBARATTRS=(thickness=&errorbar_size.px);

                            seriesplot  y=meananthro_whr&suffix x=re_wk / group=trt_lng lineattrs=(thickness=&linethickness_size.px);

                        endlayout; /* Close of layout overlay for second plot (top-right) */

                    endcell; /* Close of cell for second plot (top-right) */

                endlayout; /* Close of layout lattice for second plot (top-right) */

                /* Blank plot */

                layout lattice / columns=1;

                    cell;

                    endcell;

                endlayout;

                /* fourth plot (bottom-left) */               

                layout lattice / columns=1 backgroundcolor=&overall_color opaque=true;

                    cell;

                        /* Necessary for label of fourth plot (bottom-left) */

                        cellheader;

                            entry "D. Plot 4" {sup " "} / border =false textattrs=(size=&title_size pt);

                        endcellheader;

                        /* Necessary for plot of fourth plot (bottom-left) */

                        layout overlay / x2axisopts=(display=(line)) xaxisopts=(&xopts) yaxisopts=(&yopts display=(line ticks tickvalues));

                            /* Includes the Logrank information in the fourth plot (bottom-left) */

                            entry &p_lt_001 / location=inside autoalign=(TopLeft) border=false  textattrs=(size=&p_value_size.pt);

                            /* Plot the fourth plot (bottom-left) */

                            scatterplot y=meananthro_midarm&suffix x=re_wk / yerrorlower=lo_midarm&suffix yerrorupper=up_midarm&suffix group=trt_lng ERRORBARATTRS=(thickness=&errorbar_size.px);

                            seriesplot  y=meananthro_midarm&suffix x=re_wk / group=trt_lng lineattrs=(thickness=&linethickness_size.px);

                        endlayout; /* Close of layout overlay for fourth plot (bottom-left) */

                    endcell; /* Close of cell for fourth plot (bottom-left) */

                endlayout; /* Close of layout lattice for fourth plot (bottom-left) */

                /* fifth plot (bottom-left-middle) */               

                layout lattice / columns=1 backgroundcolor=&overall_color opaque=true;

                    cell;

                        /* Necessary for label of fifth plot (bottom-left-middle) */

                        cellheader;

                            entry "E. Plot 5" {sup " "} / border =false textattrs=(size=&title_size pt);

                        endcellheader;

                        /* Necessary for plot of fifth plot (bottom-left-middle) */

                        layout overlay / x2axisopts=(display=(line)) xaxisopts=(&xopts) yaxisopts=(&yopts display=(line ticks tickvalues));

                            /* Includes the Logrank information in the fifth plot (bottom-left-middle) */

                            entry &p_037 / location=inside autoalign=(TopLeft) border=false  textattrs=(size=&p_value_size.pt);

                            /* Plot the fifth plot (bottom-left-middle) */

                            scatterplot y=meananthro_waist&suffix x=re_wk / yerrorlower=lo_waist&suffix yerrorupper=up_waist&suffix group=trt_lng ERRORBARATTRS=(thickness=&errorbar_size.px);

                            seriesplot  y=meananthro_waist&suffix x=re_wk / group=trt_lng lineattrs=(thickness=&linethickness_size.px);

                        endlayout; /* Close of layout overlay for fifth plot (bottom-left-middle) */

                    endcell; /* Close of cell for fifth plot (bottom-left-middle) */

                endlayout; /* Close of layout lattice for fifth plot (bottom-left-middle) */

                /* sixth plot (bottom-right-middle) */               

                layout lattice / columns=1 backgroundcolor=&overall_color opaque=true;

                    cell;

                        /* Necessary for label of sixth plot (bottom-right-middle) */

                        cellheader;

                            entry "F. Plot 6" {sup " "} / border =false textattrs=(size=&title_size pt);

                        endcellheader;

                        /* Necessary for plot of sixth plot (bottom-right-middle) */

                        layout overlay / x2axisopts=(display=(line)) xaxisopts=(&xopts) yaxisopts=(&yopts display=(line ticks tickvalues));

                            /* Includes the Logrank information in the sixth plot (bottom-right-middle) */

                            entry &p_lt_001 / location=inside autoalign=(TopLeft) border=false  textattrs=(size=&p_value_size.pt);

                            /* Plot the sixth plot (bottom-right-middle) */

                            scatterplot y=meananthro_hip&suffix x=re_wk / yerrorlower=lo_hip&suffix yerrorupper=up_hip&suffix group=trt_lng ERRORBARATTRS=(thickness=&errorbar_size.px);

                            seriesplot  y=meananthro_hip&suffix x=re_wk / group=trt_lng lineattrs=(thickness=&linethickness_size.px);

                        endlayout; /* Close of layout overlay for sixth plot (bottom-right-middle) */

                    endcell; /* Close of cell for sixth plot (bottom-right-middle) */

                endlayout; /* Close of layout lattice for sixth plot (bottom-right-middle) */

                /* seventh plot (bottom-right) */               

                layout lattice / columns=1 backgroundcolor=&overall_color opaque=true;

                    cell;

                        /* Necessary for label of seventh plot (bottom-right)) */

                        cellheader;

                            entry "G. Plot 7" {sup " "} / border =false textattrs=(size=&title_size pt);

                        endcellheader;

                        /* Necessary for plot of seventh plot (bottom-right) */

                        layout overlay / x2axisopts=(display=(line)) xaxisopts=(&xopts) yaxisopts=(&yopts display=(line ticks tickvalues));

                            /* Includes the Logrank information in the seventh plot (bottom-right) */

                            entry &p_lt_001 / location=inside autoalign=(TopLeft) border=false  textattrs=(size=&p_value_size.pt);

                            /* Plot the seventh plot (bottom-right) */

                            scatterplot y=meananthro_midthigh&suffix x=re_wk / yerrorlower=lo_midthigh&suffix yerrorupper=up_midthigh&suffix group=trt_lng ERRORBARATTRS=(thickness=&errorbar_size.px);

                            seriesplot  y=meananthro_midthigh&suffix x=re_wk / group=trt_lng lineattrs=(thickness=&linethickness_size.px);

                        endlayout; /* Close of layout overlay for seventh plot (bottom-right) */

                    endcell; /* Close of cell for seventh plot (bottom-right) */

                endlayout; /* Close of layout lattice for seventh plot (bottom-right) */

                /* Add label to y-axis of figure */

                sidebar / align=left;   

                    entry 'Mean change from baseline (bars are 95% CIs)' / rotate=90 textattrs=(size=&yaxis_size.pt weight=bold);

                endsidebar;

                /* Add label to y-axis of figure */

                sidebar / align=bottom ;   

                    entry 'Week' / textattrs=(size=&yaxis_size.pt weight=bold);

                endsidebar;

                /* Create buffer on bottom of figure */

                sidebar / align=bottom;   

                     entry " ";

                endsidebar;

                /* Add legend to the bottom of figure */

                sidebar / align=bottom;   

                    *discretelegend 'pts' / border=false halign=center valign=bottom valueattrs=(size=7);

                endsidebar;

            endlayout; /* Close of layout lattice for figure */    

        endgraph; /* Close of begingraph statement */

    end;

run;

Attachment
Ask a Question
Discussion stats
  • 0 replies
  • 385 views
  • 0 likes
  • 1 in conversation