ColorBrewer project is a very popular tool to select harmoniously matching color palettes. RColorBrewer
is a port of the project for R
and provides also colorblind-friendly palettes.
An example of use
colors_vec <- brewer.pal(5, name = 'BrBG')
print(colors_vec)
[1] "#A6611A" "#DFC27D" "#F5F5F5" "#80CDC1" "#018571"
RColorBrewer
creates coloring options for ggplot2
: scale_color_brewer
and scale_fill_brewer
.
library(ggplot2)
ggplot(mtcars)+
geom_point(aes(x = mpg, y = hp, color = factor(cyl)), size = 3)+
scale_color_brewer(palette = 'Greens')+
theme_minimal()+
theme(legend.position = c(.8,.8))