DATA Step, Macro, Functions and more

formatting certain labels as headers on axis (hbar) using sgplot

Reply
Contributor
Posts: 26

formatting certain labels as headers on axis (hbar) using sgplot

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:

 

valueordertypePercentreport_cat
Head1Beverages  
body2Milo99,6london
body2Milo100reported
body3Ovaltine84,1reported
body3Ovaltine84,7london
body4Sugar73,4london
body4Sugar93,8reported
body5Coffee70,2london
body5Coffee93,8reported
body6milk70,6london
body6milk93,8reported
body7condense milk84,8london
body7condense milk92,6reported
Head8Snacks  
body9cake15,2reported
body9cake69,1london
body10pie15,2reported
body10pie68,1london
body11biscuits15,2reported
body11biscuits68,1london
body12donuts15,2reported
body12donuts51,7london
Head13Sweets  
body14toffies reported
body14toffies70london
body15chewinggums reported
body15chewinggums68,1london
body16chocolate reported
body16chocolate55,7london

 

 

 

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;

Super User
Super User
Posts: 7,981

Re: formatting certain labels as headers on axis (hbar) using sgplot

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:

https://blogs.sas.com/content/graphicallyspeaking/2016/05/30/ctspedia-clinical-graphs-subgrouped-for...

Contributor
Posts: 26

Re: formatting certain labels as headers on axis (hbar) using sgplot

I have tried the your suggestions but it isn't working. Pls am still counting on any other help

Super User
Posts: 11,343

Re: formatting certain labels as headers on axis (hbar) using sgplot

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.

Ask a Question
Discussion stats
  • 3 replies
  • 127 views
  • 0 likes
  • 3 in conversation