04-01-2015 10:30 AM
I'm using sgscatter and have two questions about controlling the output.
1. On the output, I would like to include a legend that includes 'fit' and prediction/confidence limits. It would be akin to the legendlabel="Fit" option in sgplot.
2. Is there a good work around to altering my xaxis value? I would like to control these for a couple of my plots, but am unsure of how to do so in sgscatter plot. Is it even possible?
Below is the basic structure for my code.
proc sgscatter data=have;
plot a1*b1 a2*b2 / reg =(clm cli) ;
02-08-2016 09:36 AM
Hi Sophia, instead of using SGSCATTER, you can use the Lattice Layout in GTL to obtain a scatterplot containing more than one cell, and the REGRESSIONPLOT, SCATTERPLOT and MODELBAND statements can produce your regression line with the various fits. You can then produce your legend with the DISCRETELEGEND statement which gives you more options. Also you can edit the x-axis with the XAXISOPTS options.
Below is example code that you can use.
proc template; define statgraph scattertemp; begingraph; layout lattice / columns = 2; layout overlay / xaxisopts = (linearopts=(viewmin=0 viewmax = 8000)); modelband "myclm"; modelband "mycli" / outlineattrs=GraphPredictionLimits display=(outline); scatterplot x=weight y=mpg_highway; regressionplot x=weight y=mpg_highway / clm = "myclm" cli = "mycli" name = "regleg" legendlabel = "Fit and Confidence Limits"; endlayout; layout overlay; modelband "myclm2"; modelband "mycli2" /outlineattrs=GraphPredictionLimits display=(outline); scatterplot x=horsepower y=msrp; regressionplot x=horsepower y=msrp /clm = "myclm2" cli = "mycli2"; endlayout; sidebar / align=bottom; discretelegend "regleg" / border=off; endsidebar; endlayout; endgraph; end; run; proc sgrender data = sashelp.cars template = scattertemp; run;
02-08-2016 11:31 PM
You can use the TMPLOUT="filename" option to get the GTL generated by the SGSCATTER procedure. It will look similar to what Kris has proposed. Then, you can add the options like LegendLabel, etc to customize the graph. Or, try using the ODS Graphics Designer to create your GTL graph.