Data visualization with SAS programming

Adding a significance star in a bar chart

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 6
Accepted Solution

Adding a significance star in a bar chart


Hi,

 

I'm trying to add a star (*) on top of the bars that are significantly different (between the 2 endpoints) in a bar chart. Please see the code below. I've tried using DATALABEL, but SAS won't allow the labels for different bars to be the same. And I can't figure out how to use an annotated dataset here correctly. I'm using SAS version 9.3.

 

In my dataset I have 2 different endpoints (type) and 5 treatment groups (group).

 

PROC SGPLOT DATA=work10;
VBARPARM CATEGORY=group RESPONSE=gm/ GROUP=type LIMITUPPER=Upper2;
XAXIS DISCRETEORDER=DATA;
YAXIS LABEL="Geometric mean (AU/mL)";
KEYLEGEND / TITLE="Groups";
RUN;

 

Is there any way to do this?


Accepted Solutions
Solution
‎03-01-2017 03:50 AM
SAS Super FREQ
Posts: 1,043

Re: Adding a significance star in a bar chart

Since you are using VBARPARM, you should be able to overlay a scatter plot with y=upper2 to plot markers where you want them.

View solution in original post


All Replies
SAS Super FREQ
Posts: 864

Re: Adding a significance star in a bar chart

The key here is the LIMITUPPER request. Data labels over the bars are not allowed when LIMITUPPER/LIMITLOWER are used. Without that option, the DATALABEL option works as expected, as demonstrated by the following program:

proc summary data=sashelp.class nway;
class age sex;
var weight;
output out=temp mean= uclm=uclm;
run;

data dlabel;
set temp;
if (sex eq 'M') then dlabel="*";
else dlabel=" ";
run;

proc sgplot data=dlabel;
vbarparm category=age response=weight / group=sex datalabel=dlabel;
run;

Fortunately, you can use annotation to get around this issue. But, my question to you is, "Do you want the star on top of the bar, or at the end of the limit bar?".

Occasional Contributor
Posts: 6

Re: Adding a significance star in a bar chart

Thank you Dan, that explains why the datalabel option doesn't work. I would prefer the star to be at the end of the limit bar. 

Solution
‎03-01-2017 03:50 AM
SAS Super FREQ
Posts: 1,043

Re: Adding a significance star in a bar chart

Since you are using VBARPARM, you should be able to overlay a scatter plot with y=upper2 to plot markers where you want them.

Occasional Contributor
Posts: 6

Re: Adding a significance star in a bar chart

Ah, thank you Sanjay. That seems to be doing the trick!

Post a Question
Discussion Stats
  • 4 replies
  • 148 views
  • 3 likes
  • 3 in conversation