| gf_square_resid_fun | R Documentation |
gf_square_resid_fun(
object = NULL,
gformula = NULL,
data = NULL,
...,
fun,
aspect = 4/6,
alpha = 0.1,
xlab,
ylab,
title,
subtitle,
caption,
geom = coursekata::GeomSquareResid,
stat = coursekata::StatResid,
position = "identity",
show.legend = NA,
show.help = NULL,
inherit = FALSE,
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 |
aspect |
The square's aspect ratio. Default is |
alpha |
The transparency of the square's fill. Default is |
xlab, ylab, title, subtitle, caption |
Labels for the plot. |
geom, stat, position |
Not set by the caller. A squared residual is drawn by its own geom and stat, and moved by the position the observations are already drawn with, so that a square 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. |
environment |
The environment mappings are resolved in. |
Draws squared residual polygons between observed points and the values
predicted by a user-supplied function of x. Where gf_square_resid()
measures a fitted model, this measures a function you wrote: it is called on
the x values the plot draws, and each square is built on the residual from an
observation to what the function predicts for it.
A ggplot object with squared residual polygons 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_square_resid_fun(my_fun, color = "red", alpha = 0.3)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.