library(ggpmisc)
data <- mpg
table(data$class)
data$class[mpg$class=="2seater"] <- c(rep("2seater", 1), rep("compact", 4))
formula <- y ~ x + I(x^2)
ggplot(data, aes(x = displ, y = hwy, color = class)) +
geom_point() +
geom_smooth(method = "lm", formula = formula) +
ggpmisc::stat_poly_eq(aes(label = paste(stat(eq.label), stat(adj.rr.label), sep = "*\", \"*")),
formula = formula, parse = TRUE)
上面的代码将生成一个没有公式和 r 平方标签的图。并会给出这个警告:
Warning message:
Computation failed in `stat_poly_eq()`:
argument "x" is missing, with no default
问题源于2seater
颜色组只有一个数据点这一事实。这还不够。但是,它至少应该为其他组输出标签?