Is there a command to easily add a grid onto an R plot?
+5
A:
See help(grid)
which works with standard graphics -- short example:
R> set.seed(42)
R> plot(cumsum(rnorm(100)), type='l')
R> grid()
The ggplot2 package defaults to showing grids due to its 'Grammar of Graphics' philosophy. And lattice has a function panel.grid()
you can use in custom panel functions.
By the way, there are search functions for help as e.g. help.search("something")
and there is an entire package called sos to make R web searches more fruitful.
Dirk Eddelbuettel
2009-12-26 14:40:00
+2
A:
The grid command seems to draw grid lines where-ever it feels like. I usually use abline to put lines exactly where I want them. For example,
abline(v=(seq(0,100,25)), col="lightgray", lty="dotted")
abline(h=(seq(0,100,25)), col="lightgray", lty="dotted")
Good luck!
cbare
2009-12-28 02:12:19