BookmarkSubscribeRSS Feed
davehalltwp
Quartz | Level 8

Hi,

 

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!

 

...dave

 

Here is my data (for one patient):

 

obs         subjid       session  thresh     slope      intercpt

35

36

101004

101004

1

2

-1.1750

-1.425

0.03274

0.03274

-1.57381

-1.57381

371010043-1.30.03274-1.57381
381010044-1.80.03274-1.57381
391010045-1.4250.03274-1.57381
401010046-1.4250.03274-1.57381
411010047-1.1750.03274-1.57381
421010048-1.30.03274-1.57381
431010049-1.30.03274-1.57381

 

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;

 

 

14 REPLIES 14
Reeza
Super User

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.

 

 

davehalltwp
Quartz | Level 8

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...

Jay54
Meteorite | Level 14

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.

davehalltwp
Quartz | Level 8

Thanks, Sanjay.  I'll see if those are options.

davehalltwp
Quartz | Level 8

http://support.sas.com/documentation/cdl/en/grstatproc/62603/HTML/default/viewer.htm#a003155517.htm

 

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! 

Reeza
Super User

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. 

davehalltwp
Quartz | Level 8

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.

Reeza
Super User

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;

http://documentation.sas.com/?docsetId=grstatproc&docsetTarget=n1gbe4z3i5l8hin1ajyvrwlcv00v.htm&docs...

 

Graph tip sheet

http://support.sas.com/rnd/app/ODSGraphics/TipSheet_ODSGraphics.pdf

 

ODS Graphics

http://support.sas.com/documentation/prod-p/grstat/9.4/en/PDF/odsbasicg.pdf?locale=en#nameddest=http...

WarrenKuhfeld
Rhodochrosite | Level 12

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.

http://go.documentation.sas.com/?docsetId=statug&docsetTarget=statug_templt_sect017.htm&docsetVersio...

ballardw
Super User

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

 

DanH_sas
SAS Super FREQ

Try setting OUTPUTFMT=PNG and see if you like the RTF output better with SGPLOT.

 

ods graphics / outputfmt=png;

 

Hope this helps!

Dan

davehalltwp
Quartz | Level 8

THanks to all.  My plot looks good!

 

 

GraphGuy
Meteorite | Level 14

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.)

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 14 replies
  • 9138 views
  • 9 likes
  • 7 in conversation