Hi! I want to add a vertical line and also a horizontal line, both of specific length,
very close to the Y-axis resp. X-axis in Proc SGPLOT.
At present I do this on the PC using PAINT.NET (from Microsoft).
(On the PC: name.svg --> take out the picture as screencopy.jpg file. Use Paint.net).
It works, but you can see on the details of the lines that my hand is not quite steady.
If possible I would like to specify the length and the position in SGPLOT.
Perhaps there is a better software than PAINT.net to draw straight lines on a graph?
Many thanks in advance!
/Br Anders
How exactly are you specifying "length"?
Adding coordinates for a Series or perhaps a Vector plot would be my idea. Here is an example placing a horizontal line. Provide a different pair of x and y variables for a vertical line. Note that I have cleverly picked a value for y of the horizontal line that is just above the starting value of the Yaxis values= list. If the space between is still too large you could use y values like 55.01 or what appears good to you.
data myline; input xline yline; datalines; 55 55.1 68 55.1 ; data toplot; set sashelp.class myline ; run; proc sgplot data=toplot; scatter x=height y=weight; series x=xline y=yline; xaxis values=(50 to 70 by 5); yaxis values=(55 to 135 by 20); run;
You could use the LINEATTRS option on the series for Xline and Yline to set color, linewidth and even a type as desired.
Use the LINEPARM statement in SGPLOT if you know ahead of time where you want to draw the lines.
Creates a straight line specified by a point and a slope. You can generate a single line by specifying a constant for each required argument. You can generate multiple lines by specifying a numeric variable for any or all required arguments.
EDIT: to limit the line, POLYGON may be better. Either way, I'd use some functionality within PROC SGPLOT to get it created.
How exactly are you specifying "length"?
Adding coordinates for a Series or perhaps a Vector plot would be my idea. Here is an example placing a horizontal line. Provide a different pair of x and y variables for a vertical line. Note that I have cleverly picked a value for y of the horizontal line that is just above the starting value of the Yaxis values= list. If the space between is still too large you could use y values like 55.01 or what appears good to you.
data myline; input xline yline; datalines; 55 55.1 68 55.1 ; data toplot; set sashelp.class myline ; run; proc sgplot data=toplot; scatter x=height y=weight; series x=xline y=yline; xaxis values=(50 to 70 by 5); yaxis values=(55 to 135 by 20); run;
You could use the LINEATTRS option on the series for Xline and Yline to set color, linewidth and even a type as desired.
Hi! I used one "SERIES" for each line. Works VERY well.
I asked one "stupid question" and reived three (3) VERY GOOD answers! ALL of them are working.
This one is perhaps the simplest. But all solutions are of GREAT interest.
MANY THANKS!
/Br Anders
%sganno
data sganno;
%SGLINE(X1=0,Y1=0,X2=50,Y2=0,DRAWSPACE="DATAPERCENT" ,LINECOLOR="black" ,LINETHICKNESS=6)
%SGLINE(X1=0,Y1=25,X2=0,Y2=50,DRAWSPACE="DATAPERCENT" ,LINECOLOR="black" ,LINETHICKNESS=6)
run;
data have;
set sashelp.stocks;
if stock='IBM';
run;
proc sgplot data=have noautolegend sganno=sganno;
loess x=date y=close;
xaxis offsetmin=0.01 ;
yaxis offsetmin=0.01 ;
run;
GANNO solution works well. The "SERIES" solution is simpler.
BUT - I know now how to use GANNO ans similar. VERY useful.
MANY THANKS!
Hi! Do you have any good examples of the use of %SGTEXT ?
Your suggestion eralier was very useful, even if another one was simpler to use.
/Br Anders
Many Thanks!
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9.
Early bird rate extended! Save $200 when you sign up by March 31.
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.
Ready to level-up your skills? Choose your own adventure.