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 ...

Get R Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.