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

From: Afshartous, David <DAfshartous_at_med.miami.edu>
Date: Mon, 10 Nov 2008 14:16:21 -0500

Thanks. I tried you suggestion and it indeed solves the problem. For the sample code below the appropriate substitute to the curve function is:

xv = seq(0, 3, by = .05)
yv = sin(xv)
yv.new = cos(xv)
p.12 = xyplot(yv + yv.new ~ xv, type="l", lty=c(1,5), col="black")

On 11/10/08 2:09 PM, "Greg Snow" <Greg.Snow_at_imail.org> wrote:

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.
______________________________________________ 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.
Received on Mon 10 Nov 2008 - 19:32:13 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Mon 10 Nov 2008 - 20:30:23 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive