Book Image

R Graph Essentials

Book Image

R Graph Essentials

Overview of this book

Table of Contents (11 chapters)
R Graph Essentials
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Including a grid on your graph


You can add a grid to your plot using the grid() command. Let's set up a simple graph and add a grid:

x <- seq(1:5)
y <- x
plot(x, y, pch = 16)

Let's add a default grid with horizontal and vertical grid lines at major units in both the horizontal and vertical directions:

grid()

You get the following graph:

Now, we omit the horizontal grid lines using ny = NA. Of course, you could do the same for the vertical grid lines.

plot(x, y, pch = 16)
grid(ny=NA)

We get the following graph:

Setting the numbers of grid lines to NULL produces the default option of grid lines at every unit, for example:

plot(x, y, pch = 16)
grid(nx = NULL, ny = NULL)