proc sql;
create table myclass as
select age,height,mean(height) as mHeight
from sashelp.class
;
quit;
proc sgplot data=myclass;
scatter x=age y=height;
refline 14 /axis=x labelloc=inside label="The Reference Line" lineattrs=(color=green);
run;
Is it possible to change the label “The reference Line” from horizontal to vertical?
Or add a data point or two and use a TEXT plot.
proc sql;
create table work.myclass as
select age,height,mean(height) as mHeight
from sashelp.class
;
quit;
data work.label;
age=14.2;
y=70;
Labeltext= "The Reference Line";
run;
data work.plot;
set work.myclass
work.label;
run;
proc sgplot data=work.plot;
scatter x=age y=height/ name='scatter';
refline 14 /axis=x labelloc=inside label="" lineattrs=(color=green);
text x=age y=y text=labeltext /rotate=90 name='text';
keylegend 'scatter';
run;
Changing the Rotate angle to =90 will make it read from top to bottom. Adjust the x and y coordinates to be "nice". There are also some text appearance options available with a Text plot, such as BACKLIGHT not available in REFLINE.
I can't find any option to rotate the label. SG-Annotation is the next best thing, but rather clumsy. You might also consider a compromise such as:
proc sgplot data=myclass;
scatter x=age y=height;
refline 14 /axis=x labelloc=inside label="Reference/Line"
lineattrs=(color=green) labelpos=min splitchar="/";
run;
after all, horizontal is always easier to read.
Hi PG,
Thanks for the info you posted -- agreed with you, with splitting label, it is nice. I don't have to use annotation.
Best,
John
Or add a data point or two and use a TEXT plot.
proc sql;
create table work.myclass as
select age,height,mean(height) as mHeight
from sashelp.class
;
quit;
data work.label;
age=14.2;
y=70;
Labeltext= "The Reference Line";
run;
data work.plot;
set work.myclass
work.label;
run;
proc sgplot data=work.plot;
scatter x=age y=height/ name='scatter';
refline 14 /axis=x labelloc=inside label="" lineattrs=(color=green);
text x=age y=y text=labeltext /rotate=90 name='text';
keylegend 'scatter';
run;
Changing the Rotate angle to =90 will make it read from top to bottom. Adjust the x and y coordinates to be "nice". There are also some text appearance options available with a Text plot, such as BACKLIGHT not available in REFLINE.
Thanks, ballardw. Text plot is much easier than annotation in this case for me at least. I really appreciate it.
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.
Find more tutorials on the SAS Users YouTube channel.