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

Cannot update the width geom default for geom_bar/geom_col and geom_errorbar #6224

Closed
davidhodge931 opened this issue Dec 9, 2024 · 3 comments

Comments

@davidhodge931
Copy link

davidhodge931 commented Dec 9, 2024

With the DEV version of ggplot2

library(tidyverse)

update_geom_defaults("bar", aes(width = 0.1))
update_geom_defaults("errorbar", aes(width = 0.1))

GeomBar$default_aes
#> Aesthetic mapping: 
#> * `colour`    -> NA
#> * `fill`      -> `from_theme(col_mix(ink, paper, 0.35))`
#> * `linewidth` -> `from_theme(borderwidth)`
#> * `linetype`  -> `from_theme(bordertype)`
#> * `alpha`     -> NA
#> * `width`     -> 0.1
GeomErrorbar$default_aes
#> Aesthetic mapping: 
#> * `colour`    -> `from_theme(ink)`
#> * `linewidth` -> `from_theme(linewidth)`
#> * `linetype`  -> `from_theme(linetype)`
#> * `width`     -> 0.1
#> * `alpha`     -> NA

data.frame(
  trt = factor(c(1, 1, 2, 2)),
  resp = c(1, 5, 3, 4),
  group = factor(c(1, 2, 1, 2)),
  upper = c(1.1, 5.3, 3.3, 4.2),
  lower = c(0.8, 4.6, 2.4, 3.6)
) |>
  ggplot(aes(
    x = trt,
    y = resp,
    ymin = lower,
    ymax = upper,
    colour = group,
    fill = group,
  )) +
  geom_col(position = "dodge") +
  geom_errorbar(position = "dodge")

Created on 2024-12-10 with reprex v2.1.1

@teunbrand
Copy link
Collaborator

teunbrand commented Dec 9, 2024

The width defaults are just practically never invoked because widths get inferred during plot building based. The updating itself works as you show in your example. I think the position adjustments and data resolutions contribute to the width under normal circumstances.

@teunbrand
Copy link
Collaborator

I think this issue might be a duplicate of #2800, which has #6065 pending.

@davidhodge931
Copy link
Author

Awesome, great work @teunbrand!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants