[R] Can grid lines color in a plot be specified?

davidr@rhotrading.com davidr at rhotrading.com
Fri Oct 1 16:31:20 CEST 2004

I usually use something like


This allows you to have irregularly spaced grid lines if you want. (Say
for futures expiration dates in my case.)

Also, as Marc pointed out, you may want to draw the lines or points
after the grid lines.

David L. Reiner
Rho Trading
440 S LaSalle Suite 620
Chicago  IL  60605

-----Original Message-----
From: Marc Schwartz [mailto:MSchwartz at medanalytics.com] 
Sent: Friday, October 01, 2004 8:16 AM
To: Luis Rideau Cruz
Cc: R-Help
Subject: Re: [R] Can grid lines color in a plot be specified?

On Fri, 2004-10-01 at 07:44, Luis Rideau Cruz wrote:
> R-help
> Is there any way to specify the color of grid lines in a simple plot?
> par(color.tick.marks=c("grey"))
> plot(rnorm(10),tck=1)
> Thank you

This is one approach:


# Now draw both axes
axis(1, tck = 1, col = "grey", lty = "dotted")
axis(2, tck = 1, col = "grey", lty = "dotted")

# Replace the grey plot region border lines with black

In this case, the grid lines are being drawn after the data is plotted,
so it is possible that the lines may overwrite your symbols or other
important visual information. An alternative would be to create the plot
background first, including the grid lines, then add the data with
lines() or points() or other functions. For example:

x <- rnorm(10)
plot(x, type = "n")
axis(1, tck = 1, col = "grey", lty = "dotted")
axis(2, tck = 1, col = "grey", lty = "dotted")
points(x, pch = 19)


Marc Schwartz

R-help at stat.math.ethz.ch mailing list
PLEASE do read the posting guide!

More information about the R-help mailing list