【发布时间】:2019-05-18 19:53:03
【问题描述】:
我一直在使用代码在图表中总结一些线性回归结果(代码和图表均已附上)。我采用了参考这里的各种来源的代码。
现在我想为 Mann-Kendall 测试结果制作完全相同的图表。代替我图表的“斜率”部分,我想插入“森斜率估计”的结果。因此,我希望在此图中显示两个不同测试的结果。
我认为问题出在“geom(label)”的“粘贴”部分。因为我必须确定要粘贴到我的图表中的特定数字结果,我不知道该怎么做。
如果任何机构有解决此问题的方法。我将不胜感激。
ggplotRegressionxpl <- function (fit) {
require(ggplot2)
ggplot(fit$model, aes_string(x = names(fit$model)[2], y = names(fit$model)[1])) +
geom_point() + geom_line() + geom_label(aes(2000, 33, hjust = 0, vjust = 0, label = paste("R^2 = ",signif(summary(fit)$adj.r.squared, 3),"\n",
"Slope =",signif(fit$coef[[2]], 3),"\n",
"p-value =",signif(summary(fit)$coef[2,4], 3)))) +
stat_smooth(method = "lm", col = "red") + xlab("Year") + ylab("Total Precipitation") +
labs(title = "Pullman (1941–2018)") + scale_y_continuous(limits = c(0, 40)) +
theme(plot.title = element_text(hjust = 0.5))
}
【问题讨论】:
-
所以你的问题是如何将测试的输出作为文本放在图表中,或者我可能错过了这个测试的一些特殊性?我不知道您的测试结果在数据结构方面是什么样的,但您很有可能可以使用
str(your_test_results)找出您需要的特定信息的存储位置。 -
@Samrat:欢迎来到 Stack Overflow!您能否通过分享您的数据样本来重现您的问题,以便其他人可以提供帮助(请不要使用
str()、head()或屏幕截图)?您可以使用reprex和datapasta包来帮助您。另见Help me Help you & How to make a great R reproducible example? -
查看 ggstatsplot。它可能有你要找的东西indrajeetpatil.github.io/ggstatsplot
-
还有这个每日流量趋势分析owi.usgs.gov/blog/Quantile-Kendall
-
这可能也很有用“休伦河系统的环境流量”hrwc.org/wp-content/uploads/2014/06/…