I am using R 2.2.1 on a Windows 2000 PC. When I do a grid() after the boxplot it overprints the boxplot:> boxplot(count ~ spray, data = InsectSprays, col = "lightgray") > grid(nx=NA, ny=NULL) >if I try the panel.first> boxplot(count ~ spray, data = InsectSprays, col = "lightgray",+ panel.first=grid(nx=NA, ny=NULL))>I can see the grid flash and go away. If I close the device and then try the panel.first, I do not get a boxplot and the following error message:> boxplot(count ~ spray, data = InsectSprays, col = "lightgray",+ panel.first=grid(nx=NA, ny=NULL)) Error in abline(h = at, col = col, lty = lty, lwd = lwd) : plot.new has not been called yet>Same thing when I try pdf device:> pdf("test.pdf") > boxplot(count ~ spray, data = InsectSprays, col = "lightgray",+ panel.first=grid(nx=NA, ny=NULL)) Error in abline(h = at, col = col, lty = lty, lwd = lwd) : plot.new has not been called yet> dev.off()null device 1 How can I get the grid behind the boxplot? Thank you, Toby Popenfoose Donnelley Manufacturing Supervisor tpopenfoose at earthlink.net
Hi, likely it's not the most elegant way, but it's straight-forward and the first which popped in my mind: a <- rnorm(100) # either boxplot(a, col="white", border="white") my.grid <- seq(-4, 4, 0.5) abline(h=my.grid, col="grey", lty=2) boxplot(a, col="red", add = TRUE) # or boxplot(a, col="white", border="white") grid(ny=5) boxplot(a, col="red", add = TRUE) Ciao, Carlo Giovanni Camarda ==========================================Camarda Carlo Giovanni PhD-Student Max Planck Institute for Demographic Research Konrad-Zuse-Strasse 1 18057 Rostock, Germany Tel: +49 (0)381 2081 172 Fax: +49 (0)381 2081 472 camarda@demogr.mpg.de ========================================== I am using R 2.2.1 on a Windows 2000 PC. When I do a grid() after the boxplot it overprints the boxplot:> boxplot(count ~ spray, data = InsectSprays, col = "lightgray") > grid(nx=NA, ny=NULL) >if I try the panel.first> boxplot(count ~ spray, data = InsectSprays, col = "lightgray",+ panel.first=grid(nx=NA, ny=NULL))>I can see the grid flash and go away. If I close the device and then try the panel.first, I do not get a boxplot and the following error message:> boxplot(count ~ spray, data = InsectSprays, col = "lightgray",+ panel.first=grid(nx=NA, ny=NULL)) Error in abline(h = at, col = col, lty = lty, lwd = lwd) : plot.new has not been called yet>Same thing when I try pdf device:> pdf("test.pdf") > boxplot(count ~ spray, data = InsectSprays, col = "lightgray",+ panel.first=grid(nx=NA, ny=NULL)) Error in abline(h = at, col = col, lty = lty, lwd = lwd) : plot.new has not been called yet> dev.off()null device 1 How can I get the grid behind the boxplot? Thank you, Toby Popenfoose Donnelley Manufacturing Supervisor tpopenfoose@earthlink.net +++++ This mail has been sent through the MPI for Demographic Rese...{{dropped}}
Simply add the same boxplot over your first graph using par(new=TRUE) x <-1:10 y <-1:5 boxplot(x, y,col="blue") grid(nx=NA, ny=NULL) #grid over boxplot par(new=TRUE) boxplot(x, y,col="blue")#grid behind boxplot Neuro>From: "Toby Popenfoose" <tpopenfoose at earthlink.net> >Reply-To: Toby Popenfoose <tpopenfoose at earthlink.net> >To: <r-help at stat.math.ethz.ch> >Subject: [R] How to get a grid behind a boxplot >Date: Fri, 28 Apr 2006 19:46:52 -0400 > >I am using R 2.2.1 on a Windows 2000 PC. >When I do a grid() after the boxplot >it overprints the boxplot: > > > boxplot(count ~ spray, data = InsectSprays, col = "lightgray") > > grid(nx=NA, ny=NULL) > > > >if I try the panel.first > > > boxplot(count ~ spray, data = InsectSprays, col = "lightgray", >+ panel.first=grid(nx=NA, ny=NULL)) > > > >I can see the grid flash and go away. > >If I close the device and then try the panel.first, >I do not get a boxplot and the following error message: > > > boxplot(count ~ spray, data = InsectSprays, col = "lightgray", >+ panel.first=grid(nx=NA, ny=NULL)) >Error in abline(h = at, col = col, lty = lty, lwd = lwd) : > plot.new has not been called yet > > > >Same thing when I try pdf device: > > > pdf("test.pdf") > > boxplot(count ~ spray, data = InsectSprays, col = "lightgray", >+ panel.first=grid(nx=NA, ny=NULL)) >Error in abline(h = at, col = col, lty = lty, lwd = lwd) : > plot.new has not been called yet > > dev.off() >null device > 1 > >How can I get the grid behind the boxplot? > >Thank you, >Toby Popenfoose >Donnelley Manufacturing Supervisor >tpopenfoose at earthlink.net > >______________________________________________ >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