Data visualization with SAS programming

PROC SGPLOT - LEGEND AND CURVELABEL TOGETHER

Accepted Solution Solved
Reply
Contributor
Posts: 42
Accepted Solution

PROC SGPLOT - LEGEND AND CURVELABEL TOGETHER


Hi All,

I have sas 9.3. I am using SGPLOT and I have set of series plot and the legend for the lines and it works fine.

However I also need to add the label to each lines using curvelabel option so that the eye movement is reduced.

The problem is when I use curvelabel option the legend disappears.

Is there a way that I could have both in my plot?

Thank you for your help.

P.S.

Here is the code and the output as an example.

/*THIS GIVES ME THE LEGEND*/

proc sgplot data=sashelp.stocks(where=(date >= "01jan2000"d and stock = "IBM")) ;;

title "Stock Trend : IBM";

series x=date y=close /legendlabel="CCCC";

series x=date y=low   /legendlabel="LLLL";

series x=date y=high  /legendlabel="HHHH";

run;

legend.png

Now I add the curvelabel option. It works but the LEGEND DISAPPEARS

proc sgplot data=sashelp.stocks(where=(date >= "01jan2000"d and stock = "IBM")) ;;

title "Stock Trend : IBM";

series x=date y=close /curvelabel='Close' curvelabelloc=inside curvelabelpos=max  legendlabel="CCCC";

series x=date y=low   /curvelabel='Low'   curvelabelloc=inside  curvelabelpos=max legendlabel="LLLL";

series x=date y=high  /curvelabel='High'  curvelabelloc=inside  curvelabelpos=max legendlabel="HHHH";

legend ;

run;

curvelabel.png


Accepted Solutions
Solution
‎03-18-2015 05:17 PM
Grand Advisor
Posts: 9,748

Re: PROC SGPLOT - LEGEND AND CURVELABEL TOGETHER

Does this do what you need:

proc sgplot data=sashelp.stocks(where=(date >= "01jan2000"d and stock = "IBM")) ;;

title "Stock Trend : IBM";

series x=date y=close /curvelabel='Close' curvelabelloc=inside curvelabelpos=max  legendlabel="CCCC" name='a';

series x=date y=low   /curvelabel='Low'   curvelabelloc=inside  curvelabelpos=max legendlabel="LLLL" name='b';

series x=date y=high  /curvelabel='High'  curvelabelloc=inside  curvelabelpos=max legendlabel="HHHH" name='c';

keylegend 'a' 'b' 'c';

run;

View solution in original post


All Replies
Solution
‎03-18-2015 05:17 PM
Grand Advisor
Posts: 9,748

Re: PROC SGPLOT - LEGEND AND CURVELABEL TOGETHER

Does this do what you need:

proc sgplot data=sashelp.stocks(where=(date >= "01jan2000"d and stock = "IBM")) ;;

title "Stock Trend : IBM";

series x=date y=close /curvelabel='Close' curvelabelloc=inside curvelabelpos=max  legendlabel="CCCC" name='a';

series x=date y=low   /curvelabel='Low'   curvelabelloc=inside  curvelabelpos=max legendlabel="LLLL" name='b';

series x=date y=high  /curvelabel='High'  curvelabelloc=inside  curvelabelpos=max legendlabel="HHHH" name='c';

keylegend 'a' 'b' 'c';

run;

SAS Super FREQ
Posts: 864

Re: PROC SGPLOT - LEGEND AND CURVELABEL TOGETHER

Ballardw is correct. By default, a curvelabel removes a plot from the auto legend because it is considered redundant information. Since the curve label was turned on for all three plot, the auto legend disappeared. However, you can override that behavior by creating your own legend, as in Ballardw's example.

Contributor
Posts: 42

Re: PROC SGPLOT - LEGEND AND CURVELABEL TOGETHER

Thanks Ballardw. It solves my problem.

Post a Question
Discussion Stats
  • 3 replies
  • 734 views
  • 4 likes
  • 3 in conversation