简体   繁体   English

使用ggplot汇总图表中的Mann Kendall测试结果

[英]Using ggplot to Summarize Mann Kendall test results in a graph

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. 现在,我想为Mann-Kendall测试结果制作完全相同的图形。 And in place of "slope" section of my graph i want to insert the result from "Sen slope estimation". 并代替我图表的“斜率”部分,我要插入“ Sen斜率估计”的结果。 So i want result from two different test to show in this graph. 所以我想从两个不同的测试结果显示在此图中。

I thing the problem is in "Paste" section of "geom(label)". 我认为问题出在“ geom(label)”的“ Paste”部分。 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))



}

在此处输入图片说明

I've used Mann-Kendall / Sens a number of years ago. 几年前,我曾经使用过Mann-Kendall / Sens。 The package I used was wql . 我使用的软件包是wql

You can run the mannKen function over your data result <- mannKen(data$Precipitation) . 您可以对数据result <- mannKen(data$Precipitation)运行mannKen函数。 Once you have done that, you can access the Sens Slope and p-value using result $sen.slope and result$p.value . 完成此操作后,您可以使用result $sen.sloperesult$p.value result $sen.slope访问Sens Slope和p值。

To graph the trend line, I usually pick a point to fix the line - eg the median concentration in my timeseries coupled with the middle point of the timeseries. 为了绘制趋势线,我通常选择一个点来固定该线-例如,时间序列中的中值浓度与时间序列的中点相结合。 This gives me a reference point of (middleYear, median) - (1978, medianPrecipitation) in your graph above. 在上面的图中,这为我提供了(middleYear,中位数)-(1978,中位数降水)的参考点。

I then use the sens slope, the start point of the timeseries (1941 in your example above), the end point of the data (2019 in your example), and some linear algebra to calculate the start point of the line (Precipitation in 1941 if you extended the sens slope back from the reference point) and the end point of the line (Precipitation in 2019 if you extended the sens slope forward from the reference point). 然后,我使用sens斜率,时间序列的起点(在上面的示例中为1941),数据的终点(在示例中为2019)和一些线性代数来计算直线的起点(1941年的降水)如果您将sens斜率从参考点向后延伸)和直线的终点(如果您将sens斜率从参考点向前延伸则为2019年的降水)。

I'm interested to hear if there are any other packages that would simplify this process. 我很想知道是否还有其他软件包可以简化此过程。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM