Hello,
I don't know if I'm in the right topic but here's my question.
I created a histogram with ggplot with quite a few variables.
The default colors generated by R are not that distinct. So I used the polychrome package for myself to create my color palette according to my number of variables.
Problem I can't integrate it into my ggplot..
Also, I'd like the legend to be displayed in descending order, so the first variable that's displayed (with its associated color) is the one with the highest value.
#create my own color palette :
P20 = createPalette(20, c("#ff0000", "#00ff00", "#0000ff"))
swatch(P20)
#Ggplot
df%>%
pivot_longer(
cols = Sp1 : Sp20,
names_to = "species",
values_to = "number"
) %>%
filter(!is.na(number)) |>
ggplot(aes(x = reorder(Station,number), y = number)) +
geom_col(aes(fill = species), width = 0.7) +
theme(axis.text.x = element_text(angle = 90, vjust = 0.5, hjust=1)) +
scale_fill_brewer(palette = "Paired")
Here I used the "Paired" palette from the RColorBrewer package because they are really distinct but there are only 12..
To add my P20 palette I tried with scale_fill_manual (values= P20) but it doesn't work..
Hope you understand^^