[BioC] lattice and base-graphics using gridBase
Maarten van Iterson
M.van_iterson.HG at lumc.nl
Wed May 12 09:14:41 CEST 2010
Hi Paul Murrell,
Thanks for your reply this is exactly what I was looking for.
To answer your question: I prefer the default graphical parameters of
the boxplot-function and tried to reproduce these using the bwplot (and
trellis.par.set) but didn't succeed and thought that combining both was
maybe easier?
In the future I will post questions like these on the R-help listserv.
Cheers,
Maarten
On Wed, 2010-05-12 at 16:42 +1200, Paul Murrell wrote:
> Hi
>
> On 5/12/2010 12:54 AM, James W. MacDonald wrote:
> > Hi Maarten,
> >
> > Maarten van Iterson wrote:
> >> Dear list,
> >>
> >> I'm trying to combine lattice and base-graphics following the example
> >> from Paul Murrell's R Graphics (B.1.2).
> >>
> >> The question I have is how to add the y-axis from the base-graphics to
> >> the lattice plot below?
> >
> > Neither of these packages are part of Bioconductor, so I think you would
> > be better served asking this question on the R-help listserv.
>
> Agreed, but since we're here already ...
>
> This code should work:
>
> boxplot.panel <- function(x, y, subscripts, ...){
> par(plt=gridPLT(), new=TRUE, ps=8)
> boxplot(data[[subscripts]], col=rep(2:7, each=2),
> ylab="", axes=FALSE,
> names=NULL, outline=FALSE)
> axis(2)
> }
>
> df <- data.frame(y=1:3, x=1:3, Method=LETTERS[1:3])
>
> plot.new()
> xyplot(y ~ x | Method, data=df, subscripts=TRUE, xlab="", ylab="",
> scales=list(draw=FALSE),
> panel=boxplot.panel, layout=c(1,3))
>
> Note that I have taken out the pushing and popping of viewports (so that
> when the boxplot axis is drawn it lines up with the panel border) and
> added axis(2) to draw the axis (and specified 'scales' in xyplot() to
> suppress the lattice axes). I have also added plot.new() just before
> the call to xyplot(), which makes sure that the base graphics system is
> set up (so you don't get the warning).
>
> But one question for you: why do you want to use boxplot() instead of
> bwplot() ?
>
> Paul
>
> > Best,
> >
> > Jim
> >
> >
> >>
> >> library(gridBase)
> >> library(lattice)
> >>
> >> data<- list(A=matrix(rnorm(8*100, 1, 1), ncol=8), B=matrix(rnorm(8*100,
> >> 0, 1), ncol=8), C=matrix(rnorm(8*100, -1, 1), ncol=8))
> >>
> >> boxplot.panel<- function(x, y, subscripts, ...){
> >> pushViewport(viewport(gp=gpar(fontsize=8)),
> >> viewport(y=unit(0.95, "npc"), width=0.9,
> >> height=unit(0.95, "npc"), just="top"))
> >> par(plt=gridPLT(), new=TRUE, ps=8)
> >> boxplot(data[[subscripts]], col=rep(2:7, each=2), ylab="", axes=FALSE,
> >> names=NULL, outline=FALSE)
> >> popViewport(2)
> >> }
> >>
> >> df<- data.frame(y=1:3, x=1:3, Method=LETTERS[1:3])
> >>
> >> xyplot(y ~ x | Method, data=df, subscripts=TRUE, xlab="", ylab="",
> >> panel=boxplot.panel, layout=c(1,3))
> >>
> >> sessionInfo()
> >> R version 2.10.0 (2009-10-26)
> >> x86_64-unknown-linux-gnu
> >>
> >> locale:
> >> [1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C
> >> [3] LC_TIME=en_US.UTF-8 LC_COLLATE=en_US.UTF-8
> >> [5] LC_MONETARY=C LC_MESSAGES=en_US.UTF-8
> >> [7] LC_PAPER=en_US.UTF-8 LC_NAME=C
> >> [9] LC_ADDRESS=C LC_TELEPHONE=C
> >> [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C
> >>
> >> attached base packages:
> >> [1] grid stats graphics grDevices utils datasets
> >> methods
> >> [8] base
> >>
> >> other attached packages:
> >> [1] lattice_0.17-26 gridBase_0.4-3
> >>
> >> Thanks in advance,
> >>
> >> Maarten
> >>
> >>
> >
>
--
Maarten van Iterson
Center for Human and Clinical Genetics
Leiden University Medical Center (LUMC)
Research Building, Einthovenweg 20
Room S-04-038
Phone: 071-526 9439
E-mail: M.van_iterson.HG at lumc.nl
---------------
Postal address:
Postzone S-04-P
Postbus 9600
2300 RC Leiden
The Netherlands
More information about the Bioconductor
mailing list