BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
KACH
Calcite | Level 5

I am trying to make a bar chart to compare treatment effects in two groups. Data

 

 

data ES;
input label $ RandomisedTo $ ES ES_lower ES_upper
Chest Intervention 0.27078 0.11417 0.42739
Chest Control -0.03958 -0.14217 0.06302
Lat Intervention 0.07824 -0.07517 0.23165
Lat Control -0.13788 -0.27184 -0.00392
VO2 Intervention 0.04811 -0.09418 0.19039
VO2 Control -0.07190 -0.20947 0.06568
;
run;

 

my code is this

 

proc sgplot data=ES(where=(RandomisedTo ne '')) noborder;
 refline 0 / axis=x;
 highlow y=label low=ES_lower high=ES_upper / group=RandomisedTo type=bar groupdisplay=cluster
 barwidth=0.6 clusterwidth=0.2;
 scatter x=ES y=label / markerattrs=(symbol=CircleFilled color=black size=5) group=RandomisedTo groupdisplay=cluster 
 legendlabel=' ';
 yaxis display=(noline) label='Variable';
 keylegend / noborder title='group';
 xaxis values=(-0.5 to 1.5 by 0.25) label='Effect size';
run;

and what i get is

 

plot.png

 

I have two questions: (i) can I remove the unneccesary legend information about the black dots?, (ii) can I place the black dots inside the bars?

1 ACCEPTED SOLUTION

Accepted Solutions
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Well, for the keylegend, if you name each plot, then only name the one you want in the keylegend it should work:

proc sgplot data=ES(where=(RandomisedTo ne '')) noborder;
 refline 0 / axis=x;
 highlow y=label low=ES_lower high=ES_upper / group=RandomisedTo type=bar groupdisplay=cluster
 barwidth=0.6 clusterwidth=0.2 name="mybar";
 scatter x=ES y=label / markerattrs=(symbol=CircleFilled color=black size=5) group=RandomisedTo groupdisplay=cluster 
 legendlabel=' ' name='myscatter';
 yaxis display=(noline) label='Variable';
 keylegend "mybar" / noborder title='group';
 xaxis values=(-0.5 to 1.5 by 0.25) label='Effect size';
run;

For the offset, could you make Y a numeric value, and apply a format with the label.  So the Y axis is 1-3, and apply the format to get the text, that should line them up.  Can't see another reason why they are offset off the top of my head.

View solution in original post

2 REPLIES 2
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Well, for the keylegend, if you name each plot, then only name the one you want in the keylegend it should work:

proc sgplot data=ES(where=(RandomisedTo ne '')) noborder;
 refline 0 / axis=x;
 highlow y=label low=ES_lower high=ES_upper / group=RandomisedTo type=bar groupdisplay=cluster
 barwidth=0.6 clusterwidth=0.2 name="mybar";
 scatter x=ES y=label / markerattrs=(symbol=CircleFilled color=black size=5) group=RandomisedTo groupdisplay=cluster 
 legendlabel=' ' name='myscatter';
 yaxis display=(noline) label='Variable';
 keylegend "mybar" / noborder title='group';
 xaxis values=(-0.5 to 1.5 by 0.25) label='Effect size';
run;

For the offset, could you make Y a numeric value, and apply a format with the label.  So the Y axis is 1-3, and apply the format to get the text, that should line them up.  Can't see another reason why they are offset off the top of my head.

KACH
Calcite | Level 5
Thank you very much.

sas-innovate-wordmark-2025-midnight.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


Register now!

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
  • 947 views
  • 1 like
  • 2 in conversation