Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Grid in an R plot

Tags:

plot

r

Is there a command to easily add a grid onto an R plot?

like image 684
Christian Avatar asked Dec 26 '09 14:12

Christian


People also ask

What is a grid in R?

Grid graphics is a low-level system for plotting within R and is as a separate system from base R graphics. By “low-level,” we mean that grid graphics functions are typically used to modify very specific elements of a plot, rather than being functions to use for a one-line plotting call.

What is plot grid?

A “plotting grid” is a physical chart used to lay out the components of a story in a visual way. It often looks a lot like this: This is a photo of the actual ratty old plotting grid I use. The plotting grid can be useful to anyone at any stage of writing.


2 Answers

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!

like image 56
cbare Avatar answered Oct 07 '22 06:10

cbare


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.

like image 28
Dirk Eddelbuettel Avatar answered Oct 07 '22 07:10

Dirk Eddelbuettel