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颜色组只有一个数据点。这还不够。但是它至少应该输出其他组的标签吗?
发布于 2021-05-23 12:40:53
这个问题现在在即将到来的'ggpmisc‘(0.4.0)中得到了解决,它可以从GitHub安装。目前,可以用remotes::install_github("aphalo/ggpp")安装固定版本,然后再安装remotes::install_github("aphalo/ggpmisc")。
一旦两个包都在CRAN中,更新'ggpmisc‘就足够了。
https://stackoverflow.com/questions/67592659
复制相似问题