BookmarkSubscribeRSS Feed
csa
Obsidian | Level 7 csa
Obsidian | Level 7

Hi All, I’m trying to display the error bars in the legend of my SGPLOT output. I’m using the following code to generate the graph, but I haven’t been able to figure out why the error bars are not appearing in the legend.
Could someone please help me identify what’s going wrong with the code?

proc sgplot data=have dattrmap=test noautolegend noborder;

styleattrs datacontrastcolors=(black blue red lime) datasymbols=(Asterisk Circle TriangleDown Triangle);
series x=xvar y=mn / name="scatter1" group=trt attrid=X markers;
scatter x=xvar y=mn / name="scatter2" group=trtan yerrorlower=lower
yerrorupper=upper
markerattrs=(size=8)
errorbarattrs=(thickness=1);

legenditem type=markerline name="A" /
label="A (N=%trim(&A))" lineattrs=GraphData1 markerattrs=GraphData1;
legenditem type=markerline name="B" /
label="B (N=%trim(&B))" lineattrs=GraphData2 markerattrs=GraphData2;
legenditem type=markerline name="C" /
label="C (N=%trim(&C))" lineattrs=GraphData3 markerattrs=GraphData3;
legenditem type=markerline name="D" /
label="D (N=%trim(&D))" lineattrs=GraphData4 markerattrs=GraphData4;

keylegend "A" "B" "C" "D"/ location=inside noborder opaque position=TOPRIGHT across=1 down=4;
yaxis label="Plasma (ug/L)" values = (0 200 400 600 800 1000) TICKSTYLE=INSIDE offsetmin=0.05
valueattrs=(family="Times New Roman" size=9) labelattrs=(family="Times New Roman" size=9);
xaxis label="Time (h)" values = (0 6 12 18 24 30 36 42 48) TICKSTYLE=INSIDE offsetmin=0.05
fitpolicy=rotate valueattrs=(family="Times New Roman" size=9) labelattrs=(family="Times New Roman" size=9);*valuesformat=vissc_.;*;

run;

 

Thanks

2 REPLIES 2
Ksharp
Super User
Can you post a graph to explain what error bar you need to display in keylegend ?
And as far as I know you cann't display error bar in keylegend, and you need another workaround way to get job done.
Ksharp
Super User

You want this ?

 


proc summary data=sashelp.stocks nway;
class stock date;
format date year4.;
var close;
output out=have lclm=lclm uclm=uclm mean=mean;
run;




%let path=%sysfunc(pathname(work));  *the path stored the picture for Legend ;
*Make a picture for Legend;
data x;
infile cards truncover;
input stock :$20. x y center lower upper label_pos;
cards;
IBM 1.5 3 
IBM 2 3 2  2.6  3.4  2.5
IBM 2.5 3 
Intel 1.5 2 
Intel 2 2 2  1.6  2.4  2.5
Intel 2.5 2 
Microsoft 1.5 1 
Microsoft 2 1 2  0.6  1.4  2.5
Microsoft 2.5 1 
;
run;
title;
ods listing gpath="&path." style=htmlblue image_dpi=300;
ods graphics/width=140px height=100px reset=index imagename='legend' outputfmt=png noborder attrpriority=none;
proc sgplot data=x noautolegend pad=0 noborder;
styleattrs datacontrastcolors=(black blue red lime) datacolors=(black blue red lime) 
           datasymbols=(Asterisk Circle TriangleDown Triangle);

series x=x y=y/lineattrs=(pattern=solid) group=stock;
scatter x=center y=y/markerattrs=(size=15)  yerrorlower=lower yerrorupper=upper group=stock;
scatter x=label_pos y=y/datalabel=stock datalabelattrs=(size=15) labelstrip
                        markerattrs=(size=0) datalabelpos=right group=stock;

xaxis display=none   offsetmax=0.5; 
yaxis display=none  ; *offsetmin=0.1 offsetmax=0.1;
run;






%sganno
data sganno;
 %SGIMAGE(
     IMAGE="&path.\legend1.png",
     ANCHOR="CENTER" ,
	 IMAGESCALE="FITHEIGHT",
	 HEIGHT=25,
     HEIGHTUNIT= "PERCENT",
     LAYER="FRONT",

     DRAWSPACE="WALLPERCENT",
     X1=88,
     Y1=88,ID="BAR"
     )
run;
ods graphics /reset=all attrpriority=none;
proc sgplot data=have  sganno=sganno  noborder noautolegend;
styleattrs datacontrastcolors=(black blue red lime) datasymbols=(Asterisk Circle TriangleDown Triangle);
series x=date y=mean /group=stock markers lineattrs=(pattern=solid);
scatter x=date y=mean / group=stock yerrorlower=lclm
yerrorupper=uclm
markerattrs=(size=8)
errorbarattrs=(thickness=1);
run;

Ksharp_0-1762418678863.png

 

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 450 views
  • 5 likes
  • 2 in conversation