Hi:

David was on the right track...

library(reshape)      # for the melt() function below
rnorm(100,5,3) -> A
rnorm(100,7,3) -> B
rnorm(100,4,1) -> C
df <- melt(data.frame(A, B, C))
names(df)[1] <- 'gp'

histogram(~ value | gp, data=df, layout=c(3,1), nint=50,
   panel=function(x, ..., groups){
       panel.histogram(x, ...)
       panel.abline(v=c(5.5, 6.5, 4.5)[groups = panel.number()],
                    col = 'red', lwd = 2)
})

It took several iterations, but persistence sometimes pays off :)

HTH,
Dennis

On Tue, Oct 12, 2010 at 6:13 PM, David Winsemius <dwinsem...@comcast.net>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()])
>
>  })
>
>>
>> Thanks in advance..
>>
>> A.
>>
>>        [[alternative HTML version deleted]]
>>
>> ______________________________________________
>> R-help@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
>
>
> ______________________________________________
> R-help@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.
>

        [[alternative HTML version deleted]]

______________________________________________
R-help@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.

Reply via email to