Description
I have used sec_axis
for the first time and it worked great. Two minor comments below.
Comment 1: Functionality suggestion.
Consider:
library(ggplot2)
ggplot(mtcars, aes(wt, hp)) +
geom_point() +
scale_y_continuous(sec.axis = sec_axis(~. / max(mtcars$hp)))
Suggestion: Allow the scale function to access the variables passed to the aes()
, so that this become possible:
ggplot(mtcars, aes(x = wt, y = hp)) +
geom_point() +
scale_y_continuous(sec.axis = sec_axis(~. / max(y)))
From the end-user perspective, + scale_y_secondary(~./max(y))
would be even better.
Comment 2: Doc improvement suggestion.
The following is a quote from the docs:
This function is used in conjunction with a position scale to create a secondary axis, positioned opposite of the primary axis. All secondary axes must be based on a one-to-one transformation of the primary axes.
With this wording, I expected to be able to do:
ggplot(mtcars, aes(wt, hp)) +
geom_point() +
sec_axis()
So I would suggest changing "in conjunction with" to "inside a" to make it clear that it's to be used inside. I would also write that it's a function associated with the sec.axis
argument of the position scale or something to that effect.