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

Using graph templates


We might often find ourselves using similar code repetitively to plot similar kinds of data or different versions of the same dataset. Once we have analyzed our data and are looking to produce a finished graph, it can be useful to quickly try out different color combinations and other aesthetic settings without having to write too much repetitive code. In this recipe, we will learn how to create graph templates and use them to quickly try out various looks for a graph.

Getting ready

We will only use the base graphics functions for this recipe. So, just open up the R prompt and type in the following code. We will use the themes.csv file that contains theme parameters for this recipe. So, let's first load it:

themes<-read.csv("themes.csv")

How to do it...

We will make a simple scatter plot showing a random normal distribution and apply different color combination themes to it with a single command:

themeplot<-function(x,theme,...) {
    i<-which(themes$theme==theme...