Press "Enter" to skip to content

Dual Y Axes in R with ggplot()

Andrea Onofri builds a complex chart:

I have often found myself needing to plot a single graph with two y-axes having different scales. For example, this might be useful for representing temperature and rainfall data at a given location. Unfortunately, doing this with ggplot() is not straightforward.

As Andrea mentions, there are specific circumstances in which having a dual-axis chart is reasonable, and click through to learn how. ggplot2 tends to be rather opinionated regarding visual choice and design. I happen to like those opinions and think they are generally correct, but I can also recognize that there may be exceptions to the rules. For those instances, I think “Somewhat difficult but not impossible” is a solid answer, as it keeps people from doing things inappropriately with a couple of mouse clicks, like setting up those stupid 3D bar charts in Excel. H/T R-Bloggers.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.