[R] Combing xyplot and curve() plot via print

Greg Snow Greg.Snow at imail.org
Mon Nov 10 19:09:31 CET 2008


The xyplot function is a lattice function that uses grid graphics.  The curve function is a base graphics function.  'par' and 'layout' work with base graphics, the print idea works with grid graphics.  Grid graphics and base graphics don't mix easily.  One option is to find a grid/lattice/ggplot2 alternative of the curve function so that you are using all grid graphics, or you can use base graphics to recreate the xyplot in base.  There is also the gridBase package that makes combining the 2 systems easier (but still not simple).

Hope this helps,

--
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
greg.snow at imail.org
801.408.8111


> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-
> project.org] On Behalf Of Afshartous, David
> Sent: Monday, November 10, 2008 8:51 AM
> To: r-help at r-project.org
> Subject: [R] Combing xyplot and curve() plot via print
>
> All,
>
> I'm trying to put an xyplot and a plot produced via curve() on the same
> page.  It seems that mfrow and layout don't work, and now I'm trying
> print
> but that does not work either.  Any suggestions much appreciated.
>
> Cheers,
> David
>
> p.11 = xyplot(1:10 ~ 1:10)
>
> curve(sin, 0,3, ylim=c(-3,3), ylab="sin and cos",  lty = 1)
> curve(cos, 0,3,  ylim=c(-3,3), lty = 5, add=TRUE)
> legend(2,2, legend = "legend here")
> p.12 = recordPlot()
>
> print(p.11, split = c(1,1, 2,1), more = T)
> print(p.12, split=c(2,1,2,1), more = T  )
>
>
>
>
>
> > sessionInfo()
> R version 2.7.1 (2008-06-23)
> i386-apple-darwin8.10.1
>
> locale:
> en_US.UTF-8/en_US.UTF-8/C/C/en_US.UTF-8/en_US.UTF-8
>
> attached base packages:
> [1] stats     graphics  grDevices utils     datasets  methods   base
>
> other attached packages:
> [1] lattice_0.17-8
>
> loaded via a namespace (and not attached):
> [1] Matrix_0.999375-11 grid_2.7.1         lme4_0.999375-24   nlme_3.1-
> 89
> >
>
> ______________________________________________
> 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.



More information about the R-help mailing list