Comparaison des anomalies de températures en France et dans le monde.
library(gdata) # read xls
## gdata: read.xls support for 'XLS' (Excel 97-2004) files ENABLED.
##
## gdata: read.xls support for 'XLSX' (Excel 2007+) files ENABLED.
##
## Attaching package: 'gdata'
##
## L'objet suivant est masqué from 'package:stats':
##
## nobs
##
## L'objet suivant est masqué from 'package:utils':
##
## object.size
library(ggplot2)
library(reshape2) # melt
library(mgcv) # for ggplot smoothing
## Loading required package: nlme
## This is mgcv 1.8-7. For overview type 'help("mgcv-package")'.
brut <- read.xls("http://www.developpement-durable.gouv.fr/IMG/xls/ONERC_2015-donnees-temperatures-air-metropole-graph2-evolution-tm-france-1900-2014.xls",
sheet=1, header=FALSE, skip=2)
tmf <- as.data.frame(cbind(brut$V1, brut$V4))
colnames(tmf) <- c("annee", "anomalie")
tmf$signe <- ifelse(tmf$anomalie < 0, "negatif", "positif")
Sys.setlocale("LC_CTYPE", "fr_FR.UTF-8")
## [1] "fr_FR.UTF-8"
ggplot(data=tmf, aes(annee, anomalie)) +
geom_bar(stat="identity", aes(fill=signe)) +
geom_smooth(span=0.15, color="black", alpha=0.3) +
scale_fill_manual(values = c("negatif"="blue", "positif"="red")) +
guides(fill=FALSE) +
xlab("Année") +
ylab("Écart à la moyenne 1961-1990 (°C)") +
ggtitle("Températures annuelles moyenne en France métropolitaine")
## geom_smooth: method="auto" and size of largest group is <1000, so using loess. Use 'method = x' to change the smoothing method.
## Warning: Stacking not well defined when ymin != 0
ggplot(data=tmf, aes(annee, anomalie)) +
geom_point(aes(color=tmf$signe)) +
geom_segment(aes(xend=tmf$annee, color=tmf$signe), yend=0) +
geom_smooth(span=0.15, color="black", alpha=0.3) +
scale_fill_manual(values = c("negatif"="blue", "positif"="red")) +
scale_color_manual(values = c("negatif"="blue", "positif"="red")) +
guides(fill=FALSE, color=FALSE) +
xlab("Année") +
ylab("Écart à la moyenne 1961-1990 (°C)") +
ggtitle("Températures annuelles moyenne en France métropolitaine")
## geom_smooth: method="auto" and size of largest group is <1000, so using loess. Use 'method = x' to change the smoothing method.
Données globales : Means Based on Land-Surface Air Temperature Anomalies Only
gistemp <- head(
read.table("http://data.giss.nasa.gov/gistemp/tabledata_v3/GLB.Ts.txt",
skip=7, na.strings=c("****", "***"), fill=TRUE, blank.lines.skip=TRUE, stringsAsFactors=FALSE, header=TRUE),
-9)
# Remove rows with garbage strings
gistemp <- gistemp[gistemp$Year != "Year",]
# remove unused last 7 columns
gistemp <- gistemp[, names(gistemp) %in% head(colnames(gistemp), -7)]
# rename columns : month name to month number
colnames(gistemp) <- c("Year", values=seq(1:12))
# long format
gistemp <- melt(gistemp, id.vars="Year", variable.name="month", value.name="tm")
gistemp$Year <- as.numeric(gistemp$Year)
# use Celsius degrees - see file for reference value
gistemp$tm <- (as.numeric(gistemp$tm) / 100) + 14.0
# use the same reference 1961-1990 as météoFrance
gistemp$tm2 <- gistemp$tm - mean(subset(gistemp, Year >= 1961 & Year <= 1990)$tm)
#last complete year
lcy <- 2015
ggplot(subset(gistemp, gistemp$Year < lcy), aes(Year, tm2, color="blue")) +
stat_summary(fun.y=mean, geom="point") +
stat_smooth(span=0.15, color="blue", guide="legend") +
geom_point(data=tmf, aes(annee, anomalie), color="red") +
stat_smooth(span=0.15, data=tmf, aes(annee, anomalie, color="red"), guide="legend") +
xlab("Année") +
ylab("Température (°C)") +
ggtitle("Température moyenne annuelle Monde (GISTEMP dTs) et France (Météo-France)\nÉcarts à leur moyenne 1961-1990") +
scale_colour_manual(name="Données", values=c("red"="red", "blue"="blue"), labels = c("Monde", "France"))
## geom_smooth: method="auto" and size of largest group is >=1000, so using gam with formula: y ~ s(x, bs = "cs"). Use 'method = x' to change the smoothing method.
## geom_smooth: method="auto" and size of largest group is <1000, so using loess. Use 'method = x' to change the smoothing method.