lokheart lokheart - 1 year ago 84
R Question

Plot with 2 y axes, one y axis on the left, and another y axis on the right

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

) is overlapped by the second layer (i.e. the

Can I move the axis of the
to the right?

Answer Source

<rant> Sometimes a client wants two y scales. Giving them the "flawed" speech is often pointless. But I do like the ggplot2 insistence on doing things the right way. I am sure that ggplot is in fact educating the average user about proper visualization techniques. </rant>

Maybe you can use faceting and scale free to compare the two data series? - e.g. look here: https://github.com/hadley/ggplot2/wiki/Align-two-plots-on-a-page