[R] Lattice: arbitrary abline in multiple histograms

David Winsemius dwinsemius at comcast.net
Wed Oct 13 04:08:21 CEST 2010


On Oct 12, 2010, at 9:13 PM, David Winsemius wrote:

>
> On Oct 12, 2010, at 8:21 PM, Alejo C.S. wrote:
>
>> Dear list.
>>
>> I have three histograms and I want to add a vertical abline in a  
>> different
>> place in each plot. The next example will plot a vertical line at  
>> x=5.5 in
>> the three plots:
>>
>> rnorm(100,5,3) -> A
>> rnorm(100,7,3) -> B
>> rnorm(100,4,1) -> C
>> rep(c("A","B","C"),each=100) -> grp
>> data.frame(G=grp,D=c(A,B,C)) -> data
>> histogram(~ D | G, data=data, layout=c(3,1), nint=50,  
>> panel=function(x,...){
>> panel.histogram(x,...)
>> panel.abline(v=5.5)
>> })
>> But I'd like to plot a vertical line at 5.5 in plot A, 6.5 in plot  
>> B and
>> 4.5 in plot C. How can I do that?
>
> histogram(~ D | G, data=data, layout=c(3,1), nint=50,  
> panel=function(x,subscripts,groups,...){
> panel.histogram(x , ...)
> panel.abline(v=c(5.5, 6.5, 4.5)[packet.number()])
> })

I may have "rushed that into production." The subscripts and groups  
argument to panel are not needed, and are only the remnants of failed  
experiments.


>>
>> Thanks in advance..
>>
>> A.
>


David Winsemius, MD
West Hartford, CT



More information about the R-help mailing list