Search notes:

R graphics: adding a grid

The value of a graph might be increased by adding a grid to it.
This can be done using the grid function.
Note: in the following example, grid is first called and points afterwards in order to not overpaint the grid with the points:
x11()

x <- seq(-6, 10, by=0.25) # c(-6:10)
y <- x*x*x/8 - 9*x -15

x11()

plot(
     c(), c(),    # Empty set, points will be drawn later …
     type = "n",  # start new plot, but don't add data
    xlim=c(-8,12)                  ,
    ylim=c(-45,15)                 ,
  )

grid()

# Call points again so that points that were drawn over by grid are
# painted »above« the grid:
points(x, y)

# wait for mouse click or enter pressed:
z <- locator(1)
Github repository about-r, path: /graphics/decoration/grid.R

See also

R graphics

Index