Data visualization with SAS programming

Histograms: y-axis on both sides and labelling of x-axis points

Reply
Frequent Contributor
Frequent Contributor
Posts: 94

Histograms: y-axis on both sides and labelling of x-axis points

I'm facing two issues in plotting histograms in gchart, if anyone could advise please?

1) How to display y-axis on both the sides of the graph, one side displaying frequencies and the other side displaying percentages?

2)On the x-axis, how to label the bars only after (say) 5 points and yet display all the bars? For instance, how to have a bar for each point from 0 to 80 (0,1,2..80) and display the labels for bars only at (0, 5, 10...80)?

I tried in proc univariate as well but couldn't work it out. Thanks.
Vikas
SAS Employee
Posts: 980

Re: Histograms: y-axis on both sides and labelling of x-axis points

The easiest way to get an axis on the left & right side of a bar chart is using "proc gbarline". If your version of SAS is not new enough to have gbarline, then you could use "proc gchart" and then annotate the tickmarks & values along the right-side of the graph (a little tricky, but do-able).

Here's some basic gbarline code, to get you started:

data foo;
input barnum value pct;
format pct percent5.0;
datalines;
1 2 .20
2 5 .50
3 3 .30
;
run;

symbol1 value=none interpol=none;
proc gbarline data=foo;
bar barnum / type=sum sumvar=value;
plot / sumvar=pct;
run;
Frequent Contributor
Frequent Contributor
Posts: 94

Re: Histograms: y-axis on both sides and labelling of x-axis points

Robert, this is very helpful. Thanks for both the answers. Vikas.
SAS Employee
Posts: 980

Re: Histograms: y-axis on both sides and labelling of x-axis points

Per your 2nd question - you can use an axis statement with "proc gchart", and it will let you specify custom text (including a blank value) for each tickmark value of the axis, referring to them by number ( t=1 is the first bar midpoint value, t=2 is the second, and so on).

Here is some sample code, that shows how to blank out the first 5 values:

axis1 value=(t=1 '' t=2 '' t=3 '' t=4 '' t=5 '');

proc gchart data=sashelp.class;
hbar name / type=sum sumvar=height maxis=axis1;
run;
Ask a Question
Discussion stats
  • 3 replies
  • 241 views
  • 0 likes
  • 2 in conversation