## Overlaying bar chart and line on one graph with sgplot

Solved
Occasional Contributor
Posts: 13

# Overlaying bar chart and line on one graph with sgplot

I've been trying to figure out how to have a bar chart (representing exposure) on the second y axis and a line chart (representing frequency) on the first y axis in sgplot.  Can anybody help?

Accepted Solutions
Solution
‎03-20-2013 03:38 PM
SAS Super FREQ
Posts: 978

## Re: Overlaying bar chart and line on one graph with sgplot

In SAS 9.4 we have added the ability to assign bar charts to secondary axes. In SAS 9.2 and 9.3, you should be able to assign the bar chart (vbar) to the first Y axis and the line chart (vline) to the secondary Y axis. Here is a simple example.

proc sgplot data=sashelp.class;

vbar age / response=height stat=mean;

vline age / y2axis;

run;

Hope this helps!

Dan

All Replies
Super Contributor
Posts: 543

## Re: Overlaying bar chart and line on one graph with sgplot

Sure thing.

proc gbarline works wonders for this sort of graphs.

Also, has a magnificent website where you can find plots (with WORKING SAS code)

Good luck!

Anca.

SAS Super FREQ
Posts: 3,910

## Re: Overlaying bar chart and line on one graph with sgplot

See this example of using PROC SGPLOT:

SAS(R) 9.3 ODS Graphics: Procedures Guide, Third Edition

Occasional Contributor
Posts: 13

## Re: Overlaying bar chart and line on one graph with sgplot

I've just resolved this.  I was using a series statement instead of a vline statement for the line graph.  If I use vline it works with the y2axis option.

proc sgplot data = test;

vline year / response = frequency y2axis;

vbar year / response = gwp;

run;

Strangely though, the vbar statement does not offer the y2axis option.

Solution
‎03-20-2013 03:38 PM
SAS Super FREQ
Posts: 978

## Re: Overlaying bar chart and line on one graph with sgplot

In SAS 9.4 we have added the ability to assign bar charts to secondary axes. In SAS 9.2 and 9.3, you should be able to assign the bar chart (vbar) to the first Y axis and the line chart (vline) to the secondary Y axis. Here is a simple example.

proc sgplot data=sashelp.class;

vbar age / response=height stat=mean;

vline age / y2axis;

run;

Hope this helps!

Dan

🔒 This topic is solved and locked.