Skip to Content
R Programming By Example
book

R Programming By Example

by Omar Trejo Navarro
December 2017
Beginner to intermediate
470 pages
12h 29m
English
Packt Publishing
Content preview from R Programming By Example

Adding a third dimension with colors

As often happens, we want to work on some code we had already created to add more features. In this case, we want to add a third dimension to the graphs using colors. We want to be able to specify a color variable that will be used to further divide the data in the graph.

To accomplish this, we add a color parameter to the function's signature using the "NULL check" pattern and we add the corresponding parameter in each case. Adding the parameter directly in the aes_string() function is not problematic in case of NULL because NULL values indicate to ggplot() we don't want to use a fill color for the graph.

However, note that we are not able to use the same technique with y . Instead, we check whether we ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Efficient R Programming

Efficient R Programming

Colin Gillespie, Robin Lovelace
R Programming

R Programming

Jared P. Lander

Publisher Resources

ISBN: 9781788292542Supplemental Content