Ranjan Maitra
2012-Dec-11 03:03 UTC
[R] lattice question: how to change the dot on boxplot to line
Hi, How does one change the dot for the median in a boxplot drawn using lattice? I have been looking at> names(trellis.par.get())[1] "grid.pars" "fontsize" "background" [4] "panel.background" "clip" "add.line" [7] "add.text" "plot.polygon" "box.dot" [10] "box.rectangle" "box.umbrella" "dot.line" [13] "dot.symbol" "plot.line" "plot.symbol" [16] "reference.line" "strip.background" "strip.shingle" [19] "strip.border" "superpose.line" "superpose.symbol" [22] "superpose.polygon" "regions" "shade.colors" [25] "axis.line" "axis.text" "axis.components" [28] "layout.heights" "layout.widths" "box.3d" [31] "par.xlab.text" "par.ylab.text" "par.zlab.text" [34] "par.main.text" "par.sub.text" I tried playing around with dot.line and dot.symbol but could not figure out what to do. Is there anything else I could try. As a reproducible example, we can consider: library(lattice) bwplot(voice.part ~ height, data=singer, xlab="Height (inches)") I want the dots for the medians to be replaced by a line through the median. Any suggestions? Many thanks, Ranjan PS; Also, how do I get the rectangles to be filled? I tried the following: box.rectangle <- trellis.par.get("box.rectangle") box.rectangle$fill<-"opaque" (also tried "filled", "shaded", etc. to no avail) trellis.par.set("box.rectangle", box.rectangle) but get errors in plotting. Many thanks again and best wishes, Ranjan ____________________________________________________________ FREE 3D EARTH SCREENSAVER - Watch the Earth right on your desktop!
S Ellison
2012-Dec-11 03:53 UTC
[R] lattice question: how to change the dot on boxplot to line
On 11 Dec 2012, at 03:05, "Ranjan Maitra" <maitra.mbox.ignored@inbox.com<mailto:maitra.mbox.ignored@inbox.com>> wrote: How does one change the dot for the median in a boxplot drawn using lattice? Check your ?panel.bwplot help page. The online version at http://stat.ethz.ch/R-manual/R-devel/library/lattice/html/panel.bwplot.html says "pch="|" is treated specially, by replacing the dot with a line ..." S Ellison ******************************************************************* This email and any attachments are confidential. Any use, copying or disclosure other than by the intended recipient is unauthorised. If you have received this message in error, please notify the sender immediately via +44(0)20 8943 7000 or notify postmaster@lgcgroup.com and delete this message and any copies from your computer and network. LGC Limited. Registered in England 2991879. Registered office: Queens Road, Teddington, Middlesex, TW11 0LY, UK [[alternative HTML version deleted]]
Duncan Mackay
2012-Dec-11 04:09 UTC
[R] lattice question: how to change the dot on boxplot to line
Hi Try this (Deepayan gave me this in reply to a similar question several years ago) bwplot(voice.part ~ height, data=singer, xlab="Height (inches)",pch = "|", panel = function(x, y, ...) { panel.bwplot(x, y, ...) meds <- tapply(x, y, median) ylocs <- seq_along(meds) panel.segments(meds, ylocs - 1/4, meds, ylocs + 1/4, lwd = 2, col = "red") }) I have made the colour red as one of the lines overlays the box. It gets a bit more involved with panel functions and horizontal - try this DF <- data.frame(site = factor(rep(1:5, each = 20)), height = rnorm(100)) bwplot(height~ site,DF, pch = "|", panel = function(x, y, ..., horizontal) { panel.bwplot(x, y, ..., horizontal = horizontal) if (horizontal) { meds <- tapply(x, y, median) ylocs <- seq_along(meds) panel.segments(meds, ylocs - 1/4, meds, ylocs + 1/4, lwd = 2, col = "red") } else { meds <- tapply(y, x, median) xlocs <- seq_along(meds) panel.segments(xlocs - 1/4, meds, xlocs + 1/4, meds, lwd = 2, col = "red") } ## if (horizontal) } ## panel function ) ## bwplot Regards Duncan Duncan Mackay Department of Agronomy and Soil Science University of New England Armidale NSW 2351 Email: home: mackay at northnet.com.au At 13:03 11/12/2012, you wrote:>Hi, > >How does one change the dot for the median in a boxplot drawn using >lattice? I have been looking at > > > names(trellis.par.get()) > [1] "grid.pars" "fontsize" "background" > [4] "panel.background" "clip" "add.line" > [7] "add.text" "plot.polygon" "box.dot" >[10] "box.rectangle" "box.umbrella" "dot.line" >[13] "dot.symbol" "plot.line" "plot.symbol" >[16] "reference.line" "strip.background" "strip.shingle" >[19] "strip.border" "superpose.line" "superpose.symbol" >[22] "superpose.polygon" "regions" "shade.colors" >[25] "axis.line" "axis.text" "axis.components" >[28] "layout.heights" "layout.widths" "box.3d" >[31] "par.xlab.text" "par.ylab.text" "par.zlab.text" >[34] "par.main.text" "par.sub.text" > >I tried playing around with dot.line and dot.symbol but could not >figure out what to do. Is there anything else I could try. > > > >As a reproducible example, we can consider: > >library(lattice) >bwplot(voice.part ~ height, data=singer, xlab="Height (inches)") > >I want the dots for the medians to be replaced by a line through the >median. > >Any suggestions? > >Many thanks, >Ranjan > >PS; Also, how do I get the rectangles to be filled? I tried the >following: > >box.rectangle <- trellis.par.get("box.rectangle") >box.rectangle$fill<-"opaque" > >(also tried "filled", "shaded", etc. to no avail) > >trellis.par.set("box.rectangle", box.rectangle) > >but get errors in plotting. > >Many thanks again and best wishes, >Ranjan > >____________________________________________________________ >FREE 3D EARTH SCREENSAVER - Watch the Earth right on your desktop! > >______________________________________________ >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.