dear all, I have a very simple question but I could not figure out. I need to make plots with grid in the background. something like I old retrive like this a=runif(100)*10 b=runif(100)*10 plot(a,b, pch=20, xlim=c(0, round(max(a))), ylim=c(0, round(max(b)))) vs=seq(0, max(a), 0.5) for(i in 1:length(vs)){ abline(v=vs[i], col="lightgrey") } hs=seq(0, max(b), 0.5) for(i in 1:length(hs)){ abline(h=hs[i], col="lightgrey") } points(a, b, pch=20) as you can see it is not very convenient -- john [[alternative HTML version deleted]]
hits=-2.6 tests=BAYES_00 X-USF-Spam-Flag: NO See ?grid though read the Note section of that page, which says that more fine tuning can be achieved through the use of abline directly. Also, note that abline is vectorized so you don't need the loop. Here is you example, adjusted to avoid the large spaces at x and y > 9.5 and which uses a single call to abline: a <- runif(100)*10 b <- runif(100)*10 plot(a,b, pch=20, xlim=c(0, round(max(a))), ylim=c(0, round(max(b))), type = "n") ## add 1 here to put in an extra grid line at 10 vs <- seq(0, max(a) + 1, 0.5) hs <- seq(0, max(b) + 1, 0.5) abline(v=vs, h=hs, col="lightgrey") points(a, b, pch=20) HTH G On Fri, 2008-01-25 at 14:14 +0100, John Lande wrote:> dear all, > > I have a very simple question but I could not figure out. > > I need to make plots with grid in the background. > > something like I old retrive like this > > a=runif(100)*10 > b=runif(100)*10 > plot(a,b, pch=20, xlim=c(0, round(max(a))), ylim=c(0, round(max(b)))) > vs=seq(0, max(a), 0.5) > for(i in 1:length(vs)){ > abline(v=vs[i], col="lightgrey") > } > hs=seq(0, max(b), 0.5) > for(i in 1:length(hs)){ > abline(h=hs[i], col="lightgrey") > } > points(a, b, pch=20) > > as you can see it is not very convenient > > -- > john > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code.-- %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~% Dr. Gavin Simpson [t] +44 (0)20 7679 0522 ECRC, UCL Geography, [f] +44 (0)20 7679 0565 Pearson Building, [e] gavin.simpsonATNOSPAMucl.ac.uk Gower Street, London [w] http://www.ucl.ac.uk/~ucfagls/ UK. WC1E 6BT. [w] http://www.freshwaters.org.uk %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%
On 1/25/2008 8:14 AM, John Lande wrote:> dear all, > > I have a very simple question but I could not figure out. > > I need to make plots with grid in the background. > > something like I old retrive like this > > a=runif(100)*10 > b=runif(100)*10 > plot(a,b, pch=20, xlim=c(0, round(max(a))), ylim=c(0, round(max(b)))) > vs=seq(0, max(a), 0.5) > for(i in 1:length(vs)){ > abline(v=vs[i], col="lightgrey") > } > hs=seq(0, max(b), 0.5) > for(i in 1:length(hs)){ > abline(h=hs[i], col="lightgrey") > } > points(a, b, pch=20) > > as you can see it is not very convenientHow about using xyplot() in the lattice package with a panel function to draw the gridlines? For example: library(lattice) a <- runif(100)*10 b <- runif(100)*10 xyplot(a ~ b, panel = function(x, y, ...){ panel.xyplot(x, y, ...) panel.grid(h=20,v=20)})> -- > john > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code.-- Chuck Cleland, Ph.D. NDRI, Inc. 71 West 23rd Street, 8th floor New York, NY 10010 tel: (212) 845-4495 (Tu, Th) tel: (732) 512-0171 (M, W, F) fax: (917) 438-0894
?grid --- John Lande <john.lande77 at gmail.com> wrote:> dear all, > > I have a very simple question but I could not figure > out. > > I need to make plots with grid in the background. > > something like I old retrive like this > > a=runif(100)*10 > b=runif(100)*10 > plot(a,b, pch=20, xlim=c(0, round(max(a))), > ylim=c(0, round(max(b)))) > vs=seq(0, max(a), 0.5) > for(i in 1:length(vs)){ > abline(v=vs[i], col="lightgrey") > } > hs=seq(0, max(b), 0.5) > for(i in 1:length(hs)){ > abline(h=hs[i], col="lightgrey") > } > points(a, b, pch=20) > > as you can see it is not very convenient > > -- > john > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, > reproducible code. >Looking for the perfect gift? Give the gift of Flickr!