Skip to content
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

Should theme elements provided to guides inherit from plot theme? #2728

Closed
clauswilke opened this issue Jun 30, 2018 · 0 comments · Fixed by #4879
Closed

Should theme elements provided to guides inherit from plot theme? #2728

clauswilke opened this issue Jun 30, 2018 · 0 comments · Fixed by #4879

Comments

@clauswilke
Copy link
Member

Here is an issue I've been pondering: Should theme elements provided to guides inherit from the plot theme? Currently they don't, and I think this causes unexpected behavior.

Example: I'm trying to change the color of the legend title but I'm inadvertently also changing the font size.

library(ggplot2)
ggplot(mtcars, aes(disp, mpg, size = cyl, color = hp)) +
  geom_point() +
  theme_grey(6) +
  scale_size(
    guide = guide_legend(
      title.theme = element_text(colour = "red")
    )
  )

Created on 2018-06-30 by the reprex package (v0.2.0).

I'd be happy to take a stab at this if we agree that the current behavior is sub-optimal. I think the right way to do it is to expand the calc_element() function so it can take as an optional argument an element that would override the theme settings.

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