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

In geom_pointrange, changes to the fatten arg are not reflected in the legend #4872

Closed
davidhodge931 opened this issue Jun 13, 2022 · 2 comments

Comments

@davidhodge931
Copy link

library(ggplot2)

df <- 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)
)

df %>% 
  ggplot() +
  geom_pointrange(aes(x = trt, y = resp, col = group, ymin = lower, ymax = upper),
                  fatten = 1)

image

@smouksassi
Copy link

possibly related to #2798
fatten is not a parameter and currently, the legend does not reflect any changes to it and is currently kind of hard coded:

draw_key_point(transform(data, size = (data$size %||% 1.5) * 4), params)

with the ongoing work of linewidth aesthetic things might be easier to handle/fix.
#3672

@yutannihilation
Copy link
Member

Thanks @smouksassi. As suggested, I think this issue is resolved by #3672. Now you can combine size and linewidth to control the sizes of points and lines differently. My understanding is fatten was a workaround for this, but is probably no longer needed.

library(ggplot2)

df <- 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(df) +
  geom_pointrange(aes(x = trt, y = resp, col = group, ymin = lower, ymax = upper),
    size = 2, linewidth = 0.5
  ) +
  theme(legend.key.size = unit(0.15, "npc"))

Created on 2022-06-19 by the reprex package (v2.0.1)

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

3 participants