Skip to content
Back to formatted view

Raw Message

Message-ID: <a394a9181001081738l7ddd11beyef46f34dc2ba18fc@mail.gmail.com>
Date: 2010-01-09T01:38:01Z
From: Ivan Gregoretti
Subject: lattice, add text to xyplot
In-Reply-To: <DFA38429-06D7-4F2C-B225-E11186A5986F@comcast.net>

Thank you. It works.

Ivan

Ivan Gregoretti, PhD
National Institute of Diabetes and Digestive and Kidney Diseases
National Institutes of Health
5 Memorial Dr, Building 5, Room 205.
Bethesda, MD 20892. USA.



On Fri, Jan 8, 2010 at 8:13 PM, David Winsemius <dwinsemius at comcast.net> wrote:
>
> On Jan 8, 2010, at 8:10 PM, Jason Morgan wrote:
>
>> On 2010.01.08 19:44:39, Ivan Gregoretti wrote:
>>>
>>> Hello listers,
>>>
>>> Does anybody know how to add text to an xyplot without whipping out
>>> the existing curve?
>>> That's all.
>>>
>>> For instance,
>>>
>>> Lets say you generate a graph like this
>>>
>>> A <- data.frame(x = rnorm(100), y = rnorm(100))
>>> xyplot(y ~ x, data = A)
>>>
>>> How would you add 'Hello world'?
>>>
>>> I tried 6.02E23 different partial solutions found on the web and
>>> failed. I just need one EXAMPLE that WORKS.
>>>
>>> Unfortunately,
>>>
>>> library(lattice)
>>> ?panel.text
>>>
>>> shows no examples.
>>>
>>> As you see, I bring you a formidable challenge.
>>
>> A <- data.frame(x = rnorm(100), y = rnorm(100))
>> xyplot(y ~ x, data = A,
>> ? ? ?panel = function(...) {
>> ? ? ? ?panel.text(0, 0, "Hello world!")
>> ? ? ? ?panel.xyplot(...)
>> ? ? ?})
>
> Or, following a Sarkar r-helpful example on how to add to an existing plot:
>
> ?library(lattice)
> ?A <- data.frame(x = rnorm(100), y = rnorm(100))
> ?xyplot(y ~ x, data = A)
> ?trellis.focus("toplevel") ## has coordinate system [0,1] x [0,1]
> ?panel.text(0.5, 0.2, "Hello, world", cex = 1.2, font = 2)
> ?trellis.unfocus()
>
> --
> David
>>
>> A whole lot of examples lattice are available here:
>>
>> http://lmdvr.r-forge.r-project.org/figures/figures.html
>>
>> If you plan on using lattice often, I highly recommend Deepayan Sarkar's
>> book.
>>
>> Hope that helps,
>> ~Jason
>>
>>>
>>> Thank you,
>>>
>>> Ivan
>>>
>
> David Winsemius, MD
> Heritage Laboratories
> West Hartford, CT
>
>