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
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 youThis is one approach: plot(rnorm(10)) # 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 box() 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") box() points(x, pch = 19) HTH, Marc Schwartz
On Fri, 2004-10-01 at 08:15, Marc Schwartz wrote:> 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 youOk....now that I have finished my second cup of coffee... For some reason, I keep forgetting about the grid() function: plot(rnorm(10)) grid() The same comment applies here with respect to the grid being drawn after your data, so you might want to do something like: x <- rnorm(10) plot(x, type = "n") grid() points(x, pch = 19) See ?grid for more information. Marc
davidr@rhotrading.com
2004-Oct-01 14:31 UTC
[R] Can grid lines color in a plot be specified?
I usually use something like abline(h=seq(...),col="green") abline(v=seq(...),col="green") 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. HTH, David L. Reiner Rho Trading 440 S LaSalle Suite 620 Chicago IL 60605 312-362-4963 -----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 youThis is one approach: plot(rnorm(10)) # 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 box() 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") box() points(x, pch = 19) HTH, Marc Schwartz ______________________________________________ R-help at stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html