将 method.args 添加到 ggplot stat_smooth() 会导致错误

Adding method.args to ggplot stat_smooth() causes error

我正在尝试来自 Introduction to Data Science: Data Analysis and Prediction Algorithms with R, chapter 28 的示例:

library(tidyverse)
library(dslabs)
data("polls_2008")

polls_2008 %>% ggplot(aes(day, margin)) +
  geom_point() + 
  geom_smooth(span = 0.15, method.args = list(degree=1))

这会导致错误,“警告消息:stat_smooth() 中的计算失败:'what' 必须是函数或字符串。”删除 method.args... 参数会导致正常操作。似乎将 method.args 定义为包含空列表的任何内容都会导致问题。

我正在使用为 Windows 和 ggplot2_3.3.2 构建的 R 版本 4.0.1 (2020-06-06)。感谢您的帮助。

我仔细检查了一下,这有效。他们将方法的默认值从“auto”更改为 NULL。这仍然与没有 method.arg 时使用的“自动”功能相同。但我认为你需要告诉它你是什么方法 运行 这样它才能正确使用 method.args

polls_2008 %>%
  ggplot(aes(day, margin)) +
  geom_point() + 
  geom_smooth(method = "loess", 
              span = 0.15, 
              method.args = list(degree=1))