[R] Plotting text with lattice

Gabor Grothendieck ggrothendieck at gmail.com
Fri Sep 29 21:18:09 CEST 2006


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")
})

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.
>



More information about the R-help mailing list