r - 如何将相关检验的 p 值和 lm 的 R² 添加到散点图?
问题描述
我没有成功添加来自 Kendall 相关性的 pvalue 和来自线性模型的 R²。我正在使用ggplot
.
我尝试使用stat_fit_glance
,stat_poly_eq
但没有奏效,它显示以下警告消息:
Warning messages:
1. Computation failed in `stat_poly_eq()`:
object of type 'closure' is not subsettable
2. Computation failed in `stat_fit_glance()`:
object of type 'closure' is not subsettable
然后,我尝试使用ggscatter
,但找不到y
使用的。我也尝试手动添加它,但它不起作用,因为我corr.test
的不是数据框。
这是我到目前为止的代码(它只是散点图)
seq15 %>% ggplot(aes(Fe, Cr, color=depth)) +
geom_point() + xlab(expression(paste("Fe mg"~ kg^-1~"2015"))) +
ylab(expression(paste("Cr mg"~ kg^-1))) +
geom_smooth(data = subset(seq15, profundidade %in% c("0-3")), method = lm, se = FALSE, colour = "black", size = 0.1) +
scale_color_discrete(labels = c("0-3 cm", "3-5 cm", "5-10 cm", "10-15 cm", "15-20 cm", "20-25 cm", "25-30 cm")) +
theme(panel.border = element_rect(colour = "black", fill = NA, size = 0.1),panel.background = element_blank(), axis.line = element_line(color="black"), axis.line.x = element_line(color="black"),legend.title = element_text(color = "white"), legend.key = element_rect(fill = NA))
以及相关性检验:
cor.test(seq15$Fe,seq15$Cr, method = "kendall")
解决方案
推荐阅读
- reactjs - 从 React 应用程序向 pm2 启动的 Express 服务器发出请求时出现“原因:CORS 请求未成功”
- python - 从目录中读取多个 CSV 文件以检查列数
- events - 如何检查或检测窗口是否在 SDL 中最小化或不活动?
- python - 我想使用for循环在python中的字典中获取每个主题的总和
- android - 自定义视图从Android中的自定义主题属性获取自定义属性值
- javascript - Ramda - 然后,否则,andFinally?
- c# - 来自主 m3u8 文件的高带宽正则表达式匹配分辨率
- typescript - 如何在 TypeScript 中声明全局类型别名?
- javascript - 已安装不可变但仍显示未定义
- angular - 如何解决 jasmin UNIT 测试用例中的这种奇怪的随机错误?