将趋势线、回归值和kendall taus值放入r中
我有一年和一年的温度数据。我在数据中进行了时间和年份之间的kendall-tau相关性、回归和t检验将趋势线、回归值和kendall taus值放入r中,r,plot,regression,R,Plot,Regression,我有一年和一年的温度数据。我在数据中进行了时间和年份之间的kendall-tau相关性、回归和t检验 Now i want to plot the data (Time~Temperature). My data is as follows; Year Annual mean 1948 9.052924791 1949 9.728310502 1950 7.984018265 1951 7.99391172 1952 9.630388585 1953 1
Now i want to plot the data (Time~Temperature). My data is as follows;
Year Annual mean
1948 9.052924791
1949 9.728310502
1950 7.984018265
1951 7.99391172
1952 9.630388585
1953 10.35083714
1954 10.08980213
1955 9.812785388
1956 10.12480974
1957 9.187214612
1958 8.658295282
1959 9.857686454
1960 9.43989071
1961 9.221461187
1962 9.102739726
1963 8.627853881
1964 9.53476017
1965 9.050228311
1966 9.063926941
1967 8.942922374
1968 10.27018822
1969 9.780060883
1970 10.16590563
1971 10.75190259
1972 8.83955677
1973 10.92161339
1974 9.847031963
1975 10.67579909
1976 9.364754098
1977 10.42085236
1978 8.744292237
1979 9.121004566
1980 9.338660578
1981 9.512937595
1982 8.953576865
1983 9.645357686
1984 9.127959927
1985 8.525114155
1986 9.95585997
1987 11.23896499
1988 9.804327808
1989 9.136986301
1990 11.00989346
1991 10.78830891
1992 9.392835458
1993 9.322678843
1994 10.12633181
1995 10.08928571
1996 8.568609593
1997 9.242770167
1998 12.0456621
1999 10.78767123
2000 10.03035823
2001 10.51141553
2002 10.53805175
2003 9.496194825
2004 10.03483607
2005 10.74642857
2006 11.1509589
2007 10.79342466
2008 9.366256831
2009 9.372998478
2010 10.87214612
2011 10.44292237
2012 12.34390878
2013 9.564687976
2014 8.698158295
2015 10.14237443
2016 11.2704918
2017 11.42694064
2018 10.62660256
My Codes so far;
Install Necessary packages#
install.packages("dplyr")
library(dplyr)
install.packages("tidyr")
library(tidyr)
install.packages("stringr")
library(stringr)
install.packages("Kendall")
library(Kendall)
dat1<-read.table("AnnualMean.csv", sep=",", header = T)
x1<-dat1$Year
y1<-dat1$Annual.mean
Kendall(x1,y1)
test<-t.test(y1)
regress<-lm(x1~y1)
plot( y1~x1 , type="b" , bty="l" , xlab="year" , ylab="Temp in Celcius")
abline(regress, col="blue")
现在我想绘制数据(时间~温度)。我的数据如下:;
年平均数
1948 9.052924791
1949 9.728310502
1950 7.984018265
1951 7.99391172
1952 9.630388585
1953 10.35083714
1954 10.08980213
1955 9.812785388
1956 10.12480974
1957 9.187214612
1958 8.658295282
1959 9.857686454
1960 9.43989071
1961 9.221461187
1962 9.102739726
1963 8.627853881
1964 9.53476017
1965 9.050228311
1966 9.063926941
1967 8.942922374
1968 10.27018822
1969 9.780060883
1970 10.16590563
1971 10.75190259
1972 8.83955677
1973 10.92161339
1974 9.847031963
1975 10.67579909
1976 9.364754098
1977 10.42085236
1978 8.744292237
1979 9.121004566
1980 9.338660578
1981 9.512937595
1982 8.953576865
1983 9.645357686
1984 9.127959927
1985 8.525114155
1986 9.95585997
1987 11.23896499
1988 9.804327808
1989 9.136986301
1990 11.00989346
1991 10.78830891
1992 9.392835458
1993 9.322678843
1994 10.12633181
1995 10.08928571
1996 8.568609593
1997 9.242770167
1998 12.0456621
1999 10.78767123
2000 10.03035823
2001 10.51141553
2002 10.53805175
2003 9.496194825
2004 10.03483607
2005 10.74642857
2006 11.1509589
2007 10.79342466
2008 9.366256831
2009 9.372998478
2010 10.87214612
2011 10.44292237
2012 12.34390878
2013 9.564687976
2014 8.698158295
2015 10.14237443
2016 11.2704918
2017 11.42694064
2018 10.62660256
到目前为止我的代码;
安装必要的软件包#
安装程序包(“dplyr”)
图书馆(dplyr)
安装程序包(“tidyr”)
图书馆(tidyr)
安装程序包(“stringr”)
图书馆(stringr)
安装程序包(“Kendall”)
图书馆(肯德尔)
dat1使用ggplot2
您可以使用geom_标签添加您的统计信息
:
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
),
)
x1使用ggplot2
您可以使用geom\u标签添加统计信息
:
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
),
)
x1可以用ggplot2
完成吗?如果您能帮助gplot,我会感谢Pawel Chabros。感谢您能使用ggplot2
?如果您能为gplot提供帮助,我将感谢Pawel Chabros。谢谢,没问题。我很高兴我能帮上忙:)我怎么把一个方程,如;图中y=0.0198x+9.1245(y截距)。感谢使用geom\u标签作为统计数据的againSam。可以使用系数(regr)
提取的方程值。而不是用文本粘贴它们。例如,paste0('y=',round(cofficies(regr)[2],4),'x+',round(cofficies(regr)[1]),4)
legend%ggplot(aes(x=Year,y=Year.Mean.Celcius))+geom_line()+geom_smooth(method='lm',se=FALSE)+geom_标签(aes(x=Mean(x1),y=max(y1),标签=legend),)我编辑了这个,但它不会将公式粘贴到您在paste0
函数中出错的框中。试试这个图例没问题。我很高兴我能帮上忙:)我怎么把一个方程,如;图中y=0.0198x+9.1245(y截距)。感谢使用geom\u标签作为统计数据的againSam。可以使用系数(regr)
提取的方程值。而不是用文本粘贴它们。例如,paste0('y=',round(cofficies(regr)[2],4),'x+',round(cofficies(regr)[1]),4)
legend%ggplot(aes(x=Year,y=Year.Mean.Celcius))+geom_line()+geom_smooth(method='lm',se=FALSE)+geom_标签(aes(x=Mean(x1),y=max(y1),标签=legend),)我编辑了这个,但它不会将公式粘贴到您在paste0
函数中出错的框中。试试这个图例