Assigning multiple colors

Hello everyone and thank you in advance.

Currently I'm learning R through a course and I have a question I can't seem to figure out or find the answer to. I'm working with the "palmerpenguins" data set and wanted to know if I can assign a specific color (of my choosing) for each species of penguins.
I know I can write :
"color = species" in the aes function and
"color = 'red'" outside of the aes function to make the plot Red.
Would I have to assign a specific color to each type of penguin and then incorporate that into the code?

You can use scale_color_manual() in the same way I have used scale_fill_manual().

DF <- data.frame(Species=c("Emperor","Cape","Hoboken"),
                 Value=c(23,34,19))
library(ggplot2)
COLORS <- c(Emperor="red",Cape="blue",Hoboken="green")
ggplot(DF,aes(x=Species,y=Value,fill=Species))+
  geom_col()+scale_fill_manual(values=COLORS)

Created on 2022-02-02 by the reprex package (v2.0.1)

1 Like

Thank you so much. It took me a second to figure out how to apply it, but it worked.

This topic was automatically closed 21 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.