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)
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..
Here is the key point of this entire vignette: By default, Polychrome gives names to each of the colors in a palette. But, in ggplot, named colors will only be applied if they match the levels of an appropriate factor in the data. The simplest solution is to remove the names:
Thank to you both !
I combined your two answers and it worked!
For info after performing the "tutorial" of @Matthias' link with this data preparation: :