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

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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