I am using SAS 9.4 on Windows.
I am making a set of scatter plots using PROC TEMPLATE. Each plot has two lines -- one for the results of quantile regression and one for the result of OLS regression. I would like to take the labels for the graph out of the individual plots and put them in a margin. Right now they clutter the plots, are hard to read and are redundant.
First, get the data:
data quantreg.anscombe; infile datalines firstobs=5; input @1 X1 4.1 @9 y1 4.2 @18 X2 4.1 @26 Y2 4.2 @34 X3 4.1 @41 y3 4.2 @48 x4 4.1 @57 Y4 4.2; datalines; I II III IV x1 y1 x2 y2 x3 y3 x4 y4 1 2 3 4 5 6 1234567890123456789012345678901234567890123456789012345678901234567890 10.0 8.04 10.0 9.14 10.0 7.46 8.0 6.58 8.0 6.95 8.0 8.14 8.0 6.77 8.0 5.76 13.0 7.58 13.0 8.74 13.0 12.74 8.0 7.71 9.0 8.81 9.0 8.77 9.0 7.11 8.0 8.84 11.0 8.33 11.0 9.26 11.0 7.81 8.0 8.47 14.0 9.96 14.0 8.10 14.0 8.84 8.0 7.04 6.0 7.24 6.0 6.13 6.0 6.08 8.0 5.25 4.0 4.26 4.0 3.10 4.0 5.39 19.0 12.50 12.0 10.84 12.0 9.13 12.0 8.15 8.0 5.56 7.0 4.82 7.0 7.26 7.0 6.42 8.0 7.91 5.0 5.68 5.0 4.74 5.0 5.73 8.0 6.89 ;
then get the regressions:
proc glm data = quantreg.anscombe; model y1 = x1; run; quit; proc quantreg data = quantreg.anscombe; model y1 = x1; run; proc glm data = quantreg.anscombe; model y2 = x1; run; quit; proc quantreg data = quantreg.anscombe; model y2 = x1; run; proc glm data = quantreg.anscombe; model y3 = x1; run; quit; proc quantreg data = quantreg.anscombe; model y3 = x1; run; proc glm data = quantreg.anscombe; model y4 = x1; run; quit; proc quantreg data = quantreg.anscombe; model y4 = x1; run;
finally, the part I am puzzled about, the plot
proc template; define statgraph ScatPlots; begingraph; layout lattice / rows=2 columns=2; layout overlay; scatterplot x = x1 y = y1; lineparm x = 0 y = 3.000090909 slope = 0.500090909/curvelabel = "OLS fit"; lineparm x = 0 y = 3.24 slope = 0.48/curvelabel = "Quantreg for median" lineattrs = (color = red) curvelabelattrs = (color = red) curvelabelposition = MIN; endlayout; layout overlay; scatterplot x = x1 y = y2; lineparm x = 0 y = 3.000909091 slope = 0.5/curvelabel = "OLS fit"; lineparm x = 0 y = 3.13 slope = 0.5/curvelabel = "Quantreg for median" lineattrs = (color = red) curvelabelattrs = (color = red) curvelabelposition = MIN; endlayout; layout overlay; scatterplot x = x1 y = y3; lineparm x = 0 y = 3.002454545 slope = 0.5/curvelabel = "OLS fit"; lineparm x = 0 y = 4.01 slope = 0.345/curvelabel = "Quantreg for median" lineattrs = (color = red) curvelabelattrs = (color = red) curvelabelposition = MIN; endlayout; layout overlay; scatterplot x = x1 y = y4; lineparm x = 0 y = 9.231363636 slope = -0.192272727/curvelabel = "OLS fit"; lineparm x = 0 y = 6.8067 slope = 0.0167/curvelabel = "Quantreg for median" lineattrs = (color = red) curvelabelattrs = (color = red) curvelabelposition = MIN; endlayout; endlayout; endgraph; end; run; proc sgrender data=quantreg.anscombe template=ScatPlots; run;
You can see that each plot has two big bits of text. I'd like to put all those in a margin and remove them from the four plots.
Would a LEGEND in a SIDEBAR be adequate?
proc template;
define statgraph ScatPlots;
begingraph;
layout lattice / rows=2 columns=2;
sidebar / align=bottom;
layout gridded / border=true ;
discretelegend "OLS" "Median" / across=2;
endlayout;
endsidebar;
layout overlay;
scatterplot x = x1 y = y1;
lineparm x = 0 y = 3.000090909 slope = 0.500090909/ legendlabel = "OLS fit" name="OLS";
lineparm x = 0 y = 3.24 slope = 0.48/ legendlabel = "Quantreg for median" lineattrs = (color = red) curvelabelattrs = (color = red) curvelabelposition = MIN name="Median";
endlayout;
layout overlay;
scatterplot x = x1 y = y2;
lineparm x = 0 y = 3.000909091 slope = 0.5/;
lineparm x = 0 y = 3.13 slope = 0.5/ lineattrs=(color = red);
endlayout;
layout overlay;
scatterplot x = x1 y = y3;
lineparm x = 0 y = 3.002454545 slope = 0.5;
lineparm x = 0 y = 4.01 slope = 0.345/ lineattrs=(color = red);
endlayout;
layout overlay;
scatterplot x = x1 y = y4;
lineparm x = 0 y = 9.231363636 slope = -0.192272727/;
lineparm x = 0 y = 6.8067 slope = 0.0167/ lineattrs=(color = red);
endlayout;
endlayout;
endgraph;
end;
run;
Would a LEGEND in a SIDEBAR be adequate?
proc template;
define statgraph ScatPlots;
begingraph;
layout lattice / rows=2 columns=2;
sidebar / align=bottom;
layout gridded / border=true ;
discretelegend "OLS" "Median" / across=2;
endlayout;
endsidebar;
layout overlay;
scatterplot x = x1 y = y1;
lineparm x = 0 y = 3.000090909 slope = 0.500090909/ legendlabel = "OLS fit" name="OLS";
lineparm x = 0 y = 3.24 slope = 0.48/ legendlabel = "Quantreg for median" lineattrs = (color = red) curvelabelattrs = (color = red) curvelabelposition = MIN name="Median";
endlayout;
layout overlay;
scatterplot x = x1 y = y2;
lineparm x = 0 y = 3.000909091 slope = 0.5/;
lineparm x = 0 y = 3.13 slope = 0.5/ lineattrs=(color = red);
endlayout;
layout overlay;
scatterplot x = x1 y = y3;
lineparm x = 0 y = 3.002454545 slope = 0.5;
lineparm x = 0 y = 4.01 slope = 0.345/ lineattrs=(color = red);
endlayout;
layout overlay;
scatterplot x = x1 y = y4;
lineparm x = 0 y = 9.231363636 slope = -0.192272727/;
lineparm x = 0 y = 6.8067 slope = 0.0167/ lineattrs=(color = red);
endlayout;
endlayout;
endgraph;
end;
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.