[R] Separate ablines in lattice panels

David Winsemius dwinsemius at comcast.net
Tue Jan 17 19:46:14 CET 2012


On Jan 17, 2012, at 1:34 PM, Doran, Harold wrote:

> Thank you, Bert. The help page doesn't have a usage example and I  
> can't seem to find one via google. Do you, or anyone else, have  
> sample code?
>
It did not seem particularly daring or complex when I tried this  
(which does appear to produce what was requested):

tmp <- data.frame(var1 = c(rnorm(1000), rnorm(1000, 1, 1)), var2 = gl(2,
1000))

densityplot(~ var1|var2, tmp,
                              type = c('g', 'l'),
                              layout = c(1,2),
                                             panel = function(x, ...){
                                             panel.densityplot(x, ...)
                                             panel.abline(v = c(0,1) 
[ panel.number() ])
                                             }
             )

-- 
David.

>> -----Original Message-----
>> From: Bert Gunter [mailto:gunter.berton at gene.com]
>> Sent: Tuesday, January 17, 2012 1:07 PM
>> To: Doran, Harold
>> Cc: r-help at r-project.org
>> Subject: Re: [R] Separate ablines in lattice panels
>>
>> ?panel.number
>>
>> This tells you what panel you're in and you can use that to determine
>> which line to draw.
>>
>> -- Bert
>>
>> On Tue, Jan 17, 2012 at 9:59 AM, Doran, Harold <HDoran at air.org>  
>> wrote:
>>> Searched archives and found some old email threads on the topic.  
>>> But mot
>> exactly what I think I need. Suppose I have a datafile such as tmp.
>>>
>>> tmp <- data.frame(var1 = c(rnorm(1000), rnorm(1000, 1, 1)), var2 =  
>>> gl(2,
>> 1000))
>>>
>>> I'd like a plot similar to the one below, but with an abline of  
>>> v=0 in the
>> lower panel and v=1 in the upper panel. Code below creates two  
>> lines in each
>> panel, not quite sure how to separate them by panel.
>>>
>>> densityplot(~ var1|var2, tmp,
>>>                              type = c('g', 'l'),
>>>                              layout = c(1,2),
>>>                                             panel =  
>>> function(x, ...){
>>>                                              
>>> panel.densityplot(x, ...)
>>>                                             panel.abline(v = c(0,1))
>>>                                             }
>>> )
>>>
>>> Thank you
>>> Harold
>>>
>>>        [[alternative HTML version deleted]]
>>>
>>> ______________________________________________
>>> R-help at r-project.org 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.
>>
>>
>>
>> --
>>
>> Bert Gunter
>> Genentech Nonclinical Biostatistics
>>
>> Internal Contact Info:
>> Phone: 467-7374
>> Website:
>> http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-
>> biostatistics/pdb-ncb-home.htm
>
> ______________________________________________
> R-help at r-project.org 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.

David Winsemius, MD
West Hartford, CT



More information about the R-help mailing list