Hello!
I have data as below, from which I want to draw a bar-line chart, volume is the bar and rate is the line, would you please help me?
Thanks!
data test;
input
Type $2. Volume 5. Rate 18.;
cards;
A -105 0
B -102 -0.005839013
C -97 0.039130435
D -91 -0.002736612
E -78 0
F -67 0
G -58 -0.166469762
H -55 0.058062447
I -52 0
J -34 0.101676241
K -30 -0.035087719
L -27 -0.001283148
M -25 -0.147058824
N -21 0.001364522
O -21 -0.019047619
P -19 -0.033603803
Q -18 0
R -12 0
S -12 0
T -12 0.338461539
U -11 0.155289702
V -10 0
W -10 -0.255411255
X -8 0
Y -7 0
Z -7 0.02945253
;run;
Here is one approach:
proc sgplot data=test; vbar type / response=volume stat=sum; vline type/ response=rate y2axis; run;
SGPLOT will attempt to overlay each separate plot type. However there are severe restrictions of what may be combined.
The Y2axis is needed because the range of values you have for rate is so small that it gets buried in the base of the bars.
Look in the documentation for SGPLOT for axis and other appearance options.
Here is one approach:
proc sgplot data=test; vbar type / response=volume stat=sum; vline type/ response=rate y2axis; run;
SGPLOT will attempt to overlay each separate plot type. However there are severe restrictions of what may be combined.
The Y2axis is needed because the range of values you have for rate is so small that it gets buried in the base of the bars.
Look in the documentation for SGPLOT for axis and other appearance options.
Hi Ballard,
Would you please guide me how to put the bars in a descending order(from the highest to lowest height), I sorted it before sgplot but why the bars still show disorderly? (see the data below). Thanks a lot!
data test;
input
Type $2. Volume 5. Rate 18.;
cards;
A -19 0
B -102 -0.005839013
C -97 0.039130435
D -91 -0.002736612
E -78 0
F -6 0
G -58 -0.166469762
H -55 0.058062447
I -52 0
J -34 0.101676241
K -30 -0.035087719
L -27 -0.001283148
M -25 -0.147058824
N -2 0.001364522
O -21 -0.019047619
P -19 -0.033603803
Q -18 0
R 12 0
S -12 0
T 11 0.338461539
U -11 0.155289702
V -10 0
W -10 -0.255411255
X -8 0
Y 24 0
Z -7 0.02945253
;run;
proc sort data=test output=test2;by descending volume ;run;
ods graphics / width=15in height=6.81in;
proc sgplot data=test2;
vbar type / response=volume stat=sum;
vline type/ response=rate y2axis;
run;
VBAR Option - categoryorder=respdesc
vbar type / response=volume stat=sum categoryorder=respdesc;
Thank you so much!
What version of SAS do you have?
Top 3 hits from Google : SAS Bar Line Chart
http://support.sas.com/rnd/datavisualization/yourGraphs/businessQuick/barline/
http://blogs.sas.com/content/graphicallyspeaking/2012/04/02/bar-line-graph/
Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.
Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.
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.