Book contents
- Frontmatter
- Contents
- Preface to the second edition
- Preface to the first edition
- 1 Getting started
- 2 Introduction to the R language
- 3 Programming statistical graphics
- 4 Programming with R
- 5 Simulation
- 6 Computational linear algebra
- 7 Numerical optimization
- Appendix Review of random variables and distributions
- Index
3 - Programming statistical graphics
Published online by Cambridge University Press: 05 July 2016
- Frontmatter
- Contents
- Preface to the second edition
- Preface to the first edition
- 1 Getting started
- 2 Introduction to the R language
- 3 Programming statistical graphics
- 4 Programming with R
- 5 Simulation
- 6 Computational linear algebra
- 7 Numerical optimization
- Appendix Review of random variables and distributions
- Index
Summary
Users of statistical computing need to produce graphs of their data and the results of their computations. In this chapter we start with a general overview of how this is done in R, and learn how to draw some basic plots. We then discuss some of the issues involved in choosing a style of plot to draw: it is not always an easy choice, and there are plenty of bad examples in the world to lead us astray. Finally, we will go into some detail about how to customize graphs in R.
There are several different graphics systems in R. The oldest one is most directly comparable to the original S graphics, and is now known as base graphics. You can think of base graphics as analogous to drawing with ink on paper. You build up a picture by drawing fixed things on it, and once something is drawn, it is permanent, though you might be able to cover it with something else, or move to a clean sheet of paper. Since the very beginning, base graphics has been designed to allow easy production of good quality scientific plots. In this chapter we will concentrate on base graphics.
The grid package provides the basis for a newer graphics system. It also has facilities to produce good quality graphics, but the programmer has access to the individual pieces of a graph, and can modify them: a graph is more like a physical model being built and displayed, rather than just drawn. The lattice and ggplot2 packages provide functions for high-level plots based on grid graphics.
Both base and grid graphics are designed to be “device independent.” Directions are given regarding where to draw and these drawing commands work on any device. The actual look of a graph will vary slightly from one device to another (e.g. on paper versus in a window on your screen), because of their different capabilities.
There are other more exotic graphics systems available in R as well, providing interactive graphics, 3D displays, etc. Some of these will be mentioned briefly in Section 3.4.
- Type
- Chapter
- Information
- A First Course in Statistical Programming with R , pp. 49 - 75Publisher: Cambridge University PressPrint publication year: 2016