change fitted line colour in nlme() trellis plot?

779 views Asked by At

I am trying to use a grouped data to fit and then plot plot(augPred(fit)). However, I would like to change the line color as it is the similar color of the points. Is there a way to make the lines in a different color? Also, I would like to remove the data points in the plot, just leaving the two fitted lines so it would be easy to compare them. In the figure attached, I would like to remove data points and change the fitted lines color.

Thanks very much for any help. Ravienter image description here

1

There are 1 answers

4
aosmith On

The plot.augPred function in nlme is based on xyplot in the lattice package(see the help page for plot.augPred for more info), so you would have to delve into that package a bit more to see what you can add to change the plot. There is a fair amount of info out there once you start looking, see this link and the help page of xyplot and panel.xyplot as possible starting places.

If it was me and I wanted to make a bunch of changes to the defaults, I'd probably just use the output from the augPred object and create a plot from scratch. But you can certainly control the plot settings via the par.settings argument from xyplot.

Here is an example, using the plot.augPred help page example. Consider including a reproducible example in the future.

library(nlme)
fm1 <- lme(Orthodont)
plot(augPred(fm1, level = 0:1, length.out = 2))

enter image description here

You can control colors line widths with superpose.line and plot.symbol to control the symbols. If you want to get rid of the symbols all together you can set pch to NA.

plot(augPred(fm1, length.out = 2, level = c(0,1)),
    par.settings = list(superpose.line = list(col = c("red", "blue"), lwd = 2),
                    plot.symbol = list(pch = NA)))

enter image description here

Notice this failed to change the legend output, though, and so still needs some work.