Problem with colours geom_violin

Hi everybody,

Does anybody knwo why I don't get the graphics in the colours I indicate?

(I'm a newbie, thanks for the help ;))

Hi @Asteinza. To manually specify colors in ggplot, you need to specify the variable of interest within aes(). Below is an illustration with geom_bar.


# set cyl to character for example
mtcars$cyl = as.character(mtcars$cyl)

# fill specified outside of aes() - all same color
ggplot(mtcars, aes(x=cyl)) + 

# fill specified within aes - different color for each value of cyl
ggplot(mtcars, aes(x=cyl)) + 

# fill specified within aes and colors of cyl set manually
ggplot(mtcars, aes(x=cyl)) + 
  geom_bar(aes(fill=cyl)) +
  scale_fill_manual(values = c('orange', 'black', 'yellow'))

Thank you very much Scott!!!

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.