tags:

views:

222

answers:

2

I need to plot a bar chart showing counts and a line chart showing rate all in one chart, I can do both of them separately, but when I put them together, I scale of the first layer (i.e. the geom_bar), is overlapped by the second layer (i.e. the geom_line), can I move the axis of the geom_line to the right?

Thanks!

+1  A: 

It's not possible in ggplot2 because plots with multiple y scales are fundamentally flawed.

hadley
I see. I have heard from you in other post about adding a "transformed y-scale" on the right hand side of the chart, can it be used as a surrogate? how can I do it?Thanks!
lokheart
Agreed. The use of multiple y axes should be discouraged.
Maiasaura
Would you mind elaborate Your opinion? Not beeing enlightened , I think its a rather compact way of plotting two independent variables.It is also a feature that seems to be asked for, and it's beein used widely.
KarlP
@hadley: Mostly I agree, but there is a genuine use for multiple y scales - the use of 2 different units for the same data, e.g., Celsius and Fahrenheit scales on temperature time series.
Richie Cotton
Yes, which is why that particular case is on the to do list.
hadley
A: 
<rant>
Sometimes a client wants two y scales. Giving them the "flawed" speech is often pointless.
But I like the ggplot2 insistence on doing things the right way. I am sure that ggplot is
infact education the average user about proper visualization techniques.
</rant>

Maybe you can use faceting and scale free to compare the two dataseries? - e.g. look here: http://rwiki.sciviews.org/doku.php?id=tips:graphics-ggplot2:aligntwoplots

Andreas