Rich Shepard
2015-Jul-10 21:09 UTC
[R] Trellis Plots: translating lattice xyplot() to ggplot()
Hadley's ggplot2 book is quite old and a new version is in the works, but not yet out. I've been using lattice graphics but the knitr package doesn't support lattice, only basic plots and ggplot2. My Web searches for Trellis plots in ggplot2 equivalent to those in lattice have not been productive. I would appreciate a pointer to a resource that would teach me how to translate from lattice xyplot() to ggplot2 ggplot(). This is one such plot needing translation: xyplot(value ~ sampdate | variable, data=carlin.1.melt, rm.na = T) Rich
Roy Mendelssohn - NOAA Federal
2015-Jul-10 21:16 UTC
[R] Trellis Plots: translating lattice xyplot() to ggplot()
Don?t know for certain but might this help: http://journal.r-project.org/archive/2015-1/murrell.pdf From the latest issue of R Journal. Abstract The gridGraphics package provides a function, grid.echo(), that can be used to convert a plot drawn with the graphics package to a visually identical plot drawn using grid. This conversion provides access to a variety of grid tools for making customisations and additions to the plot that are not possible with the graphics package. -Roy> On Jul 10, 2015, at 2:09 PM, Rich Shepard <rshepard at appl-ecosys.com> wrote: > > Hadley's ggplot2 book is quite old and a new version is in the works, but > not yet out. I've been using lattice graphics but the knitr package doesn't > support lattice, only basic plots and ggplot2. My Web searches for Trellis > plots in ggplot2 equivalent to those in lattice have not been productive. > > I would appreciate a pointer to a resource that would teach me how to > translate from lattice xyplot() to ggplot2 ggplot(). > > This is one such plot needing translation: > > xyplot(value ~ sampdate | variable, data=carlin.1.melt, rm.na = T) > > Rich > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > 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.********************** "The contents of this message do not reflect any position of the U.S. Government or NOAA." ********************** Roy Mendelssohn Supervisory Operations Research Analyst NOAA/NMFS Environmental Research Division Southwest Fisheries Science Center ***Note new address and phone*** 110 Shaffer Road Santa Cruz, CA 95060 Phone: (831)-420-3666 Fax: (831) 420-3980 e-mail: Roy.Mendelssohn at noaa.gov www: http://www.pfeg.noaa.gov/ "Old age and treachery will overcome youth and skill." "From those who have been given much, much will be expected" "the arc of the moral universe is long, but it bends toward justice" -MLK Jr.
Rich Shepard
2015-Jul-10 21:20 UTC
[R] Trellis Plots: translating lattice xyplot() to ggplot()
On Fri, 10 Jul 2015, Roy Mendelssohn - NOAA Federal wrote:> Don?t know for certain but might this help: > http://journal.r-project.org/archive/2015-1/murrell.pdf > From the latest issue of R Journal.Roy, Thanks. I'll certainly read that article. Carpe weekend, Rich
Rich Shepard
2015-Jul-10 21:38 UTC
[R] Trellis Plots: translating lattice xyplot() to ggplot()
On Fri, 10 Jul 2015, Roy Mendelssohn - NOAA Federal wrote:> Don?t know for certain but might this help:It's very interesting, but does not appear to resolve the immediate need to write the R code in a knitr chunk for incorporation into the compiled LyX document. The gridGraphics package description notes that both lattice and ggplot2 are built on the grid framework, and the new gridGraphics package will 'echo' either to a grid format for further tweaking. Unless the knitr package will accept the echoed image ... It does not. Here is what the compiled document shows (the R code is included in the document): pdf('carlin-1-description.pdf') xyplot(value ~ sampdate | variable, data=carlin.1.melt, rm.na = T) require(gridGraphics) ## Loading required package: gridGraphics ## Loading required package: grid grid.echo() ## Error in grid.echo.recordedplot(recordPlot(), newpage, prefix): No ## graphics to replay dev.off() Rich
Hadley Wickham
2015-Jul-10 21:50 UTC
[R] Trellis Plots: translating lattice xyplot() to ggplot()
Have you tried explicitly print()ing the lattice graphics in your knitr doc? Hadley On Friday, July 10, 2015, Rich Shepard <rshepard at appl-ecosys.com> wrote:> Hadley's ggplot2 book is quite old and a new version is in the works, but > not yet out. I've been using lattice graphics but the knitr package doesn't > support lattice, only basic plots and ggplot2. My Web searches for Trellis > plots in ggplot2 equivalent to those in lattice have not been productive. > > I would appreciate a pointer to a resource that would teach me how to > translate from lattice xyplot() to ggplot2 ggplot(). > > This is one such plot needing translation: > > xyplot(value ~ sampdate | variable, data=carlin.1.melt, rm.na = T) > > Rich > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > 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. >-- http://had.co.nz/ [[alternative HTML version deleted]]
Rich Shepard
2015-Jul-10 21:57 UTC
[R] Trellis Plots: translating lattice xyplot() to ggplot()
On Fri, 10 Jul 2015, Hadley Wickham wrote:> Have you tried explicitly print()ing the lattice graphics in your knitr > doc?Hadley, Only now. Had not thought of trying this before. pdf('carlin-1-descriptive.pdf') print(xyplot(value ~ sampdate | variable, data=carlin.1.melt, rm.na = T)) No error messages, but no graphic, either. Without specifying the pdf device, TeX complains it cannot find a graphics device and lists bit-mapped, ps and svg devices. Most likely I do not have the correct syntax. Thanks, Rich
Jeff Newmiller
2015-Jul-10 21:58 UTC
[R] Trellis Plots: translating lattice xyplot() to ggplot()
I don't actually use lattice very much, but I have no difficulty setting up a lattice plot in a knitr/rmarkdown file, and can think of no reason why you might have concluded that knitr does not support lattice. Sorry, not going to translate your non-reproducible example... please go the extra little effort to dput some example data so we can communicate clearly about your problem. [1] [1] http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example --------------------------------------------------------------------------- Jeff Newmiller The ..... ..... Go Live... DCN:<jdnewmil at dcn.davis.ca.us> Basics: ##.#. ##.#. Live Go... Live: OO#.. Dead: OO#.. Playing Research Engineer (Solar/Batteries O.O#. #.O#. with /Software/Embedded Controllers) .OO#. .OO#. rocks...1k --------------------------------------------------------------------------- Sent from my phone. Please excuse my brevity. On July 10, 2015 2:09:45 PM PDT, Rich Shepard <rshepard at appl-ecosys.com> wrote:>Hadley's ggplot2 book is quite old and a new version is in the works, >but >not yet out. I've been using lattice graphics but the knitr package >doesn't >support lattice, only basic plots and ggplot2. My Web searches for >Trellis >plots in ggplot2 equivalent to those in lattice have not been >productive. > > I would appreciate a pointer to a resource that would teach me how to >translate from lattice xyplot() to ggplot2 ggplot(). > > This is one such plot needing translation: > >xyplot(value ~ sampdate | variable, data=carlin.1.melt, rm.na = T) > >Rich > >______________________________________________ >R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see >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.