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

ggplot2 key_glyphs could be helpful at some point #26

Open
ddsjoberg opened this issue Feb 5, 2024 · 5 comments
Open

ggplot2 key_glyphs could be helpful at some point #26

ddsjoberg opened this issue Feb 5, 2024 · 5 comments
Assignees

Comments

@ddsjoberg
Copy link
Contributor

https://ggplot2.tidyverse.org/reference/draw_key.html

@ddsjoberg
Copy link
Contributor Author

Here's a blog post that illustrates how to create a custom key glyph. This has the potential to immensely simply the internals
https://emilhvitfeldt.com/post/changing-glyph-in-ggplot2/

(Just making notes for the future...it doesn't sound like anyone has bandwidth at the moment)

@rsh52 rsh52 self-assigned this Feb 23, 2024
@ddsjoberg
Copy link
Contributor Author

The symbol used in the legend can be customized using the key_glyph argument. There are a bunch of pre-defined ones (example below). But I am curious if we could simply write a custom one one the fly.

For example, if we exported a new geom geom_marker(aes(...), marker = "\u1234") that could write a custom glyph function using the marker symbol passed by the user. These functions look like they are simple grob objects, so perhaps not too complicated (that said, everything with legends is complicated!).

library(tidyverse)

ggplot(mtcars) +
  geom_point(aes(x = hp, y = mpg, color = "Death"))

ggplot(mtcars) +
  geom_point(aes(x = hp, y = mpg, color = "Death"), key_glyph = draw_key_boxplot)

Created on 2024-02-23 with reprex v2.1.0

@rsh52
Copy link
Contributor

rsh52 commented Feb 23, 2024

Yea I think this could work! I want to look into this and how the new guides updates can simplify the brute-force things I was trying to achieve originally.

You're envisioning that marker symbols get passed to glyphs, or that we expose key_glyphs as an option for users? I'm not sure how much I like having something in the legend that doesn't exactly appear in the plot:

image

Silly example, but there are no smileys to find in the plot itself.

@ddsjoberg
Copy link
Contributor Author

oh users should never know about glyphs. for them, they just pass to us that they want this symbol/emoji at these points, and we take care of the rest.

@rsh52
Copy link
Contributor

rsh52 commented Feb 24, 2024

oh users should never know about glyphs. for them, they just pass to us that they want this symbol/emoji at these points, and we take care of the rest.

Got it, makes sense to me! Hope to explore more in the next week or two.

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