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

Colour/fill legend with coloured text #31

Closed
teunbrand opened this issue Jan 6, 2021 · 2 comments
Closed

Colour/fill legend with coloured text #31

teunbrand opened this issue Jan 6, 2021 · 2 comments
Labels
enhancement New feature or request

Comments

@teunbrand
Copy link
Owner

Implement new legend guide that describes colour or fill with coloured text.
Should take the scale's labels and apply the mapped colour to the labels.
Goal is to have it look like the following, but easier to specify and strings left-aligned by default.

library(ggplot2)

ggplot(iris, aes(Sepal.Width, Sepal.Length)) +
  geom_point(aes(colour = Species),
             key_glyph = draw_key_text) +
  scale_colour_discrete(
    labels = NULL,
    guide = guide_legend(
      override.aes = list(label = levels(iris$Species),
                          size = 4, vjust = 0)
    )
  ) +
  theme(legend.key.width = unit(3, "cm"),
        legend.key = element_blank())

Created on 2021-01-06 by the reprex package (v0.3.0)

@teunbrand
Copy link
Owner Author

Might as well make a spin-off package with different guide extensions

@teunbrand teunbrand added the enhancement New feature or request label Jan 6, 2021
teunbrand added a commit that referenced this issue Jan 9, 2021
@teunbrand
Copy link
Owner Author

You can do this now.

library(ggh4x)
#> Loading required package: ggplot2
ggplot(mpg, aes(displ, hwy)) +
  geom_point(aes(colour = manufacturer)) +
  guides(colour = guide_stringlegend(ncol = 2))

Created on 2021-01-09 by the reprex package (v0.3.0)

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

No branches or pull requests

1 participant