我正在尝试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)。感谢您的帮助。
答案 0 :(得分:1)
我仔细检查了一下,这个方法可行。他们将方法的默认值从“ 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))