Book Image

R Graphs Cookbook Second Edition

Book Image

R Graphs Cookbook Second Edition

Overview of this book

Table of Contents (22 chapters)
R Graphs Cookbook
Credits
About the Authors
About the Reviewers
www.PacktPub.com
Preface
Index

Choosing color combinations and palettes


We often need more than one color to represent various elements in graphs. Palettes are combinations of colors, which is a convenient way to use multiple colors without choosing individual colors separately. R provides inbuilt color palettes as well as the ability to create our own custom palettes. Using palettes is a good way to avoid repeatedly choosing or setting colors in multiple locations, which can be a source of error and confusion. This helps in separating the presentation settings of a graph from the construction.

Getting ready

All you need to try out in this recipe is to run R and type the recipe in the command prompt. You can also choose to save the recipe as a script so that you can use it again later on. One new library needs to be installed, which is also explained.

How to do it...

We can change the current palette by passing a character vector of colors to the palette() function as shown in the following code:

palette(c("red","blue","green...