Data visualization with SAS programming

horizontal bar chart using sgplot

Accepted Solution Solved
Reply
Contributor
Posts: 57
Accepted Solution

horizontal bar chart using sgplot

[ Edited ]

I plotted a horizontal Barchart using sgplot. All works fine, the only problem I have, is that  I wish to rotate the whole graph so that the 

yaxis which is now on the left hand side, is turned to the right hand side. Also is there anyway to get rid of the vertical line on the yaxis? can anyone help?

export.jpg


Accepted Solutions
Solution
‎02-26-2018 02:09 AM
SAS Super FREQ
Posts: 1,265

Re: horizontal bar chart using sgplot

[ Edited ]

Use Y2AXIS as suggested by RW9 (see bold options in code below).  Also, you can remove the baseline by setting BASELINEATTRS=(thickness=0) on the HBAR.  I would put the grid on the xaxis.

 

proc sgplot data=sg.test2 noborder nowall; 
hbar types / response=total barwidth=0.5 y2axis missing datalabel fillattrs=(color=gray)
     baselineattrs=(thickness=0);
y2axis display=(nolabel noline noticks) discreteorder=data; 
xaxis display=(nolabel noline novalues noticks) max=3000 reverse grid;
run;

 

View solution in original post


All Replies
Super User
Super User
Posts: 9,227

Re: horizontal bar chart using sgplot

You can set the display on yaxis to none:

http://documentation.sas.com/?docsetId=grstatproc&docsetTarget=n0n6uml63c6h8dn16phbd1arm9g9.htm&docs...

See display.

 

Then you can setup the y2axis as you want to display it:

http://support.sas.com/documentation/cdl/en/grstatproc/65235/HTML/default/viewer.htm#n04drrb1aehuqzn...

 

You will find this blog helpful as it has thousands of examples of all types of graphs:

http://blogs.sas.com/content/graphicallyspeaking/

SAS Super FREQ
Posts: 1,265

Re: horizontal bar chart using sgplot

And, if you also want the bars to go from right to left, then you can use the REVERSE option on the XAXIS.

Contributor
Posts: 57

Re: horizontal bar chart using sgplot

Thanks for your quick responses. I tried both methods but haven't still got it working. when I use reverse on the xaxis I get something like this:  dok1.jpg

 How do I get the labels on the left handside? Also I wish to get rid of the line holding the bars. Is there any way to do that?

 

Contributor
Posts: 57

Re: horizontal bar chart using sgplot

let me just post the sas code here incase someone can help. I will be very gratefull for any help. Thanks

proc sgplot data=sg.test2 noborder nowall;
yaxis grid type=discrete discreteorder=data; 
hbar types /response=total barwidth=0.5 missing datalabel fillattrs=(color=gray);
yaxis display=(nolabel noline noticks); 
xaxis display=(nolabel noline novalues noticks) max=3000 reverse;
run;

and here is the input data

Attachment
Solution
‎02-26-2018 02:09 AM
SAS Super FREQ
Posts: 1,265

Re: horizontal bar chart using sgplot

[ Edited ]

Use Y2AXIS as suggested by RW9 (see bold options in code below).  Also, you can remove the baseline by setting BASELINEATTRS=(thickness=0) on the HBAR.  I would put the grid on the xaxis.

 

proc sgplot data=sg.test2 noborder nowall; 
hbar types / response=total barwidth=0.5 y2axis missing datalabel fillattrs=(color=gray)
     baselineattrs=(thickness=0);
y2axis display=(nolabel noline noticks) discreteorder=data; 
xaxis display=(nolabel noline novalues noticks) max=3000 reverse grid;
run;

 

Contributor
Posts: 57

Re: horizontal bar chart using sgplot

Okay, thanks a lot Sanjay, I will try that and let you know if it worked. my regards

Contributor
Posts: 57

Re: horizontal bar chart using sgplot

Thankyou very much Sanjay. It worked very fine. I have also in included the grid on the xaxis.
☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 7 replies
  • 258 views
  • 3 likes
  • 3 in conversation