|
21 | 21 | #' @param ... not used by this method |
22 | 22 | #' @keywords internal |
23 | 23 | #' @export |
24 | | -#' @examples |
| 24 | +#' @examplesIf require("broom") |
25 | 25 | #' mod <- lm(mpg ~ wt, data = mtcars) |
26 | | -#' head(fortify(mod)) |
27 | | -#' head(fortify(mod, mtcars)) |
28 | | -#' |
29 | | -#' plot(mod, which = 1) |
30 | 26 | #' |
31 | | -#' ggplot(mod, aes(.fitted, .resid)) + |
32 | | -#' geom_point() + |
33 | | -#' geom_hline(yintercept = 0) + |
34 | | -#' geom_smooth(se = FALSE) |
| 27 | +#' # Show augmented model |
| 28 | +#' head(augment(mod)) |
| 29 | +#' head(fortify(mod)) |
35 | 30 | #' |
36 | | -#' ggplot(mod, aes(.fitted, .stdresid)) + |
| 31 | +#' # Using augment to convert model to ready-to-plot data |
| 32 | +#' ggplot(augment(mod), aes(.fitted, .resid)) + |
37 | 33 | #' geom_point() + |
38 | 34 | #' geom_hline(yintercept = 0) + |
39 | 35 | #' geom_smooth(se = FALSE) |
40 | 36 | #' |
41 | | -#' ggplot(fortify(mod, mtcars), aes(.fitted, .stdresid)) + |
42 | | -#' geom_point(aes(colour = factor(cyl))) |
43 | | -#' |
44 | | -#' ggplot(fortify(mod, mtcars), aes(mpg, .stdresid)) + |
45 | | -#' geom_point(aes(colour = factor(cyl))) |
46 | | -#' |
47 | | -#' plot(mod, which = 2) |
48 | | -#' ggplot(mod) + |
49 | | -#' stat_qq(aes(sample = .stdresid)) + |
50 | | -#' geom_abline() |
51 | | -#' |
52 | | -#' plot(mod, which = 3) |
53 | | -#' ggplot(mod, aes(.fitted, sqrt(abs(.stdresid)))) + |
54 | | -#' geom_point() + |
55 | | -#' geom_smooth(se = FALSE) |
56 | | -#' |
57 | | -#' plot(mod, which = 4) |
58 | | -#' ggplot(mod, aes(seq_along(.cooksd), .cooksd)) + |
59 | | -#' geom_col() |
60 | | -#' |
61 | | -#' plot(mod, which = 5) |
62 | | -#' ggplot(mod, aes(.hat, .stdresid)) + |
63 | | -#' geom_vline(linewidth = 2, colour = "white", xintercept = 0) + |
64 | | -#' geom_hline(linewidth = 2, colour = "white", yintercept = 0) + |
65 | | -#' geom_point() + geom_smooth(se = FALSE) |
66 | | -#' |
67 | | -#' ggplot(mod, aes(.hat, .stdresid)) + |
68 | | -#' geom_point(aes(size = .cooksd)) + |
69 | | -#' geom_smooth(se = FALSE, linewidth = 0.5) |
70 | | -#' |
71 | | -#' plot(mod, which = 6) |
72 | | -#' ggplot(mod, aes(.hat, .cooksd)) + |
73 | | -#' geom_vline(xintercept = 0, colour = NA) + |
74 | | -#' geom_abline(slope = seq(0, 3, by = 0.5), colour = "white") + |
75 | | -#' geom_smooth(se = FALSE) + |
| 37 | +#' # Colouring by original data not included in the model |
| 38 | +#' ggplot(augment(mod, mtcars), aes(.fitted, .std.resid, colour = factor(cyl))) + |
76 | 39 | #' geom_point() |
77 | | -#' |
78 | | -#' ggplot(mod, aes(.hat, .cooksd)) + |
79 | | -#' geom_point(aes(size = .cooksd / .hat)) + |
80 | | -#' scale_size_area() |
81 | 40 | fortify.lm <- function(model, data = model$model, ...) { |
82 | 41 | lifecycle::deprecate_warn( |
83 | 42 | "3.6.0", I("`fortify(<lm>)`"), I("`broom::augment(<lm>)`") |
|
0 commit comments