Skip to content
Back to formatted view

Raw Message

Message-ID: <CAEhWdG7D9nGW81p+Z8yGppX8exrQgsJe045Krvo-YCoi9kV5+A@mail.gmail.com>
Date: 2011-10-16T13:50:05Z
From: Weidong Gu
Subject: grouped lattice plot with overall regression line
In-Reply-To: <fd882811ba8adb293b9d03940ff1eaf6@tweb15-2.nm>

If  you want to draw the global regression line in each panel, you can try

xyplot(T~A|speaker,data=spk0,layout=c(4,5),type='p',groups=fns),
panel=function(x,y,...){
panel.xyplot(x,y,...)
panel.abline(lm(y~x,data=spk0))})

Weidong Gu

2011/10/16 ??? <feb211 at naver.com>:
> I'd like to draw a lattice plot with groups. The groups (the grouping condition, fns) are successfully marked with separate symbols, using the following code:
> xyplot(T~A|speaker,groups=fns,pch=1:3,key=list(space="right",points=list(pch=1:3)),type=c("g","p","r"))
> Here's a hard part. This draws regression lines for each group in each panel (there are three groups, so three regression lines show up in each panel). But I want to have only one global regression line for all groups together, still maintaining separate symbols for each group.
> I don't want to have individual regression lines for each group.
> I tried many things, with various panel functions, but I've never succeeded. Could any expert help with this? I'd appreciate it greatly. The closest I could find was something like the following, which didn't work for me - anyways, it is supposed to draw by-group regression lines as well as the global one. So this is not exactly I need.
> xyplot(T~A|speaker,data=spk0,layout=c(4,5),type='p',groups=fns),
> panel=function(x,y){
> ?panel.superpose(x,y)
> ?panel.abline(lm(y~x))}),
> panel.groups=function(x,y,lty){
> ?panel.xyplot(x,y,lty=lty)
> ?panel.abline(lm(y~x),lty=3)})
> Thanks so much !!!
>
> ? ? ? ?[[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.
>