[R] Plotting text with lattice
Deepayan Sarkar
deepayan.sarkar at gmail.com
Fri Sep 29 22:13:20 CEST 2006
On 9/29/06, Gabor Grothendieck <ggrothendieck at 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 at 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 at geodecapital.com
> >
> >
> >
> > This e-mail, and any attachments hereto, are intended for us...{{dropped}}
> >
> > ______________________________________________
> > R-help at 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 at 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/
More information about the R-help
mailing list