How do I flip the default ordering of colors which ggplot picks for factor variable passed onto 'fill' aesthetic. (Here, I have a factor variable with two levels Won
and Lost
).
Ref image below, I'd like this 'red-family' shade to go with Lost
; As it is, 'red' gets used for Won
category instead of Lost
, which in my view doesn't gel with one's common intuition of colors.
ggplot(data, mapping = aes(x = Party, y = Votes, fill = Result)) +
geom_bar(stat = "identity", width = .6)
Votes scored by Political Parties in Indian State of TamilNadu:
Thanks @Djork for sharing the link which answers 'Emulate ggplot default color-palette'
I used this code-chunk to preview and select color-codes of interest, from default-palette,
library(scales)
show_col(hue_pal()(4))
hue_pal()(4)
and later,
+ scale_fill_manual( values = c("#7CAE00", "#F8766D"))
to use the 'green' and 'red' chosen from default hue-palette.
To clarify, I found manual-colors resulting from 'green', 'red' custom-labels (as suggested in comments above) to be of very high contrast. With the hue-palette, I get nuanced color-tones.