BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
davehalltwp
Quartz | Level 8

As you know by now, I'm just learning about plotting!

 

I have developed a line plot of a mean across timepoints, with bars for 95% confidence interval. (PROC GPLOT) I'm trying to create a very simple legend, simply indicating that the red line is treatment group 1 and the blue line is treatment group 2.  Everything I try generates stuff that I don't want. 

 

Is there an easy way to populate the legend with something simple like this?

 

--- Placebo      ---- Study Drug

 

 

Here is my code (I found it online and it does exactly what I need).  Mean1 is the mean per session, Thresh1 contains LCM and UCM.

 

proc gplot data=prep5;    
     plot thresh1*session mean1*session thresh2*session mean2*session / overlay haxis=axis1 vaxis=axis2  
    /*legend=legend1*/;
 title1 h=8pt color=black font='courier' J=L "&titlel1";
 title2 h=8pt color=black font='courier' J=L "Protocol: &titlel2 													Page 1 of 1";

 title5 h=8pt color=black font='courier' J=C "&titlel5";
 title6 h=8pt color=black font='courier' J=C "&titlel6";
 title7 h=8pt color=black font='courier' J=C "&titlel7";
  
run; 
1 ACCEPTED SOLUTION

Accepted Solutions
GraphGuy
Meteorite | Level 14

I often use title or footnote statements to 'fake' a legend, to get one exactly like I want it.

In your case, you could use something like the following:

 

title8 c=blue "--- Placebo" c=red "  --- Study Drug";

 

View solution in original post

5 REPLIES 5
Cynthia_sas
SAS Super FREQ
I'd recommend investigating the LEGEND option for GPLOT and then the LEGEND statement. You currently have the LEGEND option commented out, I am guessing because you did not have a LEGEND1 statement.

Consider this example http://www2.sas.com/proceedings/forum2007/163-2007.pdf on page 2 with the use of the simple LEGEND option to place a legend on the plot.

Then, look on page 3 at the use of the LEGEND1 statement and legend=legend1 option. You should get an idea of how to do what you want.

Cynthia
Reeza
Super User

If you're just learning graphing in SAS I would strongly recommend learning SG procedures instead of GPLOT procedures. 

 

There is more on GPLOT currently - because it's really really old. SG is available in more versions of SAS, you have more control over your graphics and it produces much better quality graphics. 

Cynthia_sas
SAS Super FREQ
You'll need 9.2 or higher to run SGPLOT. I agree with Reeza that the SG procedures are easier to start with then the older SAS/Graph procedures.

Cynthia
davehalltwp
Quartz | Level 8

Thanks, Cynthia.  I went through Wendi's paper and was able to come up with something that'll be good enough.

 

I will definitely take yours and Reeza's advice and learn about SGPLOT!

GraphGuy
Meteorite | Level 14

I often use title or footnote statements to 'fake' a legend, to get one exactly like I want it.

In your case, you could use something like the following:

 

title8 c=blue "--- Placebo" c=red "  --- Study Drug";

 

SAS INNOVATE 2024

Innovate_SAS_Blue.png

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. 

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.

Get the $99 certification deal.jpg

 

 

Back in the Classroom!

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

View all other training opportunities.

Discussion stats
  • 5 replies
  • 761 views
  • 2 likes
  • 4 in conversation