Exemples instructifs… Représentations graphiques
Fonctions de répartition x=1:6 y=rep(1/6,6) z=cumsum(y) plot(c(0,x),c(0,z),lwd=3,col="blue") segments(0,0,1,0,col="green") segments(x,z, x+1,z)
Utiliser des données de packages existants search() [1] ".GlobalEnv" "package:methods" "package:stats" [4] "package:graphics" "package:grDevices" "package:utils" [7] "package:datasets" "Autoloads" "package:base" library( ) ash David Scott's ASH routines base The R Base Package boot Bootstrap R (S-Plus) Functions (Canty) class Functions for Classification cluster Functions for clustering (by Rousseeuw et al.)…… MASS Main Package of Venables and Ripley's MASS……
library(MASS);search() [1] ".GlobalEnv" "package:MASS" "package:methods" [4] "package:stats" "package:graphics" "package:grDevices" [7] "package:utils" "package:datasets" "Autoloads" [10] "package:base" data(iris); iris Sepal.Length Sepal.Width Petal.Length Petal.Width Species setosa setosa setosa setosa… versicolor versicolor versicolor versicolor plot(iris$Petal.Length,iris$Petal.Width)
data(Animals); Animals body brain Mountain beaver Cow Grey wolf Goat Guinea pig Dipliodocus Asian elephant Donkey Horse …….
plot( Animals[,"brain"],Animals[,"body"]) plot(Animals$brain,Animals$body) plot(Animals[,1],Animals[,2]) attach(Animals) plot(body,brain) detach(Animals)
Plusieurs dessins sur la même page par(mfrow=c(2,2)) data(Animals) attach(Animals) plot(body,brain) plot(sqrt(body),sqrt(brain)) plot(body^0.1,brain^0.1) plot(log(body), log(brain)) detach(Animals) par(mfrow=c(1,1))
Les fonctions plot(), points(), lines(), ablines(),pairs()… x = rnorm(50) plot(x, ann = FALSE, type = "n" ) abline(h = 0,col="gray") lines(x, col = "green4", lty = "dotted") points(x, bg = "limegreen", pch = 21) title(main = "Utilisation simple de la couleur dans un dessin",col.main = "blue", cex.main = 1.2, font.main = 4)
par(bg = "white") n = 100 x = c(0, cumsum(rnorm(n))) y = c(0, cumsum(rnorm(n))) xx = c(0:n, n:0) yy = c(x, rev(y)) plot(xx, yy, type = "n", xlab = "Time", ylab = "Distance") polygon(xx, yy, col = "gray") title("Distance entre deux mouvements Browniens")
x = c(0, 0.4, 0.86, 0.85, 0.69, 0.48, 0.54, 1.09, 1.11, 1.73, 2.05, 2.02) par(bg = "lightgray"); plot(x, type = "n", axes = FALSE, ann = FALSE); lines(x, col = "blue"); points(x, pch = 21, bg = "lightcyan", cex = 1.25); axis(2, col.axis = "blue", las = 1); axis(1, at = 1:12, lab = month.abb, col.axis = "blue"); box(); title(main = "The Level of Interest in R", font.main = 4, col.main = "red") title(xlab = "1996", col.lab = "red")
x=c(…) par(bg = "lightgray"); plot(x, type = "n", axes = FALSE, ann = FALSE);
lines(x, col = "blue"); points(x, pch = 21, bg = "lightcyan", cex = 1.25);
axis(2, col.axis = "blue", las = 1); axis(1, at = 1:12, lab = month.abb, col.axis = "blue");
box(); title(main = "The Level of Interest in R", font.main = 4, col.main = "red") title(xlab = "1996", col.lab = "red")
La fonction pairs pairs(iris[1:4], main = « donnees sur les Iris d’Edgar Anderson", font.main = 4, pch = 19)
La fonction pairs() pairs(iris[1:4], main = « Données sur les Iris d’Edgar Anderson", pch = 21, bg = c("red","green3«,"blue") [unclass(iris$Species)])
Résolution de l’ex 1 p40 t=c(2:12);N=c(55,90,135,245,403,66 5,1100,1810,3000,4450,7350) T=data.frame(t,N,y=log(N));T; > T t N y t N y …..
Calcul de moyenne et écart-type apply(T,2,mean); t N y apply(T,2,sd); t N y
plot(T$t,T$N)
plot(T$t,T$y)
droite de regression ll=lm(y~t,data=T);ll; Call: lm(formula = y ~ t, data = T) Coefficients: (Intercept) t
abline(ll);
summary(ll) Call: lm(formula = y ~ t, data = T) Residuals: Min 1Q Median 3Q Max Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) e-14 *** t e-15 *** --- Signif. codes: 0 `***' `**' 0.01 `*' 0.05 `.' 0.1 ` ' 1
summary(ll) suite Residual standard error: on 9 degrees of freedom Multiple R-Squared: , Adjusted R- squared: F-statistic: 1.329e+04 on 1 and 9 DF, p-value: 1.413e-15