Hi @jasonserviss , if you convert the colour variable to a factor when you construct the data frame with levels for black and white in addition to the observed values of colour I think the result is what you are after.
For your actual use case you may need to convert the variable to a factor and then use the forcats package to get the factor levels how you want them. Hope this helps
library(ggplot2)
df <- data.frame(
x = 1:4,
y = 1:4,
colour = factor(
c("red", "green", "blue", "yellow"),
levels = c("red", "green", "blue", "yellow","black","white")
)
)
ggplot(df, aes(x, y)) +
geom_tile(aes(fill = colour)) +
scale_fill_identity(
"trt",
labels = letters[1:2],
breaks = c("black", "white"),
guide = "legend",
drop = FALSE
)
it looks like this:
