| gf_resid_fun | R Documentation |
gf_resid_fun(plot, fun, linewidth = 0.2, ...)
plot |
A ggformula/ggplot object, typically created with |
fun |
A function that takes a numeric vector x and returns predicted y. |
linewidth |
Numeric width of the residual lines. Default |
... |
Additional aesthetics passed to |
Draws vertical residual lines from observed points to predicted values
computed by a user-supplied function of x (e.g., the function plotted with
gf_function()).
A ggplot object with residual segments 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.