So to be candid, I have a solution for my problem, but this is primarily a question about laziness... I have recently begun customising my ggplot2
graphs. One thing I've been doing is defining a different colour palette. Most of my plots revolve around three factors, so I've been specifying the colours as follows:
cols <- c(
"factorA" = "#CC6677",
"factorB" = "#2DA17E",
"factorC" = "#4477AA"
)
I can then call those in ggplot, for example:
ggplot(data) +
geom_point(x = factor, y = values, fill = factor) +
scale_colour_manual(values = cols)
and that works perfectly fine; I've managed to customise over 40 plots using the above. But I've just realised that I now want to include NA
values in a large minority of those, but I can't seem to define a colour for NA
values as follows:
cols <- c(
"factorA" = "#CC6677",
"factorB" = "#2DA17E",
"factorC" = "#4477AA",
na.value = "#000000",
)
From what I've just read you have to define it outside the values call (and this does work):
...+ scale_colour_manual(values = cols, na.value = "#000000")
but I don't really want to go through and manually append the na.value call to those plots that need it, unless I have no choice... Is there a way I can edit my cols
to make this less painful?