Re: [R] abline and plot(augPred) help

From: Gabor Grothendieck <ggrothendieck_at_gmail.com>
Date: Mon 04 Sep 2006 - 20:37:00 GMT

On 9/4/06, Paul Murrell <p.murrell@auckland.ac.nz> wrote:
> Hi
>
>
> Petr Pikal wrote:
> > Dear all
> >
> > as I did not get any response on my post about abline and
> > plot(augPred)) I try again. I hope I do not break some posting guide
> > rules. I would try to contact package maintainer directly but there
> > is stated to be R-core people, so I feel R-help list shall be OK.
> >
> > I need to draw straight lines through augPred plotted panels
> > (vertical or horizontal) at specified point. I know I shall probably
> > use panel.abline but I am missing correct syntax. Below you can see
> > my attempts together with results. I hope somebody can point me to
> > right direction.
> >
> > I am probably somewhere close but I have no clue, which parameter I
> > shall modify to get measured points, fitted lines and vertical lines
> > in panels together.
>
>
> The problem is that you do not know about the default panel function
> that nlme:::plot.augPred() uses, so your panel functions are not
> replicating all of the default behaviour as well as adding your vertical
> lines. Some possible solutons suggested below ...
>
>
> > fm1 <- lme(Orthodont)
> >
> > # standard plot
> > plot(augPred(fm1, level = 0:1, length.out = 2))
> >
> > #plot with vertical but without points and fitted lines
> > plot(augPred(fm1, level = 0:1, length.out = 2),
> > panel=function(v,...) {
> > panel.abline(v=10)}
> > )
> >
> > # plot with vertical but without fitted lines
> > plot(augPred(fm1, level = 0:1, length.out=2),
> > panel=function(x,y,...) {
> > panel.xyplot(x,y,...)
> > panel.abline(v=10)}
> > )
> >
> > # plot with vertical and with all points (fitted lines are drawn as
> > points)
> > plot(augPred(fm1, level = 0:1),
> > panel=function(x,y,...) {
> > panel.xyplot(x,y,...)
> > panel.abline(v=10)}
> > )
>
> One option is to take a sneak a peek at nlme:::plot.augPred() to see
> what the default panel function is doing. Here I have replicated the
> default panel function and added a call to panel.abline().
>
> plot(augPred(fm1, level = 0:1, length.out = 2),
> panel=function(x, y, subscripts, groups, ...) {
> orig <- groups[subscripts] == "original"
> panel.xyplot(x[orig], y[orig], ...)
> panel.superpose(x[!orig], y[!orig], subscripts[!orig],
> groups, ..., type = "l")
> panel.abline(v=10)
> })
>
> The problem with this approach is that you need to crawl around in the
> code of nlme:::plot.augPred(). An alternative approach is to annotate
> the plot after-the-fact. This is shown below.
>
> plot(augPred(fm1, level = 0:1, length.out = 2))
> for (i in 1:5) {
> for (j in 1:6) {
> if (i < 5 || j < 4) {
> trellis.focus("panel", j, i, highlight=FALSE)
> panel.abline(v=10)
> }
> }
> }
>
> This avoids crawling around in code, but the problem with this is
> knowing how many rows and columns of panels there are. If you
> explicitly controlled the 'layout' of the original plot, you could
> guarantee that your annotation works properly.
>

You can find that out with trellis.currentLayout:

tcL <- trellis.currentLayout()
for(i in 1:nrow(tcL))
  for(j in 1:ncol(tcL))
    if (tcL[i,j] > 0) {

        trellis.focus("panel", j, i, highlight = FALSE)
        panel.abline(v = 10)
        trellis.unfocus()

    }

R-help@stat.math.ethz.ch 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. Received on Tue Sep 05 06:40:00 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Thu 07 Sep 2006 - 07:51:18 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.