Data visualization with SAS programming

How to do a Very Simple Legend?

Accepted Solution Solved
Reply
Contributor
Posts: 23
Accepted Solution

How to do a Very Simple Legend?

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; 

Accepted Solutions
Solution
‎11-10-2017 08:55 AM
SAS Employee
Posts: 1,024

Re: How to do a Very Simple Legend?

Posted in reply to davehalltwp

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


All Replies
SAS Super FREQ
Posts: 9,259

Re: How to do a Very Simple Legend?

Posted in reply to davehalltwp
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
Super User
Posts: 22,857

Re: How to do a Very Simple Legend?

Posted in reply to davehalltwp

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. 

SAS Super FREQ
Posts: 9,259

Re: How to do a Very Simple Legend?

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
Contributor
Posts: 23

Re: How to do a Very Simple Legend?

Posted in reply to Cynthia_sas

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!

Solution
‎11-10-2017 08:55 AM
SAS Employee
Posts: 1,024

Re: How to do a Very Simple Legend?

Posted in reply to davehalltwp

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";

 

☑ This topic is solved.

Need further help from the community? Please ask a new question.

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