Data visualization with SAS programming

X Axis - Create Tick lines

Accepted Solution Solved
Reply
Contributor
Posts: 28
Accepted Solution

X Axis - Create Tick lines

I am using SAS 9.4 and I've created a cluster grouped VBAR (2 types in the group). Below the VBAR I've add 4 vlines. I am trying to add tick lines in the bottom x axis to visually segregate the data below the chart aligning with the vbars above. I've attached a pic and I show (in blue) lines I'd like to add. Of course, I'd like straight lines not my messy illustration.

Attachment

Accepted Solutions
Solution
‎07-16-2016 06:59 AM
SAS Super FREQ
Posts: 1,044

Re: X Axis - Create Tick lines

[ Edited ]

With SAS 9.4M3, you can do a graph like this with fewer lines of code.  Note use of color bands to separate the columns.  AxisTable does not have options to draw the column borders.  VBARBASIC is used if the color bands are to be hidden using the BAND.  Else you can just use VBAR.

 

BarWithTable.png

 

 

title h=10pt 'Auto Statistics';
proc sgplot data=sashelp.cars(where=(type ne 'Hybrid')) noborder;
  format mpg_city mpg_highway horsepower 3.0;
  styleattrs datacolors=(lightgreen gold forestgreen)
             datacontrastcolors=(lightgreen gold forestgreen)
             axisextent=data;
  band x=type lower=0 upper=340 / fill nooutline fillattrs=graphwalls;
  vbarbasic type / response=horsepower dataskin=pressed stat=mean name='a' 
       group=origin groupdisplay=cluster baselineattrs=(thickness=0);
  xaxistable mpg_city mpg_highway horsepower / class=origin classdisplay=cluster 
       stat=mean colorgroup=origin location=inside;
  xaxis display=(noticks nolabel noline) colorbands=even colorbandsattrs=(transparency=0.4);
  keylegend 'a' / location=inside position=topright across=1 title='';
  yaxis offsetmax=0;
run;

 

View solution in original post


All Replies
SAS Super FREQ
Posts: 1,044

Re: X Axis - Create Tick lines

Please share your code and (some) data so it is easier to provide a solution.

Contributor
Posts: 28

Re: X Axis - Create Tick lines

I added the code. Thank you
Grand Advisor
Posts: 9,748

Re: X Axis - Create Tick lines

This example

http://support.sas.com/kb/35/132.html

shows one way of adding a table of other values below an axis that aligns with the ticks.

 

Contributor
Posts: 28

Re: X Axis - Create Tick lines

I thought using Vline with VBar there may be a simple solution I am missing. Thank you for your help.

Contributor
Posts: 28

Re: X Axis - Create Tick lines

SAS Super FREQ
Posts: 1,044

Re: X Axis - Create Tick lines

[ Edited ]

Unfortunately, you did not attach any data.  So it is not possible to run your code.

 

With SAS 9.4, you can use the XAXISTABLE to display the tabular data.  Is there a reason you are not using it?

Here are some examples:  

http://blogs.sas.com/content/graphicallyspeaking/?s=xaxistable

http://blogs.sas.com/content/graphicallyspeaking/2013/12/16/grouped-bar-chart-with-statisticstable/

 

GROUPDISPLAY=CLUSTER can now be used with the XAXISTABLE.

Solution
‎07-16-2016 06:59 AM
SAS Super FREQ
Posts: 1,044

Re: X Axis - Create Tick lines

[ Edited ]

With SAS 9.4M3, you can do a graph like this with fewer lines of code.  Note use of color bands to separate the columns.  AxisTable does not have options to draw the column borders.  VBARBASIC is used if the color bands are to be hidden using the BAND.  Else you can just use VBAR.

 

BarWithTable.png

 

 

title h=10pt 'Auto Statistics';
proc sgplot data=sashelp.cars(where=(type ne 'Hybrid')) noborder;
  format mpg_city mpg_highway horsepower 3.0;
  styleattrs datacolors=(lightgreen gold forestgreen)
             datacontrastcolors=(lightgreen gold forestgreen)
             axisextent=data;
  band x=type lower=0 upper=340 / fill nooutline fillattrs=graphwalls;
  vbarbasic type / response=horsepower dataskin=pressed stat=mean name='a' 
       group=origin groupdisplay=cluster baselineattrs=(thickness=0);
  xaxistable mpg_city mpg_highway horsepower / class=origin classdisplay=cluster 
       stat=mean colorgroup=origin location=inside;
  xaxis display=(noticks nolabel noline) colorbands=even colorbandsattrs=(transparency=0.4);
  keylegend 'a' / location=inside position=topright across=1 title='';
  yaxis offsetmax=0;
run;

 

Contributor
Posts: 28

Re: X Axis - Create Tick lines

Sanjay - perfect! I thought I reviewed all the great work you've done. I missed this one. Thanks again.

Post a Question
Discussion Stats
  • 8 replies
  • 482 views
  • 1 like
  • 3 in conversation