Skip to content

Commit 8905de7

Browse files
committed
highlight {broom} functions in examples
1 parent 6e09cc4 commit 8905de7

File tree

4 files changed

+58
-122
lines changed

4 files changed

+58
-122
lines changed

R/fortify-lm.R

Lines changed: 8 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -21,63 +21,22 @@
2121
#' @param ... not used by this method
2222
#' @keywords internal
2323
#' @export
24-
#' @examples
24+
#' @examplesIf require("broom")
2525
#' mod <- lm(mpg ~ wt, data = mtcars)
26-
#' head(fortify(mod))
27-
#' head(fortify(mod, mtcars))
28-
#'
29-
#' plot(mod, which = 1)
3026
#'
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))
3530
#'
36-
#' ggplot(mod, aes(.fitted, .stdresid)) +
31+
#' # Using augment to convert model to ready-to-plot data
32+
#' ggplot(augment(mod), aes(.fitted, .resid)) +
3733
#' geom_point() +
3834
#' geom_hline(yintercept = 0) +
3935
#' geom_smooth(se = FALSE)
4036
#'
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))) +
7639
#' geom_point()
77-
#'
78-
#' ggplot(mod, aes(.hat, .cooksd)) +
79-
#' geom_point(aes(size = .cooksd / .hat)) +
80-
#' scale_size_area()
8140
fortify.lm <- function(model, data = model$model, ...) {
8241
lifecycle::deprecate_warn(
8342
"3.6.0", I("`fortify(<lm>)`"), I("`broom::augment(<lm>)`")

R/fortify-multcomp.R

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,28 +11,35 @@
1111
#' @param data,... other arguments to the generic ignored in this method.
1212
#' @name fortify-multcomp
1313
#' @keywords internal
14-
#' @examples
15-
#' if (require("multcomp")) {
14+
#' @examplesIf require("multcomp") && require("broom")
1615
#' amod <- aov(breaks ~ wool + tension, data = warpbreaks)
17-
#' wht <- glht(amod, linfct = mcp(tension = "Tukey"))
16+
#' wht <- multcomp::glht(amod, linfct = multcomp::mcp(tension = "Tukey"))
1817
#'
18+
#' tidy(wht) # recommended
1919
#' fortify(wht)
20-
#' ggplot(wht, aes(lhs, estimate)) + geom_point()
2120
#'
22-
#' CI <- confint(wht)
23-
#' fortify(CI)
24-
#' ggplot(CI, aes(lhs, estimate, ymin = lwr, ymax = upr)) +
21+
#' ggplot(tidy(wht), aes(contrast, estimate)) + geom_point()
22+
#'
23+
#' ci <- confint(wht)
24+
#' tidy(ci) # recommended
25+
#' fortify(ci)
26+
#'
27+
#' ggplot(tidy(confint(wht)),
28+
#' aes(contrast, estimate, ymin = conf.low, ymax = conf.high)) +
2529
#' geom_pointrange()
2630
#'
27-
#' fortify(summary(wht))
28-
#' ggplot(mapping = aes(lhs, estimate)) +
29-
#' geom_linerange(aes(ymin = lwr, ymax = upr), data = CI) +
30-
#' geom_point(aes(size = p), data = summary(wht)) +
31+
#' smry <- summary(wht)
32+
#' tidy(smry) # recommended
33+
#' fortify(smry)
34+
#'
35+
#' ggplot(mapping = aes(contrast, estimate)) +
36+
#' geom_linerange(aes(ymin = conf.low, ymax = conf.high), data = tidy(ci)) +
37+
#' geom_point(aes(size = adj.p.value), data = tidy(smry)) +
3138
#' scale_size(transform = "reverse")
3239
#'
33-
#' cld <- cld(wht)
40+
#' cld <- multcomp::cld(wht)
41+
#' tidy(cld) # recommended
3442
#' fortify(cld)
35-
#' }
3643
NULL
3744

3845
#' @method fortify glht

man/fortify-multcomp.Rd

Lines changed: 21 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/fortify.lm.Rd

Lines changed: 9 additions & 48 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)