Reputation: 11
I have an sgplot that plots 2 series which I need to annotate with a number of lines. I understand how to add standard reflines (see below), BUT
My problem is that I can't work out how to add a refline between 2 distinct points. I.e a vertical dashed line at xaxis value of 50 between yaxis values 0 and -50. I need to set the start and end of each line, not just the point on the axis it begins.
proc sgplot data = all_sd_dplot noautolegend ;
by variablecode ;
where variablecode='V01'
and comparisonstudyid in (29318 29322);
series x=bin y= sigmavalue / group=legendname name="series";
series x=bin y= fit / group=legendname name="series" LINEATTRS= (color = black thickness=2);
yaxis values=(-160 to 20 by 20) label = "Accumulated minutes over baseline";
xaxis values = (0 12 24 36 48 60) label = "Hours";
REFLINE 0 / AXIS= Y TRANSPARENCY = 0.2 LINEATTRS= (COLOR=black pattern=dot thickness=2); *baseline;
REFLINE 4 / AXIS= X TRANSPARENCY = 0.5 LINEATTRS= (COLOR=red); *end of SD;
REFLINE 0 / AXIS= X TRANSPARENCY = 0.5 LINEATTRS= (COLOR=blue); *start of SD;
REFLINE -135 / AXIS= Y TRANSPARENCY = 0.2 LINEATTRS= (COLOR=black pattern=dot thickness=2); *Y0;
run;
Any help would be much appreciated!!
Upvotes: 1
Views: 7592
Reputation: 1
Perhaps "VECTOR" usage in the following SAS-UG paper (http://pharmasug.org/download/papers/SA-AD-02.pdf) could work (see example on page 3).
Upvotes: 0
Reputation: 63424
This feels easier to me to use with annotations, rather than using SGPLOT functions. You could certainly do like Reeza says and add those in as rows in your dataset, but that might not be ideal for a few reasons; annotations really exist for this purpose, and they keep it more well organized in my opinion (though certainly there are times it's easier to cheat).
Using Reeza's example in part, here's how I'd do it:
proc sort data=sashelp.class out=class;
by sex;
run;
data class_annotations;
x1space='DataValue';
y1space='DataValue';
x2space='DataValue';
y2space='DataValue';
x1=13;
y1=80;
x2=13;
y2=120;
function='line';
output;
x1=15;
x2=15;
output;
run;
proc sgplot data=class sganno=class_annotations;
by sex;
scatter x=age y=weight;
scatter x=age y=height/ y2axis;
run;
Upvotes: 0
Reputation: 21274
I don't think there's a way to do it using refline. I think you'll need to create some fake data in your dataset to have your start/end point and the rest of the values missing. Then use series to draw the line. I would also recommend posting over at communities.sas.com so one of the SAS Graph guys can help.
proc sort data=sashelp.class out=class;
by sex;
run;
data class;
set class;
by sex;
if last.sex then do;
x=13; y=75;output;
x=18; y=75; output;
end;
else output;
run;
proc sgplot data=class;
by sex;
scatter x=age y=weight;
scatter x=age y=height;
series x=x y=y/lineattrs=(color=red thickness=2 pattern=solid);
run;
Upvotes: 1