r - 当一组没有足够的数据点时,ggpmisc::stat_poly_eq 崩溃
问题描述
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
颜色组只有一个数据点这一事实。这还不够。但是,它至少应该为其他组输出标签?
解决方案
该问题现已在即将推出的 'ggpmisc' (0.4.0) 中得到解决,可以从 GitHub 安装。目前可以安装固定版本,remotes::install_github("aphalo/ggpp")
后跟remotes::install_github("aphalo/ggpmisc")
.
一旦两个软件包都在 CRAN 中,更新“ggpmisc”就足够了。
推荐阅读
- python - 使用网状将R变量传递给python脚本
- c# - 如何为通过 HttpClientFactory 直接创建的 HttpClient 配置 Web 代理?
- html - CSS Slider - 悬停功能而不是单击
- raku - 减少 Perl 6 中的逻辑运算符
- python - 检查 Python 字典中的多个“键”
- vba - SAP GUI 脚本 - 从 pywin32 中的打印屏幕创建 PDF
- c# - XML 排序在 ASP.NET MVC 中使用 LINQ
- java - 即使它在我的工作目录中,java也无法从文本文件中扫描
- powershell - powershell 在不运行时启动一个 ScheduledTask
- react-native - 什么时候在 react-native 的 AsyncStorage 中使用 flushGetRequests?