scale_fill_discrete and own color palette

Hi,
I'm doing a geom_col plot and I used scale_fill_discrete to have my legend in descending order.
I also made my own colour palette to have the more distinctive colours in my plots.
But the problem is that my code doesn't take colour from my palette but use random colour and it's definitely not distinctive colour..

How can I figure it out ?
Here is my code :

#Plot
ggplot(x,aes(Station)) + geom_col(aes(y = Median, fill = Species), 
                                  color = "white") +
  theme(axis.text.x = element_text(angle = 90, vjust = 0.5, hjust=1)) +
  scale_colour_manual(values=P20) + 
  scale_fill_discrete(breaks = legend_order) 

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

Thanks

I think you need to use scale_fill_manual since you are using the fill aesthetic.

library(tidyverse)
#> Warning: package 'tibble' was built under R version 4.1.2
DF <- data.frame(Station = c("A", "B", "C", "A", "B", "C"),
                 median = c(2,4,3,3,5,4),
                 Species = c("Y", "Y", "Y", "Z", "Z", "Z"))
ggplot(DF, aes(Station, median, fill = Species)) + geom_col()

COLORS = c(Y = "pink", Z = "green")
legend_order <- c("Z", "Y")
ggplot(DF, aes(Station, median, fill = Species)) + geom_col() +
  scale_fill_manual(breaks = legend_order, values = COLORS)

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

It works, thanks very much
I though I have to keep "scale_fill_discrete" to be able to use my legend order !

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.