Description Usage Arguments Value Examples
Convenient function for adding curves to an existing plot, or to plot the data with the fitted curve.
For non-linear regression plotting (plot_nls
), works for simple non-linear regression models fit with nls
, grouped non-linear regression (with nlsList
), and non-linear quantile regression fit with nlrq
from the quantreg package.
When plotting an nlsList
object, plot_nls
plots the fitted curve for each of the groups specified in the model, and sets colours with lines.col
and points.col
arguments.
For local regression models fitted with loess
, use the plot_loess
function, which additionally adds a confidence interval around the fitted curve (unless band=FALSE
).
1 2 3 4 5 6 |
object |
The object returned by |
col |
Colour to be used for the data symbols and the fitted line, unless |
band |
For |
plotdata |
Logical. Whether to add the data points to the plot. |
extrapolate |
Logical (default FALSE). If TRUE, extends the fitted curve beyond the data, based on the x-axis limits specified. |
lines.col |
Colour(s) for the fitted lines. When plotting a |
points.col |
Colour(s) for the data symbols. When plotting a |
ci.col |
Colour of the confidence band, if plotted. Defaults to a transparent grey colour. |
lwd |
Thickness of the line (see |
lty |
Line type (see |
add |
Logical. Whether to add to current plot (default FALSE). |
xlab |
Label for x-axis |
ylab |
Label for y-axis |
coverage |
If confidence band to be plotted, the coverage (e.g. for 95% confidence interval, use 0.95) |
xlim |
X-axis limits (optional). |
... |
Further arguments passed to |
Returns the predicted values used in plotting (invisibly), as a dataframe with columns 'predvar' (regularly spaced predictor values), and 'fit' (fitted values). For plot_loess
also returns confidence intervals, standard error, and df of the residual.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | # Plot an nls object
chick <- as.data.frame(ChickWeight)
fit0 <- nls(weight ~ a*Time^b, data=chick, start=list(a=10, b=1.1))
plot_nls(fit0)
# Plot a grouped nls object
library(nlme)
fit1 <- nlsList(weight ~ a*Time^b|Diet, data=chick, start=list(a=10, b=1.1))
plot_nls(fit1)
# Plot a local regression object, with confidence interval
l <- loess(wt ~ disp, data=mtcars)
plot_loess(l)
# To plot behind the data:
with(mtcars, plot(disp, wt, pch=19,
panel.first=plot_loess(l, plotdata=FALSE)))
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.