Description Usage Arguments Details Value Examples
Draw a plot after fitting a two-dimensional model.
1 | model_display(df, ..., digits = 2)
|
df |
A grouped data frame, created with |
... |
List of name-value pairs in the form |
digits |
Integer indicating the number of significant digits to be used when fitted parameters are substituted in the model formula. Negative values are allowed; see signif(...). |
The parameters of the model, usually accessible via the .$tidy
column after model_cleanly_groupwise
has been called, are substituted
in the fitted formula and can be accessed as .$sub.formula
.
A ggplot
that can be further customized.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | library(dplyr)
library(ggplot2)
# create some noisy data for fitting a linear model
x <- seq(1, 10)
y1 <- 3 * x + 5 + rnorm(10)
y2 <- 1 * x + 1 + rnorm(10)
my_data <- bind_rows(data1 = tibble(x, y = y1),
data2 = tibble(x, y = y2), .id = "dataset") %>%
group_by(dataset)
my_data %>%
model_cleanly_groupwise(lm, formula = y ~ x) %>%
model_display(color = dataset)
## positioning of per-facet text labels in ggplot is inherently
## difficult; the visual of the example could be improved
my_data %>%
model_cleanly_groupwise(lm, formula = y ~ x) %>%
model_display() +
# add substituted formula
geom_text(aes(x = -Inf, y = Inf, label = sub.formula),
hjust = 0, vjust = 1) +
# add R square
geom_text(data = . %>% tidyr::unnest(glance),
aes(x = Inf, y = Inf, label = paste("R^2 =", signif(r.squared, 3))),
hjust = 1, vjust = 1) +
# show as facet
facet_wrap(vars(dataset))
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.