BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
MaryA_Marion
Lapis Lazuli | Level 10

I have tried to do this two ways. I want to plot two regression lines. I am not sure I have the correct sg procedure for I am not getting the two regression lines I want and I don't know why the legend is not positioning itself in top left corner in proc gplot. No errors are indicated. Any ideas? Thanks. MM

 

data simpson;
input week X Y percentLA;
percentRecall=X/Y;
datalines;
1  60 200   0
1 320 800   0
2 640 800 100
2 180 200 100
;
proc sgscatter data=simpson;
title 'Simpson Paradox';
plot percentRecall*percentLA / group=week;
run;

data simpson2;
input week percentRecall percentLA;
cards;
1 .3   0
2 .4   0
1 .8 100
2 .9 100
;
PROC GPLOT DATA=simpson2;
PLOT percentRecall*percentLA=week;
symbol1 value=dot i=r ci=orange;
symbol2 value=dot i=r ci=blue;
legend mode=protect down=2 position=(top left);
run; quit;
1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

I might suggest spending time learning the SGPLOT as there are not any updates coming with the device based GPLOT procedure.

 

Generally you want to make sure that all the symbol, axis, legend and/or pattern statements are defined before the graphic procedure when using Gplot or Gchart.

It is a good idea to explicitly number your legends as well as symbols. Then you need to tell the procedure which legend to use.

 

This shows two plots with the legend:

symbol1 value=dot i=r ci=orange;
symbol2 value=dot i=r ci=blue;
legend1 mode=protect down=2 position=(top left);

PROC GPLOT DATA=simpson2;
PLOT percentRecall*percentLA=week
  / legend=legend1;

run; quit;

Which will conflict with the y axis label but the legend does appear in the upper left.

At least for this data I might suggest placing it inside the graph.

A similar graph with SGPLOT:

proc sgplot data=simpson2;
   styleattrs datacontrastcolors=(orange blue);
   reg x=percentla y=percentrecall / group=week;
   keylegend  /down=2  location=inside
               position=topleft
   ;
run;

View solution in original post

5 REPLIES 5
ballardw
Super User

I might suggest spending time learning the SGPLOT as there are not any updates coming with the device based GPLOT procedure.

 

Generally you want to make sure that all the symbol, axis, legend and/or pattern statements are defined before the graphic procedure when using Gplot or Gchart.

It is a good idea to explicitly number your legends as well as symbols. Then you need to tell the procedure which legend to use.

 

This shows two plots with the legend:

symbol1 value=dot i=r ci=orange;
symbol2 value=dot i=r ci=blue;
legend1 mode=protect down=2 position=(top left);

PROC GPLOT DATA=simpson2;
PLOT percentRecall*percentLA=week
  / legend=legend1;

run; quit;

Which will conflict with the y axis label but the legend does appear in the upper left.

At least for this data I might suggest placing it inside the graph.

A similar graph with SGPLOT:

proc sgplot data=simpson2;
   styleattrs datacontrastcolors=(orange blue);
   reg x=percentla y=percentrecall / group=week;
   keylegend  /down=2  location=inside
               position=topleft
   ;
run;
MaryA_Marion
Lapis Lazuli | Level 10

One of my problems with the sg series of graphics is that I'm never sure which one to use (sgplot, sgscatter, sgpanel). Is there a summary of what these procedures do somewhere? I sometimes get lost in the documentation. I need to post it somewhere where I can see it. Thank  you for your reply.

DanH_sas
SAS Super FREQ

Basically, it breaks down like this:

  • SGPLOT is used to create "single-celled" plots. Think of it as taking all of the plots you want to overlay and putting them in one box.
  • SGPANEL is used to a classification panel of plots. Think of it as taking the box from SGPLOT and replicating it in a panel based on unique values for one or more classification variables.
  • SGSCATTER is used to create panels of scatter (or series) plots *NOT* based on classification. It can also produce scatterplot matrices. Each X/Y variable pair produces a cell in the panel (the scatterplot matrix statement just uses a list of variables to produce the panel).

Hope this helps!

Dan

ballardw
Super User

@MaryA_Marion wrote:

One of my problems with the sg series of graphics is that I'm never sure which one to use (sgplot, sgscatter, sgpanel). Is there a summary of what these procedures do somewhere? I sometimes get lost in the documentation. I need to post it somewhere where I can see it. Thank  you for your reply.


Way back when, meaning SAS Version 6, I was given some tasks to do and two stack-feet of SAS manuals (stack foot is how high the pile measures when you lay the books on a table and stack them).

Look at procedure, try the sample programs, look at options, try code with my data. Wash, rinse, repeat until until the data matched the requirements for the graphing procedure and the output looked right.

 

Now days you don't have to worry about customizing the device drivers (Proc Gdevice) to get desired appearance which was pretty much a requirement with the Gplot/ Gchart procedures at the time if you did not have exactly the printer in the lists provided or wanted to use some of the less common options. I won't even go into the Graphic Stream File output learning curve.

 

Start at https://support.sas.com/en/knowledge-base/graph-samples-gallery.html for a whole bunch of complete examples of code and data. Look for a graph similar to what you want, or has elements that you want. Steal code freely to modify.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 5 replies
  • 1096 views
  • 4 likes
  • 3 in conversation