首页 > 解决方案 > 如何将相关检验的 p 值和 lm 的 R² 添加到散点图?

问题描述

我没有成功添加来自 Kendall 相关性的 pvalue 和来自线性模型的 R²。我正在使用ggplot.

我尝试使用stat_fit_glancestat_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")

标签: rggplot2

解决方案


推荐阅读