how keep aesthetic mapping but remove a specific item from legend with ggplot

FWIW, you can access the default colours for the discrete palette using scales::hue_pal(). The show_col() function I'm using below is just a convenience function for printing the colours for you to see:

scales::hue_pal()(3)
#> [1] "#F8766D" "#00BA38" "#619CFF"
scales::show_col(scales::hue_pal()(3))

Created on 2020-02-13 by the reprex package (v0.3.0.9001)

Specifying this directly in scale_fill_manual() gets rid of the fill for the bar as well, but you might be able to do a workaround with one of the guides() functions.

library(tidyverse)
tibble(column = letters[1:3]) %>% 
  ggplot(aes(column)) +
  geom_bar(aes(fill = column)) +
  scale_fill_manual(values = c(scales::hue_pal()(3)[[1]], scales::hue_pal()(3)[[2]], NA))

1 Like