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

facet_wrap_paginate(): dropping colors in the legend #298

Open
adamolko opened this issue Mar 12, 2023 · 1 comment
Open

facet_wrap_paginate(): dropping colors in the legend #298

adamolko opened this issue Mar 12, 2023 · 1 comment
Labels
feature a feature request or enhancement

Comments

@adamolko
Copy link

Hello,

Thank you for a very nice package! I found function facet_wrap_paginate() especially useful, but would be great if it would also allow for dropping irrelevant colors from the legend..

As an example: here is a plot using starwars dataset from dplyr package, where I want to assign a specific color to every name.

library(ggplot2)
library(ggforce)
library(dplyr)

plot_data <- starwars[1:20, ]
g <- ggplot(data = plot_data, aes(x = homeworld, y = height, color = name)) + 
  geom_point(size = 3) + 
  scale_color_manual(values = c("#89C5DA", "#DA5724", "#74D944", "#CE50CA", "#3F4921", "#C0717C", "#CBD588", "#5F7FC7", 
                                         "#673770", "#D3D93E", "#38333E", "#508578", "#D7C1B1", "#689030", "#AD6F3B", "#CD9BCD", 
                                         "#D14285", "#6DDE88", "#652926", "#7FDCC0"),
                     labels = unique(plot_data$name)) +
  theme(axis.text.x = element_text(angle = 90))

Then I use facet_wrap_paginate() function to have at most 6 facets per page:

g + facet_wrap_paginate(facets = "hair_color", nrow = 3, ncol = 2, page = 1)

image

And then the second page:
g + facet_wrap_paginate(facets = "hair_color", nrow = 3, ncol = 2, page = 2)
image

As you can see, color legend on both pages is the same, even though the names in the dataset are unique and are only present on one of the two pages. It would be handy to have an option to drop those irrelevant elements from the legend.

@AngelicaEMB
Copy link

Hi!
Same question here.
It would definitively be handy to have the option to drop the irrelevant elements from the legend.

@thomasp85 thomasp85 added the feature a feature request or enhancement label Jan 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature a feature request or enhancement
Projects
None yet
Development

No branches or pull requests

3 participants