options(digits=6) # APPROSSIMAZIONE ALLA 6° CIFRA DECIMALE
library(tseries)
install.packages("tseries")
dati<- "http://www.remss.com/data/msu/monthly_time_series/RSS_Monthly_MSU_AMSU_Channel_TLT_Anomalies_Land_and_Ocean_v03_2.txt"
RSS_mensile <- read.table(dati,skip = 3,sep = "",dec=".",row.names = NULL,header = FALSE,as.is = T,colClasses = c(rep("numeric",3),rep("NULL", 8)),comment.char = "#",na.strings = c("*", "-",-99.9, -999.9),col.names = c("Anno", "Mese", "RSS_anom", rep("",8)))
anno_fraz <- RSS_mensile$Anno + (RSS_mensile$Mese-1)/12
RSS_data_frame<-data.frame(RSS_mensile,anno_fraz)
attach(RSS_data_frame)
c<-nrow(RSS_data_frame)
ultimo_mese <- RSS_data_frame$Mese
ultimo_anno <- RSS_data_frame$Anno
ultimo_dato <- RSS_anom
RSS <- ts(RSS_anom,start=c(1979,1),frequency=12)
plot(anno_fraz,RSS_anom,type="s",col="grey",xlab="",ylab = "°C - Anomalia termica",xlim=c(1979, 2010), ylim=c(-0.6,max(RSS)),cex.axis=0.95,cex.lab=0.95)
lines(RSS,type="h",col="lightgrey") # GRAFICO DI FONDO
abline(h=0,col="darkgrey")
lm_fit <- lm(RSS_anom~anno_fraz)
a <- coef(lm_fit)[1]
b <- coef(lm_fit)[2]
yr1 <- min(anno_fraz)
yr2 <- max(anno_fraz)
y1 <- a+b*yr1
y2 <- a+b*yr2
x_val <- c(yr1,yr2)
y_val <- c(y1,y2)
lines(x_val,y_val,type="l",col="red")
b <- signif(b, 3)
#points(yr2, ultimo_dato, pch=20, col = "blue")
#points(1995, -0.5, pch=20, col = "blue")
note2 <- paste("Ultima osservazione ",ultimo_mese, "/", ultimo_anno, " = ", ultimo_dato," °C")
text(1995, -0.5, note2, pos = 4, col = "blue", cex = 0.7)
note3 <- paste("Trend = ",b," °C / anno ")
text(1995,-0.4, note3,pos=4, col = "red", cex = 0.7)