thomasp85 / ggforce

Accelerating ggplot2
https://ggforce.data-imaginist.com
Other
916 stars 105 forks source link

`geom_circle` appearance in legend #267

Open SchmidtPaul opened 2 years ago

SchmidtPaul commented 2 years ago

Sorry - I know this is not a bug, but I'd like your opinion on it anyway. The reprex below shows how I would use geom_circle to draw a circle around some but not all geom_point. As far as I know, the legend will always show a rectanlge around the symbols, yet it would be nice if it would actually be a circle. I don't think I can approach this with guide() or theme(legend.key = ). Can you think of a solution?

library(ggforce)

dat <- data.frame(
  x = c(1, 1.3, 1.6),
  y = c(1, 1, 1),
  circle = c("yes", "no", "no")
)

ggplot() +
  coord_equal() +
  theme_classic() +
  geom_circle(
    data = subset(dat, circle == "yes"),
    aes(x0 = x, y0 = y, r = 0.5, alpha = circle),
    fill = "grey",
    color = NA,
    show.legend = TRUE
  ) +
  geom_point(
    data = dat,
    aes(x, y, color = circle)
  ) +
  scale_color_manual(
    values = c("yes" = "blue", "no" = "red")
  ) +
  scale_alpha_manual(
    values = c("yes" = 0.25, "no" = 0)
  )

Created on 2022-07-21 by the reprex package (v2.0.1)

thomasp85 commented 2 years ago

Thanks for the suggestion - a draw_key_circle() would make sense