Using ANNOTATE to color labels dependent on data. Attempting to color the markers as well. I've added Function='symbol' to the annotate dataset, but am missing something as there are no changes to the markers.
FUNCTION='symbol';
size=5;
text='dot';
position='5';
style='marker';
Data and working code (other than marker color) is below.
DM LOG 'CLEAR';
DM OUTPUT 'CLEAR';
DATA plotme3;
LENGTH Location $10. WeekEnding 8. NetPromoter Threshold Target Maximum 8.;
FORMAT WeekEnding mmddyy10. NetPromoter Threshold Target Maximum percent5.1;
INPUT Location WeekEnding DATE9. NetPromoter Threshold Target Maximum;
CARDS;
Blanchard 23JUN2018 . 0.845 0.861 0.878 Blanchard 07JUL2018 0.667 0.845 0.861 0.878 Blanchard 21JUL2018 0.872 0.845 0.861 0.878 Blanchard 04AUG2018 0.904 0.845 0.861 0.878 Blanchard 18AUG2018 0.852 0.845 0.861 0.878 Blanchard 01SEP2018 0.72 0.845 0.861 0.878 Blanchard 15SEP2018 0.667 0.845 0.861 0.878 Blanchard 29SEP2018 0.95 0.845 0.861 0.878 Blanchard 13OCT2018 0.833 0.845 0.861 0.878 Blanchard 27OCT2018 0.763 0.845 0.861 0.878 Blanchard 10NOV2018 0.821 0.845 0.861 0.878 Blanchard 24NOV2018 0.863 0.845 0.861 0.878 Blanchard 08DEC2018 0.6 0.845 0.861 0.878 Blanchard 22DEC2018 . 0.845 0.861 0.878 RUN;
goptions reset=all;
* prevent surprises from other options being set;
ods noresults;
* keep adobe from opening inside SAS session;
OPTIONS orientation=landscape nodate nonumber;
* create annotate dataset to add labels to the three targets;
* annotate will also color-code the labels and symbols;
DATA anno(KEEP=function x y text style color position size hsys xsys ysys when);
LENGTH function color $8. text $16.;
retain hsys xsys ysys "2" when 'a';
FORMAT x mmddyy10.;
SET plotme3 end=eof;
IF NetPromoter < .845 THEN
DO;
* lowest ranking, text and marker should be red;
FUNCTION='label';
x=WeekEnding;
y=NetPromoter;
color='red';
position='4';
text=TRIM(LEFT(put(NetPromoter, percent5.1))) || "--";
OUTPUT;
FUNCTION='symbol';
size=5;
text='dot';
position='5';
style='marker';
OUTPUT;
*<< not working as expected;
END;
ELSE IF NetPromoter < .861 THEN
DO;
* met threshold, text and marker should be yellow;
FUNCTION='label';
x=WeekEnding;
y=NetPromoter;
color='yellow';
position='4';
text=TRIM(LEFT(put(NetPromoter, percent5.1))) || "--";
OUTPUT;
FUNCTION='symbol';
size=5;
text='dot';
position='5';
style='marker';
OUTPUT;
*<< not working as expected;
END;
ELSE IF NetPromoter < .878 THEN
DO;
* met target, text and marker should be green;
FUNCTION='label';
x=WeekEnding;
y=NetPromoter;
color='green';
position='4';
text=TRIM(LEFT(put(NetPromoter, percent5.1))) || "--";
OUTPUT;
FUNCTION='symbol';
size=5;
text='dot';
position='5';
style='marker';
OUTPUT;
*<< not working as expected;
END;
ELSE
DO;
* highest ranking, text and marker should be magenta;
FUNCTION='label';
x=WeekEnding;
y=NetPromoter;
color='magenta';
position='4';
text=TRIM(LEFT(put(NetPromoter, percent5.1)));
OUTPUT;
FUNCTION='symbol';
size=5;
text='dot';
position='5';
style='marker';
OUTPUT;
*<< not working as expected;
END;
IF eof THEN
DO;
* create labels;
style='Albany';
FUNCTION="label";
x=WeekEnding;
hsys='D';
position='1';
size=15;
color="magenta";
y=.878;
text='Maximum: 87.8%';
OUTPUT;
color="green";
y=.861;
text='Target: 86.1%';
OUTPUT;
color="yellow";
y=.845;
text='Threshold: 84.5%';
OUTPUT;
END;
RUN;
PROC SORT DATA=anno;
WHERE text NE '.';
BY function x y;
RUN;
* creates better spacing on the graph;
* f = font, w = width in pixels, h = height in cells, l = line type (1 is solid, 2-46 dashed lines), v=value (plus, x star, square diamond dot circle), i = interpolation (none, join, spline);
symbol1 v=dot cv=green ci=black i=join l=1 h=2;
symbol2 c=magenta i=join l=3 w=2;
symbol3 c=green i=join l=3 w=2;
symbol4 c=yellow i=join l=3 w=2;
PROC GPLOT DATA=plotme3;
FORMAT NetPromoter Maximum target Threshold percent5.1;
PLOT NetPromoter * WeekEnding=1 Maximum*WeekEnding=2 Target*WeekEnding=3
Threshold*WeekEnding=4 /OVERLAY ch=purple lh=3 skipmiss haxis=axis1
vaxis=axis2 cframe=ligr annotate=anno;
AXIS1 LABEL=(height=1 font=albany color=black '2-Week Period Ending Date')
VALUE=(height=1 font=albany color=black);
AXIS2 LABEL=(angle=90 height=1.0 font=albany color=black 'Net Promoter Score')
VALUE=(height=1 font=albany color=black);
TITLE h=2 f=albany "Net Promoter Score by Pay Period";
RUN;
QUIT;
... View more