Is it possible to change the NA colour within a geom?

Hi,

Is it possible to change the NA colour within a geom?

I assume not..

Cheers
David

You can change the NA color using the na.value argument in the scale_color_*() functions.

library(tidyverse)

df = tibble(
  x = c('a', 'b', 'c', 'd'),
  y = c(1, 4, 5, 9),
  Color = c('color1', 'color2', 'color3', NA)
)


gg = ggplot(df, aes(x, y, color = Color)) +
  geom_point(size = 5) 

gg

gg +
  scale_color_discrete(na.value = 'black')

Created on 2022-09-01 with reprex v2.0.2.9000

1 Like

If you mean changing the color of a color or fill, you can do that in the appropriate scale_..() function with the na.value argument.

library(ggplot2)
DF <- data.frame(X=1:4,Y=2:5,Grp=c("A","B",NA,"A"))
ggplot(DF,aes(X,Y,color=Grp))+geom_point(size=3)


ggplot(DF,aes(X,Y,color=Grp))+geom_point(size=3)+
  scale_color_discrete(na.value="blue")

Created on 2022-09-01 with reprex v2.0.2

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.