hi there
i am creating a scatter plot and i want to add the actual values on each bar.
My code:
proc sgplot data = consolidated;
vbar channel/group = subchannel groupdisplay = stack;
run;
how do i get the values to show on the bars?
Have you tried the SEGLABEL option on the VBAR statement? That should add labels to each section which I think is what you are asking. If you also want the bar "total" value then DATALABEL would also be needed.
Have you tried the SEGLABEL option on the VBAR statement? That should add labels to each section which I think is what you are asking. If you also want the bar "total" value then DATALABEL would also be needed.
Thank you. that solved it 🙂
how do i show the label on a stack thats really small though?
@Citrine10 wrote:
Thank you. that solved it 🙂
how do i show the label on a stack thats really small though?
Depending on the actual data and how important it may be to show something like 0.01% (just an example) there are a few options that may work.
Make the graph physically taller (or wider for HBAR), the ODS GRAPHICS option lets you control the height/width of the graph display area. This probably most useful if the text almost fits.
The SEGLABELATTRS can modify text size of the labels so a smaller or different font may work. Again more likely if the current text almost fits.
For extremely small values it may be better to create a custom format for the variable that would suppress text , show a "blank" value for very small ranges. That at least keeps from getting collisions and hard to read text.
If you "know" that several group values are consistently extremely small individually create a group value that represents 2 or more categories and provide an appropriate group definition. This may make more sense if the "groups" represent some sort of order that naturally places them together.
You can create an annotate data set and use the SGANNO option on the Proc statement to use the set. This is a bit of work as then you have to provide coordinates for where you actually want text to appear as well as the text. Sometimes with VBAR and character axis values this can be a challenge. I would use this in conjunction with the custom format suppressing the small values on the bar and then just display the value off to the side of the bar.
Related to this is using the VBARBASIC, to allow sharing with other types of charts and modify you existing data to include some additional values/variables to do a TEXT plot overlaying the graph with the label values. Again this might be just the "small" values. Both of these overlay approaches often work better with summarized values instead of letting VBAR build the heights using the internal stats.
Sometimes vertical scales might work such as a Log scale for the Yaxis but that only helps if the "small" values to display are actually appearing at the base of the bar.
Unless there is a lot of $$$ involved for the exact values of the small segments I tend to suppress the values on the actual bar and then use a footnote or other explanatory text that indicates the range of values that were suppressed.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.