Skip to content

Documentation of arguments to guide_axis is unclear #4958

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
jarauh opened this issue Aug 23, 2022 · 2 comments · Fixed by #4879
Closed

Documentation of arguments to guide_axis is unclear #4958

jarauh opened this issue Aug 23, 2022 · 2 comments · Fixed by #4879

Comments

@jarauh
Copy link

jarauh commented Aug 23, 2022

  1. Apparently, order has to be numeric. However, this is not checked. Passing a character simply gives a warning ("NAs introduced by coercion").
  2. There is no example of order nor of position.

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...

@jarauh
Copy link
Author

jarauh commented Aug 23, 2022

See also: #4650 (comment). Where it is suggested, that the primary axis should automatically take the opposite position of the secondary axis.

@teunbrand
Copy link
Collaborator

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.

teunbrand added a commit to teunbrand/ggplot2 that referenced this issue Sep 4, 2022
teunbrand added a commit that referenced this issue Apr 24, 2023
The guide system, as the last remaining chunk of ggplot2, has been rewritten 
in ggproto. The axes and legends now inherit from a <Guide> class, which makes
them extensible in the same manner as geoms, stats, facets and coords 
(#3329, @teunbrand). In addition, the following changes were made:
    * Styling theme parts of the guide now inherit from the plot's theme 
      (#2728). 
    * Styling non-theme parts of the guides accept <element> objects, so that
      the following is possible: `guide_colourbar(frame = element_rect(...))`.
    * Primary axis titles are now placed at the primary guide, so that
      `guides(x = guide_axis(position = "top"))` will display the title at the
      top by default (#4650).
    * Unknown secondary axis guide positions are now inferred as the opposite 
      of the primary axis guide when the latter has a known `position` (#4650).
    * `guide_colourbar()`, `guide_coloursteps()` and `guide_bins()` gain a
      `ticks.length` argument.
    * In `guide_bins()`, the title no longer arbitrarily becomes offset from
      the guide when it has long labels.
    * The `order` argument of guides now strictly needs to be a length-1 
      integer (#4958).
    * More informative error for mismatched 
     `direction`/`theme(legend.direction = ...)` arguments (#4364, #4930).
    * `guide_coloursteps()` and `guide_bins()` sort breaks (#5152).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants