Re: [R] Trellis Plots: translating lattice xyplot() to ggplot()
On Fri, 10 Jul 2015, Yihui Xie wrote: Your LyX example has two problems: 1) We don't have your .RData; 2) You didn't library(reshape) and library(lattice). Hence it is not a self-contained reproducible example. Yihui, I assumed that reading in the *.csv file would create a local .RData file. Here, lattice and reshape2 are loaded when R is invoked. However, explicitly loading them in the embedded code will be done. After fixing these two issues, I don't see why lattice graphics can be problematic with knitr. There is no need to print() the plot, and no need to pdf(), either. See the attached PDF I generated. I'll see if requireing those two libraries in the document resolves the issue. Initially, I did not specify pdf() and added the explicit print() based on that suggestion in this thread. Will test later today. Thanks very much, Rich __ R-help@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.
Re: [R] Trellis Plots: translating lattice xyplot() to ggplot() [RESOLVED]
On Fri, 10 Jul 2015, Yihui Xie wrote: Your LyX example has two problems: Yihui, et al.: All fixed now. After adding the specific libraries the chuck calling xyplot() to produce the graphic caused an error when I tried to generate a dvips preview: LaTeX Error: File 'figure/unnamed-chunk-7-1' not found. I could not locate the file with any of these extensions: .eps,.ps,.eps.gz,.ps.gz,.eps.Z Which is what sent me down the path of specifying pdf() and dev.off(). However, compiling with pdflatex produces the graphic in the document. All part of being brand new to using knitr. Thank you all very much, Rich __ R-help@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.
Re: [R] Trellis Plots: translating lattice xyplot() to ggplot() [RESOLVED]
I guess you didn't tell us you were compiling the document with dvips (BTW, I'm surprised that dvips is still alive today...), otherwise the solution would be simply to use the postscript device instead of the default pdf device (i.e. use the chunk option dev='postscript'). Hopefully you learned some lessons on what a reproducible example means. Regards, Yihui -- Yihui Xie xieyi...@gmail.com Web: http://yihui.name On Sat, Jul 11, 2015 at 9:03 AM, Rich Shepard rshep...@appl-ecosys.com wrote: On Fri, 10 Jul 2015, Yihui Xie wrote: Your LyX example has two problems: Yihui, et al.: All fixed now. After adding the specific libraries the chuck calling xyplot() to produce the graphic caused an error when I tried to generate a dvips preview: LaTeX Error: File 'figure/unnamed-chunk-7-1' not found. I could not locate the file with any of these extensions: .eps,.ps,.eps.gz,.ps.gz,.eps.Z Which is what sent me down the path of specifying pdf() and dev.off(). However, compiling with pdflatex produces the graphic in the document. All part of being brand new to using knitr. Thank you all very much, Rich __ R-help@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.
Re: [R] Trellis Plots: translating lattice xyplot() to ggplot()
On Fri, 10 Jul 2015, David Winsemius wrote: #Generally one needs to complete a pdf() call with: dev.off() # And an empty file is the symptom os such a failure. David, I did leave that off the example file, but it make no difference. The attached is the compiled example.pdf Rich example.pdf Description: Adobe PDF document __ R-help@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.
Re: [R] Trellis Plots: translating lattice xyplot() to ggplot()
Your LyX example has two problems: 1) We don't have your .RData; 2) You didn't library(reshape) and library(lattice). Hence it is not a self-contained reproducible example. After fixing these two issues, I don't see why lattice graphics can be problematic with knitr. There is no need to print() the plot, and no need to pdf(), either. See the attached PDF I generated. Regards, Yihui -- Yihui Xie xieyi...@gmail.com Web: http://yihui.name On Fri, Jul 10, 2015 at 7:18 PM, Rich Shepard rshep...@appl-ecosys.com wrote: On Fri, 10 Jul 2015, David Winsemius wrote: #Generally one needs to complete a pdf() call with: dev.off() # And an empty file is the symptom os such a failure. David, I did leave that off the example file, but it make no difference. The attached is the compiled example.pdf Rich __ R-help@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. example.pdf Description: Adobe PDF document __ R-help@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.
Re: [R] Trellis Plots: translating lattice xyplot() to ggplot()
On Jul 10, 2015, at 2:57 PM, Rich Shepard wrote: 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)) #Generally one needs to complete a pdf() call with: dev.off() # And an empty file is the symptom os such a failure. David. 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 __ R-help@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. David Winsemius Alameda, CA, USA __ R-help@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.
Re: [R] Trellis Plots: translating lattice xyplot() to ggplot()
I'd recommend starting with a simpler .Rmd or .Rnw file, rather than using it with lyx. The basic .Rmd file below works for me without any further adjustments: # Lattice test ```{r} library(lattice) xyplot(mpg ~ wt, data = mtcars) ``` Hadley On Fri, Jul 10, 2015 at 3:39 PM, Rich Shepard rshep...@appl-ecosys.com wrote: On Fri, 10 Jul 2015, Hadley Wickham wrote: You shouldn't be explicitly opening a device in a knitr document. Hadley, Didn't think so. I think maybe you should post a minimal document so we can figure out what's going wrong. Agreed. Attached are the raw data (carlin.csv) and a stripped down LyX document with the knitr chunks. This is my first attempt to use knitr; I'm reading the knitr book and that's where I got the impression that lattice graphics are not supported. Rich __ R-help@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/ __ R-help@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.
Re: [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 __ R-help@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.
Re: [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 rshep...@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@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]] __ R-help@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.
Re: [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 __ R-help@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.
Re: [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 NewmillerThe . . Go Live... DCN:jdnew...@dcn.davis.ca.usBasics: ##.#. ##.#. Live Go... Live: OO#.. Dead: OO#.. Playing Research Engineer (Solar/BatteriesO.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 rshep...@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@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. __ R-help@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.
Re: [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 rshep...@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@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.mendelss...@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. __ R-help@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.
Re: [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 __ R-help@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.
Re: [R] Trellis Plots: translating lattice xyplot() to ggplot()
You shouldn't be explicitly opening a device in a knitr document. I think maybe you should post a minimal document so we can figure out what's going wrong. Hadley On Friday, July 10, 2015, Rich Shepard rshep...@appl-ecosys.com wrote: 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 __ R-help@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]] __ R-help@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.
Re: [R] Trellis Plots: translating lattice xyplot() to ggplot()
On Fri, 10 Jul 2015, Hadley Wickham wrote: You shouldn't be explicitly opening a device in a knitr document. Hadley, Didn't think so. I think maybe you should post a minimal document so we can figure out what's going wrong. Agreed. Attached are the raw data (carlin.csv) and a stripped down LyX document with the knitr chunks. This is my first attempt to use knitr; I'm reading the knitr book and that's where I got the impression that lattice graphics are not supported. Richsiteid,sampdate,Temp.h2o,Temp.air,Disc.cfs,Turb,SC,DO,pH,ANC,HCO3,CO3,Alk,Hard,TDS,TSS,N.tot,N.org,NH4,NO3,NO2,PO4,C,Ca,Mg,Na,K,Cl,SO4,F,Si,As,Ba,Be,Cd,Cr,Co,Cu,Fe,Pb,Mn,Mo,Ni,Ag,Sr,V,Zi,Al,Li,Se,CN,Hg 10321000,1965-10-01,,,98,,490,,8.4,,238,4,,150,,40,12,46,, 10321000,1965-11-01,,,141,,507,,8.3,213,252,4,,170,,50,11,42,, 10321000,1965-12-01,,,128,,564,,8.1,238,290,0,,190,359,56,13,47,6.4,16,37,0.5,40, 10321000,1966-01-01,,,122,,506,,8.2,212,259,0,,170,321,50,11,45,6.1,16,34,0.6,31, 10321000,1966-01-17,,,97,,551,,8.5,241,276,9,,200,,58,13,48,, 10321000,1966-02-01,,,108,,506,,8.2,216,263,0,,180,,52,11,42,, 10321000,1966-03-01,,,384,,516,,7.7,201,245,0,,160,,46,11,46,8, 10321000,1966-03-18,,,701,,628,,8.1,235,286,0,,190,,51,16,61,8.5, 10321000,1966-04-01,,,612,,470,,8,189,231,0,,160,301,43,12,40,6.3,14,37,0.5,34, 10321000,1966-04-11,,,541,,423,,8,172,210,0,,140,,40,10,34,5.4, 10321000,1966-04-18,,,355,,466,,8.1,193,235,0,,160,,43,12,39,5.9, 10321000,1966-05-01,,,167,,498,,8,208,253,0,,170,,46,13,42,6.8, 10321000,1966-05-06,,,260,,420,,8.1,181,221,0,,140,,41,10,33,5.4, 10321000,1966-07-01,,,7,,566,,8,226,275,0,,180,450,47,16,52,96,21,48,0.6,34, 10321000,1966-08-01,,,3.9,,550,,8.1,210,256,0,,170,,40,17,51,9.7, 10321000,1966-09-01,,,4.1,,536,,8.4,208,254,0,,170,,41,17,48,8.9, 10321000,1966-10-01,,,7.7,,546,,8.4,220,260,4,,190,340,48,16,46,8.5,19,43,0.5,27, 10321000,1966-11-01,,,16,,536,,8.4,224,263,5,,180,,49,15,45,7.6, 10321000,1966-12-01,,,31,,533,,8.6,222,248,11,,180,336,50,13,47,7.5,14,37,0.5,34, 10321000,1966-12-16,,,30,,615,,8.6,264,296,13,,210,,60,14,56,8.7, 10321000,1967-01-01,,,43,,517,,8.8,214,228,16,,170,333,50,12,48,7.3,19,40,0.5,28, 10321000,1967-02-01,,,72,,513,,8.7,217,234,15,,180,,51,12,46,6.9, 10321000,1967-02-12,,,113,,474,,8.3,189,230,3,,160,,46,11,41,6.8, 10321000,1967-03-01,,,232,,464,,8.5,174,212,7,,150,,44,10,41,6.6, 10321000,1967-03-25,,,422,,498,,8.5,179,218,6,,160,,48,10,43,6.5, 10321000,1967-04-01,,,333,,448,,8.5,164,200,5,,150,283,42,11,39,5.7,15,40,0.5,26, 10321000,1967-05-01,,,327,,451,,8.5,165,201,6,,150,,43,10,38,5.8, 10321000,1967-05-10,,,406,,371,,8.3,127,155,2,,110,,29,9.5,34,5.7, 10321000,1967-05-14,,,396,,435,,8.3,158,193,2,,160,,45,11,38,6.7, 10321000,1967-05-20,,,844,,365,,8,147,179,0,,150,,45,8.1,25,5.6, 10321000,1967-06-01,,,1560,,443,,8.4,189,230,4,,180,,55,10,35,6.7, 10321000,1967-07-01,,,1340,,386,,8.5,175,213,13,,150,255,47,8.6,27,4.8,7.4,14,0.5,28, 10321000,1967-07-11,,,651,,406,,8.3,187,228,2,,170,,55,9.1,27,5, 10321000,1967-07-21,,,254,,453,,8.2,207,252,0,,190,,58,10,35,6, 10321000,1967-08-01,,,48,,, 10321000,1967-08-01,,,48,,525,,8.2,223,272,0,,190,,53,13,47,7.4, 10321000,1967-09-01,,,18,,508,,8.1,210,256,0,,180,,46,15,45,7.9, 10321000,1967-10-01,,,20,,556,,8.4,221,255,7,,180,322,47,15,45,8.2,16,32,0.6,24, 10321000,1967-10-01,,,7.7,,546,,8.4,213,260,4,,190,340,0.0248,16,46,8.5,19,43,0.5,27, 10321000,1967-10-09,,,27,,612,,8.4,242,281,7,,190,,53,15,57,11, 10321000,1967-10-17,,,23,,586,,8.2,238,290,0,,190,,53,15,49,8.3, 10321000,1967-11-01,,,36,,582,,8.4,238,278,6,,190,,55,14,50,7.8, 10321000,1967-12-01,,,44,,565,,8.2,239,292,0,,170,,50,12,53,8.2,