Home > Software design >  How to assign a color to the rest of the values in scale_color_manual?
How to assign a color to the rest of the values in scale_color_manual?

Time:11-19

So this is the way that I'm setting up my own color pallette:

nice_colors <- c('orange', 'red', 'blue')
names(nice_colors) <- c("4", "2", "3")

ggplot(mtcars, aes(mpg, wt, color = factor(carb)))  
  geom_point()   scale_colour_manual(values = nice_colors, name = 'carb') theme_bw()

mtcars$carb has 6 unique factors. I'm only assigning three of those factors so the rest of the factors are in grey. I want to assign the rest as green without explicitly telling it or it showing in my legend or changing the variable values.

enter image description here

CodePudding user response:

Set the na.value to green.

ggplot(mtcars, aes(mpg, wt, color = factor(carb)))  
  geom_point()   scale_colour_manual(values = nice_colors, name = 'carb', na.value = "green") theme_bw()

enter image description here

  • Related