将趋势线,回归值和kendall taus值放在r中

时间:2019-02-01 06:35:22

标签: r plot regression

我有一年和一年的温度数据。我在数据中的时间和年份,回归和t检验之间进行了kendall tau关联。

from src.classfile import *

我想在趋势图中放置一条趋势线,以及我根据Kendall tau计算出的tau值为0.20,根据t.test得到的显着值以及根据图例中的回归得到的rsquared值。我该如何进一步进行?

1 个答案:

答案 0 :(得分:2)

使用ggplot2,您可以使用geom_label添加统计信息:

x1 <- dat1$Year
y1 <- dat1$Annual_mean

kend_test <- Kendall(x1, y1)
t_test <- t.test(y1)
regr <- lm(x1~y1)

legend <- paste0(
    'tau: ', round(kend_test$tau, 2), '   ',
    'p-value: ', round(t_test$p.value, 2), '   ',
    'R^2: ', round(summary(regr)$r.squared, 2)
  )

dat1 %>%
  ggplot(aes(
    x = Year,
    y = Annual_mean
  )) +
  geom_point() +
  geom_smooth(method = 'lm', se = FALSE) +
  geom_label(aes(
      x = mean(x1),
      y = max(y1),
      label = legend
    ),
  )