I am tring to create a horizontal bar chart using sgplot I already have the chart drawn but on the yaxis where the labels are:
I will like each group to have a header. Is there an way to use annotate to make this?
e.g. I have milk, ovaltine, sugar, this is grouped under beverages
biscuits, cake, donuts is grouped under Snacks
chocolate, toffies, chewing gums grouped under Sweets
I have sg already plotted the graph but I want beverages, Snacks and Sweets to be bold, with border lines, and background=blue
here is my data and the program: I will appreciate any help:
value | order | type | Percent | report_cat |
Head | 1 | Beverages | ||
body | 2 | Milo | 99,6 | london |
body | 2 | Milo | 100 | reported |
body | 3 | Ovaltine | 84,1 | reported |
body | 3 | Ovaltine | 84,7 | london |
body | 4 | Sugar | 73,4 | london |
body | 4 | Sugar | 93,8 | reported |
body | 5 | Coffee | 70,2 | london |
body | 5 | Coffee | 93,8 | reported |
body | 6 | milk | 70,6 | london |
body | 6 | milk | 93,8 | reported |
body | 7 | condense milk | 84,8 | london |
body | 7 | condense milk | 92,6 | reported |
Head | 8 | Snacks | ||
body | 9 | cake | 15,2 | reported |
body | 9 | cake | 69,1 | london |
body | 10 | pie | 15,2 | reported |
body | 10 | pie | 68,1 | london |
body | 11 | biscuits | 15,2 | reported |
body | 11 | biscuits | 68,1 | london |
body | 12 | donuts | 15,2 | reported |
body | 12 | donuts | 51,7 | london |
Head | 13 | Sweets | ||
body | 14 | toffies | reported | |
body | 14 | toffies | 70 | london |
body | 15 | chewinggums | reported | |
body | 15 | chewinggums | 68,1 | london |
body | 16 | chocolate | reported | |
body | 16 | chocolate | 55,7 | london |
proc sgplot data=input pad=(bottom=5%);
styleattrs datacolors=(green blue);
yaxis grid type=discrete discreteorder=data;
hbar type /response=percent group=report_cat groupdisplay=cluster
barwidth=0.8 missing ;
yaxis display=(nolabel) offsetmin=0.05 offsetmax=0.05;
xaxis label='percentage %' grid offsetmin=0.0 offsetmax=0.05;
keylegend / location=outside position=bottomleft across=1 title="" ;
run;
First port of call on any graphing question is here:
https://blogs.sas.com/content/graphicallyspeaking/
Thousands of examples of all kinds of graphs. One from the first page that jumped out to me as showing groupings might be this one:
I have tried the your suggestions but it isn't working. Pls am still counting on any other help
Doesn't work is awful vague.
Are there errors in the log?: Post the code and log in a code box opened with the {i} to maintain formatting of error messages.
No output? Post any log in a code box.
Unexpected output? Provide input data in the form of a dataset, the actual results and the expected results. Data should be in the form of a data step. Instructions here: https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat... will show how to turn an existing SAS data set into data step code that can be pasted into a forum code box using the {i} icon or attached as text to show exactly what you have and that we can test code against.
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 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.