O'Reilly logo

R Cookbook by Paul Teetor

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 10. Graphics

Introduction

Graphics is a great strength of R. The graphics package is part of the standard distribution and contains many useful functions for creating a variety of graphic displays. This chapter focuses on those functions, although it occasionally suggests other packages. In this chapter’s See Also sections I mention functions in other packages that do the same job in a different way. I suggest that you explore those alternatives if you are dissatisfied with the basic function.

Graphics is a vast subject, and I can only scratch the surface here. If you want to delve deeper, I recommend R Graphics by Paul Murrell (Chapman & Hall, 2006). That book discusses the paradigms behind R graphics, explains how to use the graphics functions, and contains numerous examples—including the code to recreate them. Some of the examples are pretty amazing.

The Illustrations

The graphs in this chapter are mostly plain and unadorned. I did that intentionally. When you call the plot function, as in:

> plot(x)

you get a plain, graphical representation of x. You could adorn the graph with colors, a title, labels, a legend, text, and so forth, but then the call to plot becomes more and more crowded, obscuring the basic intention:

> plot(x, main="Forecast Results", xlab="Month", ylab="Production",
+      col=c("red", "black", "green")) 

I want to keep the recipes clean, so I emphasize the basic plot and then show later (as in Recipe 10.2) how to add adornments.

Notes on Graphics Functions

It is ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required