ggplot2
ggplot2 copied to clipboard
Documentation of arguments to `guide_axis` is unclear
- Apparently,
order
has to be numeric. However, this is not checked. Passing a character simply gives a warning ("NAs introduced by coercion"). - There is no example of
order
nor ofposition
.
I tried to add a secondary axis on the same side as the primary axis as follows:
ggplot(mtcars, aes(hp, mpg)) +
geom_point() +
scale_y_continuous(
sec.axis = sec_axis(trans = ~ 235.215 / ., name = "l/100 km",
guide = guide_axis(order = 2, position = "left")))
This leads to a warning: "Discarding guide on merge. Do you have more than one guide with the same position?" And the secondary axis is not drawn. So it seems that I did not fully understand the use of order
and position
yet...
See also: https://github.com/tidyverse/ggplot2/issues/4650#issuecomment-1214136938. Where it is suggested, that the primary axis should automatically take the opposite position
of the secondary axis.
I'll incorporate an explicit type and length check for the order
argument in #4879. Though I think the order
argument only matters for axis guides when there are multiple guides for the same position. That makes the guide_axis()
documentation a bit weird.