I have been using a code to summarize some Linear Regression Results in a graph (Both code and graph are attached). I adopted the code referring to various sources from here.
Now i want to make the exact same graph for Mann-Kendall test Results. And in place of "slope" section of my graph i want to insert the result from "Sen slope estimation". So i want result from two different test to show in this graph.
I thing the problem is in "Paste" section of "geom(label)". Because i have to identify the particular numeric result that is to be pasted in my graph which i dont know how to do.
If any body have a solution to this problem. I will greatly appreciate it.
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))
}