• Aucun résultat trouvé

Mise en forme de la fenêtre "graphique" : agencements complexes de figures

N/A
N/A
Protected

Academic year: 2022

Partager "Mise en forme de la fenêtre "graphique" : agencements complexes de figures"

Copied!
14
0
0

Texte intégral

(1)

SEMIN-

Mise en forme de la fenêtre "graphique" : agencements complexes de figures

Caroline SIMONIS

Muséum national d'Histoire naturelle

Département Écologie et Gestion de la Biodiversité MNHN USM 301 & CNRS UMR 7179

csimonis@mnhn.fr

SEMIN-R du MNHN | 8 Avril 2008

(2)

SUPERPOSITION DE GRAPHIQUES

2 4 6 8 10

246810

Index

x

2 4 6 8 10

246810

Index

x

Pour superposer successivement des graphiques, il faut utiliser par ( new = TRUE ) entre chaque graphique.

x<-1:10

plot(x,cex=x,col=x) par(new=TRUE)

plot(x,cex=rev(x),col=x)

Attention aux échelles !! Il s'agit d'un superposition brute…

# 1≤x≤10, par défaut ylim=c(1,10) plot(x,cex=x,col=x)

par(new=TRUE)

# 2≤2*x≤20, par défaut ylim=c(2,20) plot(2*x,cex=rev(x),col=x)

plot(x,cex=x,col=x, ylim=c(1,20)) par(new=TRUE)

plot(2*x,cex=rev(x),col=x,ylim=c(1,20))

2 4 6 8 10

246810

Index

x

2 4 6 8 10

5101520

Index

2 * x

2 4 6 8 10

5101520

Index

x

2 4 6 8 10

5101520

Index

2 * x

(3)

DIVISION DE LA FENETRE GRAPHIQUE (1)

DIVISION DE LA FENETRE GRAPHIQUE (1)

La fenêtre peut être divisée en sous-ensembles de tailles égales avec les arguments mcol ou mfrow de par()

mfcol, mfrow

A vector of the form c(nr, nc). Subsequent figures will be drawn in an nr-by-nc array on the device by columns (mfcol), or rows (mfrow), respectively. [...]

1

2

1 2

3 4

par(mfrow=c(2,1))

# ou

par(mfcol=c(2,1))

par(mfrow=c(2,2))

1 2

1 3

2 4

par(mfrow=c(1,2))

# ou

par(mfcol=c(1,2))

par(mfcol=c(2,2))

(4)

DIVISION DE LA FENETRE GRAPHIQUE (2)

024681012

Associations Graphiques

par(mfrow(2,2))

-2 -1 0 1

-2-1012

x

y

0 2 4 6 8 10

1 2

3 4

# avec par(mfrow=c(2,2))

# case 1

barplot(hist(x,plot=F)$counts,

col=rgb(255,157,36,max=255))

# case 2 plot.new()

title(main="Associations Graphiques", sub="par(mfrow(2,2))",

line=-5)

# case 3

plot(x,y,pch=20,

col=rgb(192,31,99,max=255))

# case 4

barplot(hist(y,plot=F)$counts,horiz=T, col=rgb(138,173,14,max=255)) x<-rnorm(50);y<-rnorm(50)

par(mfrow=c(2,2))

voir les arguments mar et oma de par()

de type c(bottom, left, top, right)

(5)

DIVISION DE LA FENETRE GRAPHIQUE (3)

Vers une mise en page plus complexe…

split.screen() ; screen() ; erase.screen() ; close.screen() These functions are totally incompatible with the other mechanisms for arranging plots on a device: par(mfrow), par(mfcol) and layout().

x<-rnorm(50);y<-rnorm(50);z<-rnorm(50)

# division de la fenêtre

2 lignes & 1 colonne : split.screen(c(2,1)) # [1] 1 2

0 10 20 30 40 50

-2-101

Index

x

0 10 20 30 40 50

-2-1012

Index

y

0 10 20 30 40 50

-2-1012

Index

z

# division de la sous-fenêtre 1 ligne & 2 colonnes : split.screen(c(1,2),2) # [1] 3 4

1

2

1

2

1

2 3

1

3 4

screen(1) ; plot(x) screen(3) ; plot(y) screen(4) ; plot(z)

(6)

DIVISION DE LA FENETRE GRAPHIQUE (2)

DIVISION DE LA FENETRE GRAPHIQUE (4)

Un pas supplémentaire vers la complexité, utilisation de la fonction layout () layout

divides the device up into as many rows and columns as there are in matrix mat, with the column-widths and the row-heights specified in the respective arguments. [...]

# cas simple équivalent à par(mfrow=c(2,2)) m<-

matrix(1:4,nrow=2,ncol=2,byrow=TRUE) m

# [,1] [,2]

#[1,] 1 2

#[2,] 3 4 layout(m)

layout.show(4)

1 2

3 4

Conseil

: pour les matrices plus complexes, prenez le temps de la dessiner

(7)

DIVISION DE LA FENETRE GRAPHIQUE (5)

2 4 6 8 10

246810

Index

1:10

2 4 6 8 10

246810

Index

1:10

2 4 6 8 10

68101214

Index

5:15

2 4 6 8 10

68101214

Index

5:15

# case 1

plot(1:10,pch=21, bg=R,cex=2)

# exemple 1 :

layout(matrix(1:4,nrow=2,ncol=2,byrow=TRUE))

# case 4

plot(5:15,pch=24, bg=V,cex=2)

# case 3

plot(5:15,pch=23, bg=O,cex=2)

# case 2

plot(1:10,pch=22, bg=C,cex=2)

# code couleur

O<-rgb(255,157,36,max=255) R<-rgb(192,31,99,max=255) V<-rgb(138,173,14,max=255) C<-rgb(147,209,228,max=255)

(8)

246810

1:10

2 4 6 8 10

68101214

Index

5:15

2 4 6 8 10

Index

# case 1

par(mar=c(0,4,4,0)) plot(1:10,pch=21,

bg=R,cex=2,

xaxt="n",xlab="")

DIVISION DE LA FENETRE GRAPHIQUE (6)

# exemple 1bis :

layout(matrix(1:4,nrow=2,ncol=2,byrow=TRUE)) par(oma=c(1,1,0,0))

# case 2

par(mar=c(0,0,4,4)) plot(1:10,pch=22,

bg=C,cex=2,

xaxt="n",xlab="", yaxt="n",ylab="")

# case 3

par(mar=c(4,4,0,0)) plot(5:15,pch=23,

bg=O,cex=2,)

# case 4

par(mar=c(4,0,0,4)) plot(5:15,pch=24,

bg=V,cex=2,

yaxt="n",ylab="")

(9)

DIVISION DE LA FENETRE GRAPHIQUE (7)

# exemple 2 équivalent à l'exemple split.screen()

2 4 6 8 10

246810

Index

1:10

1

2

3 4

2 4 6 8 10

68101214

Index

5:15

m<-matrix(c(1,1,2,3),2,2,byrow=TRUE) m

# [,1] [,2]

#[1,] 1 1

#[2,] 2 3

# case 3

plot(5:15,pch=23,

bg=O,cex=2,type="b") layout(m)

layout.show(3)

# case 1

plot(1:10,pch=21,bg=R,cex=2)

# case 2

pie(c(0.5,0.25,0.1,0.15), col=c(R,C,O,V))

(10)

DIVISION DE LA FENETRE GRAPHIQUE (8)

1 2

3

1 2

3 0

# exemple 3 :

layout(matrix(c(1,2,3,0),2,2,byrow=TRUE), widths=c(3,1),heights=c(3,1))

layout.show(3)

# exemple 3 bis :

layout(matrix(c(1,2,3,0),2,2,byrow=TRUE), widths=c(3,1),heights=c(3,1))

# création d'une marge extérieure : par(oma=c(2,1,1,1))

layout.show(3)

1 2

3

1 2

3 0

(11)

DIVISION DE LA FENETRE GRAPHIQUE (9)

# exemple 4 :

-10123

variable y

-3 -2 -1 0 1 2 3

variable x

layout(matrix(c(1,2,3,0),2,2,byrow=TRUE), widths=c(3,1),heights=c(3,1))

par(oma=c(2,1,1,1)) layout.show(3)

# case 3

par(mar=c(2,4,0,0))

boxplot(x,horizontal=TRUE,col=O)

# case 1

par(mar=c(0,4,0,0)) plot(x,y,pch=20,col=R,

xaxt="n",xlab="", ylab="variable y", cex.lab=1.5)

# case 2

par(mar=c(0,0,0,1))

boxplot(y,col=V,yaxt="n",ylab="") x<-rnorm(50);y<-rnorm(50)

# ajout de la légende axe des X

mtext("variable x",side=1,outer=TRUE,at=0.4,cex=1.5)

(12)

DIVISION DE LA FENETRE GRAPHIQUE (10)

0 5 10 15 20 25

0.00.10.20.30.40.5

Comment faire un encart (zoom)

N = 1000 Bandwidth = 0.2426

Density

0.0 0.2 0.4 0.6 0.8 1.0

0.500.520.540.560.580.60

m<-matrix(c(1,2,1,1),ncol=2,byrow=T) m

# [,1] [,2]

# [1,] 1 2

# [2,] 1 1

layout(m,widths=c(1.25,1)) layout.show(2)

# exemple 5 : ZOOM

plot(density(x),main="Comment faire un encart (zoom)") x<-rlnorm(1000)

# distribution lognormale -> distribution asymétrique

plot(density(x),xlim=c(0,1),ylim=c(0.5,0.6),xlab="",ylab="",main="")

(13)

DIVISION DE LA FENETRE GRAPHIQUE (11)

1

2

3

4

5

0

0

3

3

3

1

1

3

3

3

0

0

3

3

3

0

2

2

0

5

4

2

2

0

5

m<-matrix(c(0,0,3,3,3,1,1,3,3,3,0,0,3,3,3,0,2,2,0,5,4,2,2,0,5),

ncol=5,nrow=5,byrow=FALSE) m

# [,1] [,2] [,3] [,4] [,5]

#[1,] 0 1 0 0 4

#[2,] 0 1 0 2 2

#[3,] 3 3 3 2 2

#[4,] 3 3 3 0 0

#[5,] 3 3 3 5 5 layout(m); layout.show(5)

# exemple 6 : …

1

3

4 2

5

(14)

SEMIN-

# Liens utiles :

http://cran.r-project.org/doc/contrib/Paradis-rdebuts_fr.pdf

"R pour les Débutants" by Emmanuel Paradis, the french version of "R for Beginners"

Ö

chap. 4 Les graphiques avec R (p.38-58)

http://addictedtor.free.fr/graphiques

R Graph Gallery by François Romain

Références

Documents relatifs

un chemin un chemin un chemin un cheval une cheminée une cheminée une cheminée des cheveux. une chemise une chemise une chemise

une cheminée une cheminée une cheminée des cheveux une chemise une chemise une chemise

[r]

1) Dans la Barre système, cliquer sur Repère, c’est l’icône pour créer un repère (fig 1)... 2) Dans la Barre de travail (sous menu de l’icône Repère) le logiciel

Pour observer l’interaction entre le ligand et le récepteur vous pouvez utiliser comme précédemment la fonctionnalité « Plan de coupe » dans le menu « Réglages » en haut à

Cliquer sur le numéro de ligne ou la tête de colonne Sélectionner la feuille entière:. Cliquer sur le bouton

3/ Dans la partie centrale de l’éditeur de formulaire (design) cliquer dans la barre de menu pour créer un menu principal Fichier et une commande Quitter. On le

Il n’est pas d’objet plus profond, plus mystérieux, plus fécond, plus ténébreux, plus éblouissant qu’une fenêtre éclairée d’une chandelle. Ce qu’on peut voir au