this is my code:
library(tidyverse)
if (!require(performance) ) {
install.packages("performance");library(performance)}
if (!require(see) ) {install.packages("see");library(see)}
# defining a model
model <- lm(mpg ~ wt + am + gear + vs * cyl, data = mtcars)
check_model(model)
How can I obtain the dataframe related to the Normality of Residuals Chart?
I need to replicate this chart and I dont know how to extract the data.
Any help?
this is my code:
library(tidyverse)
if (!require(performance) ) {
install.packages("performance");library(performance)}
if (!require(see) ) {install.packages("see");library(see)}
# defining a model
model <- lm(mpg ~ wt + am + gear + vs * cyl, data = mtcars)
check_model(model)
How can I obtain the dataframe related to the Normality of Residuals Chart?
I need to replicate this chart and I dont know how to extract the data.
Any help?
Share Improve this question edited Mar 15 at 23:13 IRTFM 264k22 gold badges379 silver badges500 bronze badges asked Mar 14 at 22:48 LauraLaura 63117 silver badges43 bronze badges 5 |1 Answer
Reset to default 7You could dig around in the code of see:::plot.see_check_normality
, but it's pretty complicated. The easier/hackier alternative is to use ggplot_build
to export the data used in the ggplot
object, as below ...
library(performance)
library(ggplot2)
m <- lm(mpg ~ wt + cyl + gear + disp, data = mtcars)
result <- check_normality(m)
p <- plot(result)
print(p)
g <- ggplot_build(p)
d <- g$data[[2]]
plot(d$x, d$y)
@stefan points out that d <- layer_data(p, i = 2)
will retrieve the same information (if you omit the p
argument it will take the data from the last ggplot rendered, but I think it's better to be explicit)
check_model()
say that it returns the frame used for plotting. Have you triedres <- check_model(model)
and look atres
? – r2evans Commented Mar 14 at 22:53