| gf_resid_fun | R Documentation |
gf_resid_fun(
object = NULL,
gformula = NULL,
data = NULL,
...,
fun,
linewidth = 0.2,
xlab,
ylab,
title,
subtitle,
caption,
geom = coursekata::GeomResid,
stat = coursekata::StatResid,
position = "identity",
show.legend = NA,
show.help = NULL,
inherit = TRUE,
environment = parent.frame()
)
object |
A ggformula plot object, typically created with |
gformula |
Not used. |
data |
Not used. The residuals are measured over the data the plot was
built from. Anything supplied here is left for ggformula and ggplot2 to
answer, exactly as it is for any other |
... |
Additional arguments. Typically these are (a) ggplot2 aesthetics to be set with
|
fun |
A function of one argument. It is called on the x values the plot
draws and must return one predicted y for each of them. May be given
positionally or as |
linewidth |
The width of the residual lines. Default is |
xlab, ylab, title, subtitle, caption |
Labels for the plot. |
geom, stat, position |
Not set by the caller. A residual is drawn by its own geom and stat, and moved by the position the observations are already drawn with, so that a segment stays on the point it belongs to. |
show.legend |
Whether this layer contributes to the legend. |
show.help |
Print the layer's own help instead of drawing. |
inherit |
Whether the layer inherits the plot's aesthetics. The axes and
the prediction are stated outright; everything else – a mapped |
environment |
The environment mappings are resolved in. |
Draws residual lines from predicted values to the observed points, using a
user-supplied function of x (e.g., the function plotted with
gf_function()). Where gf_resid() measures a fitted model, this measures a
function you wrote: it is called on the x values the plot draws, and each
residual runs from the prediction to the observation.
A ggplot object with residual lines added.
set.seed(1)
df <- data.frame(X = 1:10, Y = 2 + 3 * (1:10) + rnorm(10))
my_fun <- function(x) 2 + 3 * x
gf_point(Y ~ X, data = df) %>%
gf_function(my_fun) %>%
gf_resid_fun(my_fun, color = "red", alpha = 0.5)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.