8.11 Colors
Colors can be set a different way in ggplot2, and in R in general.
The easiest way is to fetch the colors by their names.
There are 657 color names available for you to pick! You can check them by pasting the following in the console:
ggplot2 provides a color scale by default. Mainy different palettes are available to change the default scale.
You can easily pick palettes from the RColorBrewer package, that is included in ggplot2.
Available palettes are shown below:
We can easily take advantage of the RColorBrewer’s palettes by using either scale_color_brewer() or scale_fill_brewer() layers (depending if color or fill was set in aes(), respectively):
ggplot(data=gtf, mapping=aes(x=chr, fill=gene_type)) +
geom_bar(position="dodge") +
scale_fill_brewer()
The default palette used is the “Blues” palette.
How does that look using “Dark2” palette?