Re: [R] Plotting text with lattice

From: Gabor Grothendieck <ggrothendieck_at_gmail.com>
Date: Thu 05 Oct 2006 - 15:02:48 GMT

This requires R 2.4.0. Its the same as my earlier example except the labels= arg has been changed to labels=which.packet().

xyplot(x ~ x | g, data = data.frame(x = 1:12), panel = function(...) {

       panel.xyplot(...)
       panel.text(x=2, y=4, labels=which.packet())

})

On 10/5/06, Ritwik Sinha <ritwik.sinha@gmail.com> wrote:
> Hi,
>
> On a related note, if I wanted to add different texts to different
> panels, should I stick to using trellis.focus() for each text in each
> panel? I cannot figure out a way to do it using a panel function.
>
> Ritwik.
>
> On 9/29/06, Deepayan Sarkar <deepayan.sarkar@gmail.com> wrote:
> > On 9/29/06, Gabor Grothendieck <ggrothendieck@gmail.com> wrote:
> > > Here are two possibilities. The first use trellis.focus/trellis/unfocus to
> > > add text subsequent to drawing the xyplot and the second uses a
> > > custom panel:
> > >
> > > xyplot(x ~ x, data = data.frame(x = 1:10))
> > > trellis.focus("panel", 1, 1)
> > > panel.text(x=2, y=4, labels="Text")
> > > trellis.unfocus()
> > >
> > > xyplot(x ~ x, data = data.frame(x = 1:10), panel = function(...) {
> > > panel.xyplot(...)
> > > panel.text(x=2, y=4, labels="Text")
> > > })
> >
> > Right, on a more general note, this is necessary because it is not clear what
> >
> > ltext(x=2, y=4, labels="Text")
> >
> > should do for a multi-panel plot. On an even more general note, you
> > will keep getting in trouble when using lattice if you (1) try to
> > follow the "incremental addition" approach of standard graphics or (2)
> > use the par() system in any way.
> >
> > Deepayan
> >
> > > On 9/29/06, McGehee, Robert <Robert.McGehee@geodecapital.com> wrote:
> > > > Hello,
> > > > I've decided to take the leap and try my hand at the lattice package,
> > > > though I am getting stuck at what one might consider a trivial problem,
> > > > plotting text at a point in a graph. Apologies in advance if (that) I'm
> > > > missing something extremely basic.
> > > >
> > > > Consider in base graphics:
> > > > > plot(1:10)
> > > > > text(2, 4, "Text")
> > > > In the above you will see text centered at the point (2, 4) on the
> > > > graph.
> > > >
> > > > Now I would like to try to do the same thing using the lattice package:
> > > >
> > > > > xyplot(x ~ x, data = data.frame(x = 1:10))
> > > > > ltext(x=2, y=4, labels="Text")
> > > > > panel.text(x=2, y=4, labels="Text")
> > > > > grid.text(label="Text", x=2, y=4)
> > > > > grid.text(label="Text", x=unit(2, "native"), y=unit(4, "native"))
> > > >
> > > > None of the above four commands puts the "Text" at the (2, 4) point on
> > > > the graph. Any help with this would be appreciated! Also, if I have more
> > > > than one panel and would like to place text at different points on
> > > > different panels how would I do this?
> > > >
> > > > Also, note that I'm hoping to use text to label interesting points in a
> > > > levelplot, but am using the above xyplot as an example.
> > > >
> > > > Thanks,
> > > > Robert
> > > >
> > > >
> > > > Robert McGehee
> > > > Quantitative Analyst
> > > > Geode Capital Management, LLC
> > > > 53 State Street, 5th Floor | Boston, MA | 02109
> > > > Tel: 617/392-8396 Fax:617/476-6389
> > > > mailto:robert.mcgehee@geodecapital.com
> > > >
> > > >
> > > >
> > > > This e-mail, and any attachments hereto, are intended for us...{{dropped}}
> > > >
> > > > ______________________________________________
> > > > R-help@stat.math.ethz.ch 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@stat.math.ethz.ch 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.
> > >
> >
> >
> > --
> > http://www.stat.wisc.edu/~deepayan/
> >
> > ______________________________________________
> > R-help@stat.math.ethz.ch 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.
> >
>
>
> --
> Ritwik Sinha
> Graduate Student
> Epidemiology and Biostatistics
> Case Western Reserve University
> ritwik.sinha_at_gmail.com | +12163682366 | http://darwin.cwru.edu/~rsinha
>
> ______________________________________________
> R-help@stat.math.ethz.ch 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@stat.math.ethz.ch 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 Fri Oct 06 01:18:21 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Thu 05 Oct 2006 - 18:30:08 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.