Skip to content

facet_wrap_paginate(): dropping colors in the legend #298

Open
@adamolko

Description

@adamolko

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    featurea feature request or enhancement

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions