【发布时间】:2016-09-05 14:52:06
【问题描述】:
这是一个后续question。当我运行下面给出的代码时,我收到警告消息,我认为这是由于我的代码中没有方面的要求,而链接中提到的源代码包括方面。看看,请让我知道哪个部分需要修改。期待!
代码:
library(dplyr)
library(ggplot2)
library(ggpmisc)
df <- diamonds %>%
dplyr::filter(cut%in%c("Fair","Ideal")) %>%
dplyr::filter(clarity%in%c("I1" , "SI2" , "SI1" , "VS2" , "VS1", "VVS2")) %>%
dplyr::mutate(new_price = ifelse(cut == "Fair",
price* 0.5,
price * 1.1))
p <- ggplot(df, aes(x,y, color=factor(cut)))
p <- p + stat_smooth(method = "lm", formula = y ~ x-1, size = 1, level=0.95)
p <- p + geom_point(alpha = 0.3)
p <- p + stat_poly_eq(aes(label = paste(..rr.label..)),
label.x.npc = "right", label.y.npc = 0.15, formula = formula,
parse = TRUE, size = 3) +
stat_fit_glance(method = 'lm', method.args = list(formula = formula),
geom = 'text', aes(label = paste("P-value = ",
signif(..p.value.., digits = 4), sep = "")),label.x.npc = 'right',
label.y.npc = 0.35, size = 3)
print(p)
警告信息:
1:stat_poly_eq() 中的计算失败:
“闭包”类型的对象不是子集
2:stat_fit_glance() 中的计算失败:
“闭包”类型的对象不是子集
【问题讨论】:
-
请注意,如果您已经使用
library(dplyr)加载了dplyr,则当您从dplyr调用函数时,无需在前面加上dplyr::(例如dplyr::filter等) .