Hi,
I'm having trouble taking an aesthetic mapping like 'color' and associating a different number of labels in the resulting guide.
In my scenario, I have N items in a dataframe but I would only like to highlight 1 or 2 items with a color and leave the remaining items gray. In the resulting guide, I'd like to call out those 1 or 2 items but group the remaining items as "Other".
I'll use mtcars as a toy example. As you can see, the best I can achieve seems to be listing each gray item individually as "Other" which won't work once I have 20+ items.
Instead, here is a doctored version of what I'm envisioning:
R code below
library(tidyverse)
# Regular plot output
cars_head <- mtcars %>% mutate(car_name = rownames(mtcars)) %>% head()
ggplot(cars_head) + geom_point(aes(x=mpg,y=disp,color=car_name))
# Assign which cars to highlight
highlight <- c("Datsun 710"="red","Hornet 4 Drive"="blue", "Hornet Sportabout"="gray",
"Mazda RX4"="gray","Mazda RX4 Wag"="gray","Valiant"="gray")
# Plot with manual scale. The legend shows each car individually
ggplot(cars_head) + geom_point(aes(x=mpg,y=disp,color=car_name)) +
scale_color_manual(values = highlight)
# When using identical labels and colors, the legend items are not grouped
ggplot(cars_head) + geom_point(aes(x=mpg,y=disp,color=car_name)) +
scale_color_manual(values = highlight, labels = c("Datsun 710","Hornet 4 Drive","Other","Other","Other","Other"))