06-12-2013 11:40 AM
Is there a command to put data labels in each bar of a chart? This is what I have:
|proc sgplot data=figure2;|
|yaxis label=' ' discreteorder=data valueATTRS=(family='calibri' size=8pt style=normal);|
|xaxis discreteorder=data label = ' ' valueATTRS=(family='calibri' size=8pt style=normal);|
|vbar group / response = col1 group = name grouporder=data barwidth=0.4 datalabel=col1 datalabelpos=data;|
|keylegend / noborder location=outside position=top across=2 valueATTRS=(family='calibri' size=7pt style=normal);|
Using this code gives me the value from the first segment of the stacked bar, at the top of the bar. Using datalabel by itself gives the grand total at the top.
I need each segment to have it's own label, and some segments are too small for the value, so it would need to be off to the side. Is there a way to do this?
06-13-2013 10:29 AM
This doesn't do what the bosses requested, but at least the data is available on the chart:
proc sgplot data=figure2;
yaxis label=' ' discreteorder=data valueattrs=(family='calibri' size=8pt style=normal) ;
xaxis discreteorder=data label = ' ' valueattrs=(family='calibri' size=8pt style=normal) ;
vbar group / response = col1 group = name grouporder=data barwidth=0.4 datalabel=col1 datalabelpos=bottom
datalabelattrs=(family='calibri' size=6pt style=normal);
keylegend / noborder location=outside position=top across=2 valueattrs=(family='calibri' size=7pt style=normal);
It seems logical from the documentation that the datalabelpos=data option should label the data sections, it just doesn't. I've seen other similar questions on various Communities boards but no easy answers. Is Annotate the only option? If anyone knows a great simple solution, I'd still like to see it.
06-14-2013 10:46 AM
There are ways to do this, but not by using a simple option on VBAR or VBARPARM. Sort the values by category and group, and compute the low, high values (and midpoint) for each bar segment per category yourself. Then, use a HIGHLOW bar to draw the segments. Use a SCATTER plot with MARKERCHAR to place the values at the midpoint of each segment.