[R] How to stamp my graphs with date and time

David Winsemius dwinsemius at comcast.net
Fri Apr 23 17:53:09 CEST 2010


On Apr 23, 2010, at 11:32 AM, Deepayan Sarkar wrote:

> On Wed, Apr 21, 2010 at 4:02 PM, David Winsemius <dwinsemius at comcast.net 
> > wrote:
>>

snipped earlier code
>>>
>>
>> Furthermore when I try:
>>
>> mtext(date(), side=3, line=4, adj=0)
>>
>> .... I get a datetime stamp even though I am mixing graphic  
>> paradigms. This
>> would seem to be one of those instances where you needn't worry about
>> getting the internal coordinates to match up.
>
> Appearances can be deceiving. Try to create a PDF file with this, and
> you will get
>
>> pdf()
>> xyplot(1 ~ 1)
>> mtext(date(), side=1, line=4, adj=0)
> Error in mtext(date(), side = 1, line = 4, adj = 0) :
>  plot.new has not been called yet
>> dev.off()
>
> Try to copy the screen device to PDF, and you will get
>
>> dev.copy(pdf, file = "/tmp/foo.pdf")
> Error in dev.copy(pdf, file = "/tmp/foo.pdf") : invalid graphics state
>
> For a footnote in lattice plots, page is the appropriate argument to
> use. Adapting an example from the book (section 9.3), the following
> will add a timestamp to all subsequent lattice plots:
>
> lattice.options(default.args = list(page = function(n) {
>    panel.text(lab = sprintf("%s", date()), x = 0.99, y = 0.05, adj =  
> 1)
> }))
>
> xyplot(1 ~ 1)

Thank you for that. Correct in all important aspects on my MacOS X  
system as well, when using the default quartz device. My eventual  
modification to your suggestion was:

lattice.options(default.args = list(page = function(n) {
    panel.text(lab = sprintf("%s", date()), x = 0.01, y = 0.01, adj =  
0, srt=90)
}))


... which puts it going upward along the right hand margin, and I like  
it so much that I think I will put it in my .Rprofile preceded of  
course by require(lattice).

>
>
> -Deepayan

David Winsemius, MD
West Hartford, CT



More information about the R-help mailing list