[R] Add annotation text outside of an xyplot (lattice package)

Richard M. Heiberger rmh at temple.edu
Sun Sep 25 20:44:25 CEST 2016


library(lattice)
library(latticeExtra)
tmp <- data.frame(x=1:10, y=1:10)

xyplot(y ~ x, data=tmp)

xyplot(y ~ x, data=tmp, main="text outside panel clipped") +
  ## "+" must be on same line as first statement.
  ## This use of "+" is from latticeExtra.
  latticeExtra::layer(panel.text(x=2, y=-0.5, label="very interesting"))

xyplot(y ~ x, data=tmp, main="outside text displayed",
       par.settings=list(clip=list(panel=FALSE)) ## permit text
outside the panel
                         ) +
  ## "+" must be on same line as first statement.
  ## This use of "+" is from latticeExtra.
  latticeExtra::layer(panel.text(x=2, y=-0.5, label="very interesting"))

## I use the phrasing "latticeExtra::layer", not the simpler "layer".
## latticeExtra and ggplot2 both use layer and they use it incompatibly.
## It is possible for both packages to be loaded at the same time, therefore
## I specify latticeExtra explicitly.

## ltext and panel.text are the same.


On Sun, Sep 25, 2016 at 12:32 PM, Jun Shen <jun.shen.ut at gmail.com> wrote:
> Thanks Bert, sub works pretty well.
>
> Carlos, thanks for the suggestion. As I am not familiar with latticeExatra,
> not sure how hard it is to make it work with my plot. I'll try.
>
> On Sat, Sep 24, 2016 at 11:04 AM, Bert Gunter <bgunter.4567 at gmail.com>
> wrote:
>
>> No.
>>
>> ltext/panel.text plots text *within* panels; IIUC, the  OP requested
>> text outside the plots. For that see the details for "main" and/or
>> "sub" in ?xyplot. I think it could also be done more flexibly via a
>> legend or a key with a title but no content -- again, see the Help
>> page -- but haven't tried it.
>>
>> Cheers,
>> Bert
>>
>>
>> Bert Gunter
>>
>> "The trouble with having an open mind is that people keep coming along
>> and sticking things into it."
>> -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )
>>
>>
>> On Fri, Sep 23, 2016 at 11:49 PM, Rainer Hurling <rhurlin at gwdg.de> wrote:
>> > Hi,
>> >
>> > one possible solution is to use ltext().
>> >
>> > ltext(xcoord, ycoord, label="TEST", adj=c(0.5,0.5))
>> >
>> > You have to know or to find out best fitting coordinates.
>> >
>> > Via adj you can control, if the text should adjust left, center or right
>> > to the coords, and above, center or bottom of them.
>> >
>> > HTH,
>> > Rainer Hurling
>> >
>> >
>> > Am 22.09.2016 um 16:04 schrieb Jun Shen:
>> >> Dear list,
>> >>
>> >> Just wonder if there is a way to add annotation text outside an xyplot,
>> >> (e.g. the bottom of the plot). the panel.text seems only add text within
>> >> the plot. Thanks.
>> >>
>> >> Jun
>> >
>> > ______________________________________________
>> > 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.
>>
>
>         [[alternative HTML version deleted]]
>
> ______________________________________________
> 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.



More information about the R-help mailing list