BookmarkSubscribeRSS Feed
deleted_user
Not applicable
Is there any way I can make a legend of reflabels in gplot?

I am basically plotting my data of mean against date. But I have two reflabels, namely:
**Current - Line type =1 ; colour = blue
** Average - Line type =3; colour =red

Is there anyway I can have this 2 lines (current and average) in my legend.

Please help
Really appreciate it. Thanks
5 REPLIES 5
GraphGuy
Meteorite | Level 14
One way would be to use annotate...

Annotate the colored line segments (using 'move' and 'draw').
And then annotate the descriptive text (using 'label').
deleted_user
Not applicable
I have already labelled the vref's using the reflabels. But because of the heavy data, its not showing properly. Even after using the function 'frontref'.

Hence the reason why i was wondering if there is a way around where I can make legend which shows outside the graph...
GraphGuy
Meteorite | Level 14
Another way with gplot would be to create some data observations that will "look like" a reference line, such as...


data my_data; set sashelp.class;
current=130;
average=105;
run;

symbol1 value=dot color=black;
symbol2 value=none interpol=line l=1 color=blue;
symbol3 value=none interpol=line l=3 color=red;

legend1 label=none position=(bottom center);

proc gplot data=my_data;
plot weight*height=1 current*height=2 average*height=3 /
overlay legend=legend1;
run;
DanH_sas
SAS Super FREQ
As an alternative, if you have SAS 9.2, you can use PROC SGPLOT which give you the ability to directly associate reflines with the legend:

[pre]
proc sgplot data=sashelp.class;
scatter x=age y=weight;
refline 90 / legendlabel="ninty pounds" name="a" lineattrs=(color=blue);
refline 100 / legendlabel="one hundred pounds" name="b" lineattrs=(color=red);
keylegend "a" "b";
run;
[/pre]

Hope this helps,
Dan
deleted_user
Not applicable
Thanks to both DanH and Robert Allison

Regards

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
  • 743 views
  • 0 likes
  • 3 in conversation