ggeffects::ggpredict 是否有全范围参数

Is there a fullrange argument for ggeffects::ggpredict

我想要一个像 ggplot2::geom_smooth(method = "lm", fullrange = T)ggeffects::ggpredict() 这样的情节。拟合应该只跨越数据而不是整个图。

有人可以帮忙吗?

例子

data(mtcars)
mtcars <- mutate(mtcars, cyl = as_factor(cyl))

ggplot2fullrange = F

ggplot(data = mtcars, aes(x = wt, y = mpg, group = cyl, color = cyl)) +
      geom_point() +
      geom_smooth(method = "lm", fullrange = F)

ggeffects 其中 fullrange = F 不可能

m <- lm(mpg ~ wt * cyl, data = mtcars)
data_m <- ggeffects::ggpredict(m, terms = c("wt", "cyl"))
ggplot() +
  geom_point(data = mtcars, aes(x = wt, y = mpg, color = cyl)) +
  geom_ribbon(data = data_m, aes(x = x, y = predicted, group = group, ymin = conf.low, ymax = conf.high), alpha = .3) +
  geom_line(data = data_m, aes(x = x, y = predicted, color = group))

也许limit.range

library(ggeffects)
data(iris)
m <- lm(Sepal.Width ~ Species * Sepal.Length, data = iris)
ggpredict(m, c("Sepal.Length", "Species")) |> plot(add.data = TRUE)
#> Loading required namespace: ggplot2

ggpredict(m, c("Sepal.Length", "Species")) |> plot(add.data = TRUE, limit.range = TRUE)

reprex package (v2.0.1)

于 2021-11-17 创建