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

Add phylopic_key_glyph #68

Merged
merged 7 commits into from
Aug 27, 2023
Merged

Add phylopic_key_glyph #68

merged 7 commits into from
Aug 27, 2023

Conversation

willgearty
Copy link
Collaborator

This adds a custom key glyph function that can be used with geom_phylopic to specify silhouettes for the legend.
image

Resolves #57.

Copy link
Collaborator

@LewisAJones LewisAJones left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This works really well @willgearty. I know it gave you some pain, so great job. A few things we might want to consider:

  • Ensure this works with the updated aesthetics for geom_phylopic (use of colour and fill) and outline feature.
  • Can we make this work with the size aesthetic as well?
  • Do we want an option for creating legends for add_phylopic and add_phylopic_base?

R/geom_phylopic.R Outdated Show resolved Hide resolved
@willgearty
Copy link
Collaborator Author

Note: I still need to figure out why one of the tests isn't making the correct snapshot.

@willgearty
Copy link
Collaborator Author

willgearty commented Aug 27, 2023

With the most recent commit, looks like this "just works" with the new fill/color split.

image

@LewisAJones LewisAJones self-requested a review August 27, 2023 10:32
Copy link
Collaborator

@LewisAJones LewisAJones left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @willgearty, this is working well! Last thing from me is whether we expect color defined outside of the aesthetics to also work when multiple values are defined? I think we should be encouraging it to be defined in the aesthetics, but just in case, I thought I'd mention it.

library(ggplot2)
df <- data.frame(x = c(2, 4), y = c(10, 20),
                 name = c("Felis silvestris catus", "Odobenus rosmarus"))
# Works with outline colour
ggplot(df) +
  geom_phylopic(aes(x = x, y = y, name = name, fill = name), color = c("blue"), 
                size = 10,
                show.legend = TRUE,
                key_glyph = phylopic_key_glyph(name =
                                                 c("Felis silvestris catus",
                                                   "Odobenus rosmarus"))) +
  coord_cartesian(xlim = c(1,6), ylim = c(5, 30))
# Doesn't work with outline colour (defaults to black)
ggplot(df) +
  geom_phylopic(aes(x = x, y = y, name = name, fill = name), color = c("blue", "red"), 
                size = 10,
                show.legend = TRUE,
                key_glyph = phylopic_key_glyph(name =
                                                 c("Felis silvestris catus",
                                                   "Odobenus rosmarus"))) +
  coord_cartesian(xlim = c(1,6), ylim = c(5, 30))

@willgearty
Copy link
Collaborator Author

willgearty commented Aug 27, 2023

This is the expected behavior for a ggplot legend (which should only represent the aesthetics). For example:

ggplot(df) +
    geom_point(aes(x = x, y = y, fill = name), color = c("blue", "red"), size = 10, shape = 21) +
    coord_cartesian(xlim = c(1,6), ylim = c(5, 30))

@willgearty
Copy link
Collaborator Author

OK, your two other requests/comments have been moved to separate issues for future development. I'll merge this once the checks pass!

@willgearty willgearty merged commit 6c0a586 into main Aug 27, 2023
@willgearty willgearty deleted the legend-keys branch August 27, 2023 23:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

custom legend icons for geom_phylopic
2 participants