There is a very similar question here: Add NA value to ggplot legend for continuous data map.
I tried to understand it, but I didn't manage to make it work for my data. So I created a super simple example. I have this data:
set.seed(1)
df = data.frame(a=rnorm(50), b=rnorm(50), c=rep(1:5, 10))
df[sample(1:50, 10), ]$c = NA
where all columns are numeric
. Now I'd like to make a ggplot with a legend entry for the NA-values. When I do the following:
ggplot(df) +
geom_point(
aes(x = a, y =b, col=c)
)
This is the result
What I want is something like this (when c is a a factor it gets automatically an entry):
ggplot(df) +
geom_point(
aes(x = a, y =b, col=factor(c))
)
Could I achieve more or less easy similar results and keep my values in class numeric
?