An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20120918/7db0f43d/attachment.pl>
add reference lines (or grid) in background
6 messages · Luigi Marongiu, Jose Iparraguirre, Jim Lemon +2 more
Dear Luigi, Here's an option: boxplot(x, boxcol="white", whiskcol="white",medcol="white",staplecol="white") abline(h=c(-1,0,1)) grid(NA, 4, lwd = 2) boxplot(x,add=T) Regards, Jos? Iparraguirre -----Original Message----- From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf Of Luigi Sent: 18 September 2012 09:36 To: r-help at r-project.org Subject: [R] add reference lines (or grid) in background Dear all, Is there a simple way to add reference lines in background? I am trying with abline() or grid() but the lines, since they are executed after the plot function, are draw on top. How can I draw such lines beneath the main plot? Here is an example: x<-rnorm(100) boxplot(x) abline(h=c(-1,0,1)) grid(NA, 4, lwd = 2) regards, Luigi Marongiu, MSc ______________________________________________ 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. Age UK and YouthNet are official charities for the Virgin London Marathon 2013 We need you to Run for it. Join the team and help raise vital funds to bring generations together to combat loneliness and isolation. Go to http://www.runforit.org.uk for more information or contact Helen Parson at helen.parsons at ageuk.org.uk or on 020 303 31369. Age UK and YouthNet. A lifeline, online. www.runforit.org.uk Age UK Improving later life www.ageuk.org.uk ------------------------------- Age UK is a registered charity and company limited by guarantee, (registered charity number 1128267, registered company number 6825798). Registered office: Tavis House, 1-6 Tavistock Square, London WC1H 9NA. For the purposes of promoting Age UK Insurance, Age UK is an Appointed Representative of Age UK Enterprises Limited, Age UK is an Introducer Appointed Representative of JLT Benefit Solutions Limited and Simplyhealth Access for the purposes of introducing potential annuity and health cash plans customers respectively. Age UK Enterprises Limited, JLT Benefit Solutions Limited and Simplyhealth Access are all authorised and regulated by the Financial Services Authority. ------------------------------ This email and any files transmitted with it are confide...{{dropped:28}}
On 09/18/2012 06:35 PM, Luigi wrote:
Dear all, Is there a simple way to add reference lines in background? I am trying with abline() or grid() but the lines, since they are executed after the plot function, are draw on top. How can I draw such lines beneath the main plot? Here is an example: x<-rnorm(100) boxplot(x) abline(h=c(-1,0,1)) grid(NA, 4, lwd = 2)
Hi Luigi, There are a few different ways to get your grid "under" the plot. Perhaps the most straightforward is to display the plot, then the grid, then "add" the plot on top using the "add" argument. The box.heresy plot in the plotrix package is one of the functions that has a "do.first" argument. This can be a call to "grid" and displays the grid before the plot. This involves only one call, but it is a bit different from the standard boxplot. Jim
Not sure if it is quite the same but ggplot2 does this as its default formatting. library(ggplot2) x<-rnorm(100) qplot(factor(0),x, geom="boxplot") John Kane Kingston ON Canada
-----Original Message----- From: marongiu.luigi at gmail.com Sent: Tue, 18 Sep 2012 09:35:47 +0100 To: r-help at r-project.org Subject: [R] add reference lines (or grid) in background Dear all, Is there a simple way to add reference lines in background? I am trying with abline() or grid() but the lines, since they are executed after the plot function, are draw on top. How can I draw such lines beneath the main plot? Here is an example: x<-rnorm(100) boxplot(x) abline(h=c(-1,0,1)) grid(NA, 4, lwd = 2) regards, Luigi Marongiu, MSc [[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.
____________________________________________________________ GET FREE SMILEYS FOR YOUR IM & EMAIL - Learn more at http://www.inbox.com/smileys Works with AIM?, MSN? Messenger, Yahoo!? Messenger, ICQ?, Google Talk? and most webmails
There is a "panel.first" argument that can be used with many different types of plots. plot(x, panel.first=abline(h=-3:3, lty="dotted", col="gray"), pch=16, col="red", cex=3) # red big plotting characters: to show that ablines are drawn before plotting # the result is different from doing the plot first and abline's after that. But this doesn't work with boxplot: ablines are drawn (so panel.first does something) but then overplotted. boxplot(x, panel.first=abline(h=-3:3, lwd=100, col="red")) # lwd=100: this would be absurd if it worked but now I can see only something red flashing # on the screen before the boxplot is drawn Maybe there are some extra parameters to boxplot or bxp (which does the drawing) that could be used (from what I see on the screen I can imagine that the ablines are first drawn but deleted by the white background of boxplot; so it might help to make this background transparent instead of white; but I haven't examined the code so can't be sure this is what bxp does). Or it might be easier to do it with ggplot. Regards, Kenn Konstabel
On 9/18/12, John Kane <jrkrideau at inbox.com> wrote:
Not sure if it is quite the same but ggplot2 does this as its default formatting. library(ggplot2) x<-rnorm(100) qplot(factor(0),x, geom="boxplot") John Kane Kingston ON Canada
-----Original Message----- From: marongiu.luigi at gmail.com Sent: Tue, 18 Sep 2012 09:35:47 +0100 To: r-help at r-project.org Subject: [R] add reference lines (or grid) in background Dear all, Is there a simple way to add reference lines in background? I am trying with abline() or grid() but the lines, since they are executed after the plot function, are draw on top. How can I draw such lines beneath the main plot? Here is an example: x<-rnorm(100) boxplot(x) abline(h=c(-1,0,1)) grid(NA, 4, lwd = 2) regards, Luigi Marongiu, MSc [[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.
____________________________________________________________ GET FREE SMILEYS FOR YOUR IM & EMAIL - Learn more at http://www.inbox.com/smileys Works with AIM?, MSN? Messenger, Yahoo!? Messenger, ICQ?, Google Talk? and most webmails ______________________________________________ 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.
Dear all , Thank you for the replies. The idea of plotting back on top of the grid was the right direction and after browsing and browsing I found a tip in the R archive ([R] How to get a grid behind a boxplot) by Neuro LeSuperH?ros which uses par(new=T): x<-rnorm(100) boxplot(x) abline(h=c(-1,0,1)) grid(NA, 4, lwd = 2) par(new=TRUE) boxplot(x, col="white") best wishes, Luigi