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

Our biggest data and AI event of the year.

Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.

Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.

 

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 1523 views
  • 0 likes
  • 3 in conversation