11-02-2017 06:28 PM
I'm trying to add a regression line to a GPLOT scatter plot, one plot per subject. I have the slope and intercept of the regression line. Is there a simple way to add the line? I was able to get it going with PROC SGPLOT, but the output in the RTF file is much rougher. It would be preferable just to enhance the GPLOT.
Thanks in advance!
Here is my data (for one patient):
Here is the existing GPLOT code (I'm leaving out the setup work for axes, legend, symbols, etc. to keep this post cleaner):
proc gplot data = lbplot;
by trtn usubjid;
plot thresh*session=trtn /vaxis=axis2 haxis=axis1 frame legend=legend1;
11-02-2017 06:55 PM - edited 11-02-2017 07:00 PM
Can you use SGPLOT instead?
If so, it would be a single REG statement.
EDIT: Sorry, I see you do have SGPLOT working. I would recommend sticking with that approach. I'm not sure what you meant by 'rougher' the output from SG procedures are much nicer than GPLOT in my experience. You can try changing the device, DPI or other settings to get better graphics, if necessary.
11-02-2017 08:34 PM
Thanks for the reply, Reeza. Yeah, I could use SGPLOT I suppose. I don't know why the .rtf file it generated doesn't look as good. Maybe all the setup the program did applied to the GPLOT but doesn't get applied to the SGPLOT?
What would be the REG line? I tried something, I think maybe (PARMLINE?) and got a line, but it also insisted on printing a goofy box (giving the SLOPE and INTERCPT) on the plot that I couldn't suppress.
Thanks, I wish I knew more about plotting and graphing...
11-02-2017 09:39 PM
Sometimes the default EMF Plus format output for RTF does not render very well. However, you can use other image formats such as PNG. Use OUTPUTFMT=PNG on the ODS Graphics statement. Or, you can produce PDF output which also renders well.
11-02-2017 10:02 PM
proc sgplot data=sashelp.class; reg x=height y=weight / CLM CLI; run;
I haven't had a chance to test it, but I did a little research on Reeza's comment. Does this REG statement produce a line based on the same SLOPE/INTERCEPT produced by PROC REG? I know that's probably a really dumb question, but this seems too easy!
11-02-2017 10:10 PM
Pretty sure, it's easy enough to check though, create the one through your previous method and the REG statement and see how they look. There's also a way to get the formula embedded if you want to be 100% sure.
11-02-2017 10:15 PM
Wow, Reeza, displaying the formula was actually something that was requested. I better look that up! You all have been so helpful, thanks so much.
11-02-2017 10:04 PM
None of the axis/legend statements that are used for the GRAPH procedures work for the SG procedures, they use their own syntax, which is easier to use in my opinion.
I don't know much about graphing myself, but I know where to find examples and that's almost always my starting point. No one really writes code from scratch, do they?
ods rtf file='/folders/myfolders/sample.rtf' style=meadow; ods graphics / imagefmt=png; proc sgplot data=sashelp.class; reg x=height y=weight / nolegfit ; run; ods rtf close;
Graph tip sheet
11-03-2017 06:15 AM
The REG statement in SGPLOT does not share code with PROC REG. Rather, the REG statement and PBSPLINE statement use the same code, which was originally written for the PBSPLINE transformation in PROC TRANSREG.
Here is an example of putting inset formulas into a fit plot.
11-03-2017 01:06 PM
If you want to overlay in Proc GPLOT you can't specify a different data set than the scatter. You would need to use a Plot2 thresh*session=subjid and require a LOT of symbol statements to do the regression plots. (Overlay won't work with y*x=z type plots)
Here is an example combining a scatter plot and regression in sgplot.
proc sgplot data=sashelp.class; scatter x=height y=weight; reg x=height y=weight / group=sex CLM CLI; run;
If want to use your regression data with scatter you will need to combine the data with the scatter and then delve into the joys of the Graphic Template Language to use the LINEPARM plot type
11-03-2017 01:25 PM
Try setting OUTPUTFMT=PNG and see if you like the RTF output better with SGPLOT.
ods graphics / outputfmt=png;
Hope this helps!
11-06-2017 11:16 AM
If you wanted to use gplot, you could annotate the line (and regression equation), and the annotate dataset could do that separately for each plot, based on the 'by' statement. (If you can share your data, and annotate dataset, I could create some code to do that for you.)