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?
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;
You can set the display on yaxis to none:
See display.
Then you can setup the y2axis as you want to display it:
You will find this blog helpful as it has thousands of examples of all types of graphs:
And, if you also want the bars to go from right to left, then you can use the REVERSE option on the XAXIS.
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:
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?
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
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;
Okay, thanks a lot Sanjay, I will try that and let you know if it worked. my regards
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
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.
Ready to level-up your skills? Choose your own adventure.