ivo welch
2015-Jun-01 21:03 UTC
[R] combine trellis lattice contour plot with simple plot() points() and text() commands?
can I add ordinary graphics commands to a contourplot? my naive attempts are telling me that plot.new() has not yet been called when I try to add text(1,1,"hi") or points( c(0,1), c(1,0) )? [or do I need to rewrite another contourplot with the old graphics system. the basics are probably looking at adjacent points, pretending that they are linear, and mark where a line between them intercepts the level, and then hope that some sanity prevents me from connecting disconnected levels. not my plan...] ---- Ivo Welch (ivo.welch at gmail.com) http://www.ivo-welch.info/
David Winsemius
2015-Jun-02 00:22 UTC
[R] combine trellis lattice contour plot with simple plot() points() and text() commands?
On Jun 1, 2015, at 2:03 PM, ivo welch wrote:> can I add ordinary graphics commands to a contourplot? my naive > attempts are telling me that plot.new() has not yet been called when I > try to add text(1,1,"hi") or points( c(0,1), c(1,0) )?There are lattice equivalents to many of the base primitives. They can be used inside lattice/trellis functions or used later if the plots have been save to names. ?llines ?trellis.focus Also take a look at the lattice Extra and gridBase packages for additional faclities like these. Examples requested for demonstration ... as always but using your earleir example: myplot= contourplot( z ~ x * y, data = d) myplot trellis.focus("panel",1,1) llines(x=3, y=1:5) #draws a blue segment on the screen device NULL trellis.unfocus() But that is not going to change myplot. For that you need ?update.trellis or latticeExtra's version of "+". -- david.> > [or do I need to rewrite another contourplot with the old graphics > system. the basics are probably looking at adjacent points, > pretending that they are linear, and mark where a line between them > intercepts the level, and then hope that some sanity prevents me from > connecting disconnected levels. not my plan...] > > ---- > Ivo Welch (ivo.welch at gmail.com) > http://www.ivo-welch.info/ > > ____David Winsemius Alameda, CA, USA
Jim Lemon
2015-Jun-02 00:24 UTC
[R] combine trellis lattice contour plot with simple plot() points() and text() commands?
Hi Ivo, Not in a sane way. Have a look at the latticeExtra package that allows most of these things to be done. Jim On Tue, Jun 2, 2015 at 7:03 AM, ivo welch <ivo.welch at anderson.ucla.edu> wrote:> can I add ordinary graphics commands to a contourplot? my naive > attempts are telling me that plot.new() has not yet been called when I > try to add text(1,1,"hi") or points( c(0,1), c(1,0) )? > > [or do I need to rewrite another contourplot with the old graphics > system. the basics are probably looking at adjacent points, > pretending that they are linear, and mark where a line between them > intercepts the level, and then hope that some sanity prevents me from > connecting disconnected levels. not my plan...] > > ---- > Ivo Welch (ivo.welch at gmail.com) > http://www.ivo-welch.info/ > > ______________________________________________ > 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.
Duncan Mackay
2015-Jun-02 00:44 UTC
[R] combine trellis lattice contour plot with simple plot() points() and text() commands?
Hi Ivo If you want to add lines, text etc you can do that by a lattice panel function included in it would be panel.contour something like (untested) contourplot(... panel = function(x,y, etc,...){ panel.countorplot(x,y, etc) panel.lines(x,y,...) panel.text(....) } ) and see also library(lattice) names(trellis.par.get()) and delve into the names that come up that are applicable See the help page ? panel.lines which should cover most of what you need. Remember that you may have to look at ? grid::gpar for fine tuning of the arguments Just finished a plot with panel.segments panel.segments(xlocs - medsbar.len, meds, xlocs + medsbar.len, meds, lineend = 1, # grid gpar call for line ending lwd = 5, col = 2) Duncan Duncan Mackay Department of Agronomy and Soil Science University of New England Armidale NSW 2351 Email: home: mackay at northnet.com.au -----Original Message----- From: R-help [mailto:r-help-bounces at r-project.org] On Behalf Of ivo welch Sent: Tuesday, 2 June 2015 07:03 To: r-help Subject: [R] combine trellis lattice contour plot with simple plot() points() and text() commands? can I add ordinary graphics commands to a contourplot? my naive attempts are telling me that plot.new() has not yet been called when I try to add text(1,1,"hi") or points( c(0,1), c(1,0) )? [or do I need to rewrite another contourplot with the old graphics system. the basics are probably looking at adjacent points, pretending that they are linear, and mark where a line between them intercepts the level, and then hope that some sanity prevents me from connecting disconnected levels. not my plan...] ---- Ivo Welch (ivo.welch at gmail.com) http://www.ivo-welch.info/ ______________________________________________ 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.