<?xml version="1.0" encoding="UTF-8" ?>
<!-- RSS generated by PHPBoost on Wed, 22 Apr 2026 11:56:21 +0200 -->

<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title><![CDATA[Derniers articles - STHDA]]></title>
		<atom:link href="https://www.sthda.com/french/syndication/rss/articles/" rel="self" type="application/rss+xml"/>
		<link>https://www.sthda.com</link>
		<description><![CDATA[Derniers articles - STHDA]]></description>
		<copyright>(C) 2005-2026 PHPBoost</copyright>
		<language>fr</language>
		<generator>PHPBoost</generator>
		
		
		<item>
			<title><![CDATA[Gestionnaires de Mot de Passe: Solution pour Windows, MAC OSX et Linux]]></title>
			<link>https://www.sthda.com/french/articles/37-autres/72-gestionnaires-de-mot-de-passe-solution-pour-windows-mac-osx-et-linux/</link>
			<guid>https://www.sthda.com/french/articles/37-autres/72-gestionnaires-de-mot-de-passe-solution-pour-windows-mac-osx-et-linux/</guid>
			<description><![CDATA[Cet article pr?sente le logiciel <a href="http://keepass.info/"><strong>keepass</strong></a>, un <strong>gestionnaires de mot de passe</strong> pour Windows.<br />
<br />
Vous pouvez t?l?charger le tutoriel cr?? par Boris Rigault (CNRS, IBMM) en cliquant sur le lien suivant:  <a href="https://www.sthda.com/french/french/upload/keepass-gestionnaire-de-mot-de-passe.pdf">Keepass-gestionnaire-de-mot-de-passe.pdf</a><br />
<br />
Il existe l??quivalent de Keepass pour OSX et Linux : <strong>Keepass X</strong>]]></description>
			<pubDate>Tue, 18 Jul 2017 11:27:00 +0200</pubDate>
			
		</item>
		
		<item>
			<title><![CDATA[Transf?rer des fichiers]]></title>
			<link>https://www.sthda.com/french/articles/22-linux/71-transferer-des-fichiers/</link>
			<guid>https://www.sthda.com/french/articles/22-linux/71-transferer-des-fichiers/</guid>
			<description><![CDATA[L'objectif de cet article est de vous montrer comment t?l?charger, transfert des fichiers, synchroniser deux r?pertoires ? partir de linux.<br />
<br />
<h2 class="formatter-title">wget : t?l?chargement de fichiers</h2><br />
<br />
Il suffit d'indiquer l?adresse HTTP ou FTP d'un fichier ? t?l?charger :<br />
<span class="formatter-code">Code BASH :</span><div class="code"><pre style="display:inline;"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">wget</span> http:<span style="color: #000000; font-weight: bold;">//</span>www.ubuntu-fr.org<span style="color: #000000; font-weight: bold;">/</span>telechargement?<span style="color: #007800;">action</span>=dl</pre></pre></div><br />
<span class="warning">Pour arr?ter le t?l?chargement : Ctrl + c</span><br />
Pour reprendre un t?l?chargement arr?t?, utiliser l'option -c :<br />
<span class="formatter-code">Code BASH :</span><div class="code"><pre style="display:inline;"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">wget</span> <span style="color: #660033;">-c</span> http:<span style="color: #000000; font-weight: bold;">//</span>www.ubuntu-fr.org<span style="color: #000000; font-weight: bold;">/</span>telechargement?<span style="color: #007800;">action</span>=dl</pre></pre></div><br />
<br />
Lancer un t?l?chargement en tache de fond :<br />
- Utiliser la technique <strong>nohup</strong> qui s'applique ? toutes les commandes<br />
- Utiliser l'option --background<br />
<br />
<span class="formatter-code">Code BASH :</span><div class="code"><pre style="display:inline;"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">wget</span> <span style="color: #660033;">--background</span> <span style="color: #660033;">-c</span> http:<span style="color: #000000; font-weight: bold;">//</span>www.ubuntu-fr.org<span style="color: #000000; font-weight: bold;">/</span>telechargement?<span style="color: #007800;">action</span>=dl</pre></pre></div><br />
<span class="success">wget propose pas mal d'options. Faire man wget pour voir les options. </span><br />
<br />
<h2 class="formatter-title">scp : copier des fichiers ? travers le r?seau</h2><br />
<br />
scp = secure copy<br />
<span class="formatter-code">Code BASH :</span><div class="code"><pre style="display:inline;"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">scp</span> fichier_origine copie_destination</pre></pre></div><br />
<strong><span style="color:#000080;">Copier un fichier de votre ordinateur vers un autre :</span></strong><br />
<span class="formatter-code">Code BASH :</span><div class="code"><pre style="display:inline;"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">scp</span> image.png akassambara<span style="color: #000000; font-weight: bold;">@</span>85.123.10.201:~<span style="color: #000000; font-weight: bold;">/</span>images<span style="color: #000000; font-weight: bold;">/</span></pre></pre></div><br />
<span class="success">Remplacer l'IP par le nom d'h?te</span><br />
<br />
<br />
<strong><span style="color:#000080;">Copier plusieurs fichiers de votre ordinateur vers un autre :</span></strong><br />
<br />
- Utiliser l'option -r (recursif) en pr?cisant le dossier : <br />
<span class="formatter-code">Code BASH :</span><div class="code"><pre style="display:inline;"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">scp</span> <span style="color: #660033;">-r</span> mon_dossier akassambara<span style="color: #000000; font-weight: bold;">@</span>85.123.10.201:~<span style="color: #000000; font-weight: bold;">/</span>images<span style="color: #000000; font-weight: bold;">/</span></pre></pre></div><br />
<br />
<br />
<strong><span style="color:#000080;">Copier un fichier d'un autre ordinateur vers le v?tre:</span></strong><br />
<span class="formatter-code">Code BASH :</span><div class="code"><pre style="display:inline;"><pre class="bash" style="font-family:monospace;">&nbsp;
<span style="color: #c20cb9; font-weight: bold;">scp</span> akassambara<span style="color: #000000; font-weight: bold;">@</span>85.123.10.201:image.png copie_image_sur_mon_pc.png
<span style="color: #666666; font-style: italic;">#Copier le fichier sans  changer le nom :</span>
<span style="color: #c20cb9; font-weight: bold;">scp</span> akassambara21<span style="color: #000000; font-weight: bold;">@</span>85.123.10.201:image.png 
&nbsp;</pre></pre></div><br />
<br />
<span class="warning">Si le serveur SSH auquel vous essayez de vous connecter n'est pas sur le port standard (22), il faudra indiquer le num?ro du port avec l'option -P :</span><br />
<span class="formatter-code">Code BASH :</span><div class="code"><pre style="display:inline;"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">scp</span> <span style="color: #660033;">-P</span> <span style="color: #000000;">16296</span> akassambara<span style="color: #000000; font-weight: bold;">@</span>85.123.10.201:image.png .</pre></pre></div><br />
<br />
<br />
<h2 class="formatter-title">ftp & sftp : transf?rer des fichiers</h2><br />
Le FTP (File Transfer Protocol) est un protocole permettant d'?changer des fichiers sur le r?seau. La connexion peut se faire en mode anonyme (site public) ou authentifi? (site priv?)<br />
<span class="formatter-code">Code BASH :</span><div class="code"><pre style="display:inline;"><pre class="bash" style="font-family:monospace;">&nbsp;
<span style="color: #666666; font-style: italic;">#Connexion au serveur debian</span>
<span style="color: #c20cb9; font-weight: bold;">ftp</span> ftp.debian.org
<span style="color: #c20cb9; font-weight: bold;">ls</span> <span style="color: #666666; font-style: italic;">#Afficher le contenu du repertoire </span>
<span style="color: #7a0874; font-weight: bold;">pwd</span> <span style="color: #666666; font-style: italic;">#chemin du r?pertoire actuel</span>
<span style="color: #7a0874; font-weight: bold;">cd</span> <span style="color: #666666; font-style: italic;"># Changer de r?pertoire</span>
&nbsp;</pre></pre></div><br />
<br />
<h3 class="formatter-title">Transfert des fichiers</h3><br />
<br />
<strong>put</strong> : envoie un fichier vers le server<br />
<strong>get</strong> : t?l?charge un fichier depuis le serveur.<br />
<br />
Vous pouvez par exemple r?cup?rer le fichier README :<br />
<span class="formatter-code">Code BASH :</span><div class="code"><pre style="display:inline;"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">ftp</span> get README </pre></pre></div><br />
<br />
Le fichier est t?l?charg? dans le dossier dans lequel vous vous trouviez sur votre ordinateur.<br />
<br />
<span class="formatter-code">Code BASH :</span><div class="code"><pre style="display:inline;"><pre class="bash" style="font-family:monospace;"> <span style="color: #c20cb9; font-weight: bold;">ftp</span><span style="color: #000000; font-weight: bold;">></span> <span style="color: #000000; font-weight: bold;">!</span><span style="color: #7a0874; font-weight: bold;">pwd</span> <span style="color: #666666; font-style: italic;"># Pour savoir dans quel dossier vous ?tes chez vous</span></pre></pre></div><br />
<br />
<span class="warning">Pour quitter la session : Ctrl + D</span><br />
<br />
<h3 class="formatter-title">sftp : Transfert s?curis?</h3><br />
<br />
Requiert un mot de passe<br />
<br />
<span class="formatter-code">Code BASH :</span><div class="code"><pre style="display:inline;"><pre class="bash" style="font-family:monospace;">sftp <span style="color: #c20cb9; font-weight: bold;">login</span><span style="color: #000000; font-weight: bold;">@</span><span style="color: #c20cb9; font-weight: bold;">ip</span></pre></pre></div><br />
<br />
<span class="warning"><br />
Si votre serveur SSH fonctionne sur un autre port, vous devrez le pr?ciser comme ceci : sftp -oPort=27401 login@serveur.<br />
</span><br />
<br />
<h2 class="formatter-title">rsync : synchroniser des fichiers pour une sauvegarde</h2><br />
<br />
<strong><span style="color:#333399;">rsync</span></strong> permet d'effectuer une synchronisation entre deux r?pertoires, que ce soit sur le m?me PC ou entre deux ordinateurs reli?s en r?seau.<br />
<br />
<span class="formatter-code">Code BASH :</span><div class="code"><pre style="display:inline;"><pre class="bash" style="font-family:monospace;">C<span style="color: #ff0000;">'est une sorte de scp intelligent : il compare et analyse les diff?rences entre deux dossiers puis copie uniquement les changements.</span></pre></pre></div><br />
<br />
<h3 class="formatter-title">Synchroniser deux dossiers du m?me ordinateur</h3><br />
<br />
Le contenu du dossier images est sauvegard? dans le dossier backups:<br />
<span class="formatter-code">Code BASH :</span><div class="code"><pre style="display:inline;"><pre class="bash" style="font-family:monospace;">&nbsp;
rsync <span style="color: #660033;">-arv</span> <span style="color: #660033;">--delete</span> Images<span style="color: #000000; font-weight: bold;">/</span> backups<span style="color: #000000; font-weight: bold;">/</span>
&nbsp;</pre></pre></div><br />
<br />
<span class="success"><br />
    -a : conserve toutes les informations sur les fichiers, comme les droits (chmod), la date de modification, etc. ;<br />
    -r : sauvegarde aussi tous les sous-dossiers qui se trouvent dans le dossier ? sauvegarder ;<br />
    -v : mode verbeux, affiche des informations d?taill?es sur la copie en cours.<br />
    --delete : pour que le contenu soit strictement identique. Lorsqu'un fichier a ?t? supprimer dans le r?pertoire d'origine, il le sera ?galement dans le r?pertoire de sauvegarde.<br />
</span><br />
<br />
<strong><span style="color:#000080;">Pour mettre les fichiers supprimer dans "un dossier corbeille" au cas ou : </span></strong><br />
Ajouter l'option : --backup --backup-dir=~/kass/backups_supprimes<br />
<br />
<span class="formatter-code">Code BASH :</span><div class="code"><pre style="display:inline;"><pre class="bash" style="font-family:monospace;">&nbsp;
 rsync <span style="color: #660033;">-arv</span> <span style="color: #660033;">--delete</span> <span style="color: #660033;">--backup</span> <span style="color: #660033;">--backup-dir</span>=~<span style="color: #000000; font-weight: bold;">/</span>kass<span style="color: #000000; font-weight: bold;">/</span>backups_supprimes Images<span style="color: #000000; font-weight: bold;">/</span> backups<span style="color: #000000; font-weight: bold;">/</span>
&nbsp;</pre></pre></div><br />
<br />
<span class="warning">Indiquer le chemin absolu du dossier corbeille pour ?viter des probl?mes</span><br />
<br />
<h3 class="formatter-title">Sauvegarder sur un autre ordinateur</h3><br />
<span class="formatter-code">Code BASH :</span><div class="code"><pre style="display:inline;"><pre class="bash" style="font-family:monospace;">&nbsp;
rsync <span style="color: #660033;">-arv</span> <span style="color: #660033;">--delete</span> <span style="color: #660033;">--backup</span> <span style="color: #660033;">--backup-dir</span>=<span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/</span>kassambara<span style="color: #000000; font-weight: bold;">/</span>fichiers_supprimes Images<span style="color: #000000; font-weight: bold;">/</span> mateo21<span style="color: #000000; font-weight: bold;">@</span>IP_du_serveur:mes_backups<span style="color: #000000; font-weight: bold;">/</span>
&nbsp;</pre></pre></div><br />
<br />
Si votre serveur SSH ?coute sur un autre port que celui par d?faut, il faudra rajouter -e "ssh -p port" :<br />
<br />
<span class="formatter-code">Code BASH :</span><div class="code"><pre style="display:inline;"><pre class="bash" style="font-family:monospace;">&nbsp;
rsync <span style="color: #660033;">-arv</span> <span style="color: #660033;">--delete</span> <span style="color: #660033;">--backup</span> <span style="color: #660033;">--backup-dir</span>=<span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/</span>kass<span style="color: #000000; font-weight: bold;">/</span>fichiers_supprimes Images<span style="color: #000000; font-weight: bold;">/</span> kass<span style="color: #000000; font-weight: bold;">@</span>IP_du_serveur:mes_backups<span style="color: #000000; font-weight: bold;">/</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">"ssh -p 12473"</span>
&nbsp;</pre></pre></div>]]></description>
			<pubDate>Fri, 03 Oct 2014 16:14:00 +0200</pubDate>
			
		</item>
		
		<item>
			<title><![CDATA[Connaitre les capacit?s de l'ordinateur]]></title>
			<link>https://www.sthda.com/french/articles/22-linux/69-connaitre-les-capacites-de-l-ordinateur/</link>
			<guid>https://www.sthda.com/french/articles/22-linux/69-connaitre-les-capacites-de-l-ordinateur/</guid>
			<description><![CDATA[<h2 class="formatter-title">RAM</h2><br />
<br />
La commande free peut ?tre utilis?e pour conna?tre la RAM. Les options -b, -k, -m, -g donnent la m?moire en KB, MB ou GB<br />
<br />
L'option -t affiche la RAM totale+SWAP<br />
<br />
<span class="formatter-code">Code BASH :</span><div class="code"><pre style="display:inline;"><pre class="bash" style="font-family:monospace;">&nbsp;
<span style="color: #c20cb9; font-weight: bold;">free</span> <span style="color: #660033;">-tg</span>
&nbsp;</pre></pre></div><br />
<br />
<h2 class="formatter-title">Taille des disques</h2><br />
<br />
Utiliser la commande df -h<br />
<br />
<span class="formatter-code">Code BASH :</span><div class="code"><pre style="display:inline;"><pre class="bash" style="font-family:monospace;">&nbsp;
<span style="color: #c20cb9; font-weight: bold;">df</span> <span style="color: #660033;">-h</span>
&nbsp;</pre></pre></div><br />
<br />
<h2 class="formatter-title">Version de linux</h2><br />
<br />
<span class="formatter-code">Code BASH :</span><div class="code"><pre style="display:inline;"><pre class="bash" style="font-family:monospace;">&nbsp;
lsb_release <span style="color: #660033;">-a</span>
&nbsp;</pre></pre></div><br />
<br />
<h2 class="formatter-title">32 ou 64 bits</h2><br />
<br />
<span class="formatter-code">Code BASH :</span><div class="code"><pre style="display:inline;"><pre class="bash" style="font-family:monospace;">&nbsp;
<span style="color: #c20cb9; font-weight: bold;">uname</span> <span style="color: #660033;">-a</span>
&nbsp;</pre></pre></div><br />
<br />
<h2 class="formatter-title">Afficher le nombre de coeurs processeur sous Linux</h2><br />
<br />
<span class="formatter-code">Code BASH :</span><div class="code"><pre style="display:inline;"><pre class="bash" style="font-family:monospace;">&nbsp;
<span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #ff0000;">'model name'</span> <span style="color: #000000; font-weight: bold;">/</span>proc<span style="color: #000000; font-weight: bold;">/</span>cpuinfo <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">wc</span> <span style="color: #660033;">-l</span>
&nbsp;</pre></pre></div>]]></description>
			<pubDate>Wed, 24 Sep 2014 09:51:00 +0200</pubDate>
			
		</item>
		
		<item>
			<title><![CDATA[La console Linux]]></title>
			<link>https://www.sthda.com/french/articles/22-linux/66-la-console-linux/</link>
			<guid>https://www.sthda.com/french/articles/22-linux/66-la-console-linux/</guid>
			<description><![CDATA[[page]La console et les commandes de base[/page]<br />
<!-- START HTML -->
<ul id="toc"></ul>
<!-- END HTML --><br />
<br />
<h3 class="formatter-title">O? se trouve la console</h3><br />
<br />
<strong>Sous KDE</strong> : Rechercher <strong>Konsole</strong> dans le lanceur graphique<br />
<strong>Sous Unity</strong>: Rechercher <strong>Terminal</strong> dans le lanceur graphique<br />
<br />
<span class="notice">Pour acc?der ? distance ? distance ? un ordinateur (ou serveur) sous linux, on utilise le protocole SSH. PuTTY est un logiciel Windows qui permet d'acc?der ? une machine Linux depuis windows via le protocole SSH.</span><br />
<br />
<h3 class="formatter-title">Symboles affich?s sur la console</h3><br />
<br />
$: compte utilisateur normal avec des droits limit?s<br />
#: mode super-utilisateur<br />
<br />
<h3 class="formatter-title">Commandes et param?tres</h3><br />
<br />
<span class="formatter-code">Code BASH :</span><div class="code"><pre style="display:inline;"><pre class="bash" style="font-family:monospace;">&nbsp;
<span style="color: #c20cb9; font-weight: bold;">date</span> <span style="color: #666666; font-style: italic;">#Affiche la date</span>
<span style="color: #c20cb9; font-weight: bold;">ls</span> <span style="color: #666666; font-style: italic;">#Liste les fichiers et dossiers du r?pertoire actuel </span>
<span style="color: #c20cb9; font-weight: bold;">ls</span> <span style="color: #660033;">-a</span> <span style="color: #666666; font-style: italic;">#Affiche tout le contenu du dossier, m?me les fichiers cach?s</span>
<span style="color: #c20cb9; font-weight: bold;">ls</span> Examples <span style="color: #666666; font-style: italic;">#Affiche le contenu du dossier Examples</span>
<span style="color: #c20cb9; font-weight: bold;">clear</span> <span style="color: #666666; font-style: italic;">#Efface le contenu de la console</span>
<span style="color: #7a0874; font-weight: bold;">pwd</span> <span style="color: #666666; font-style: italic;">#Affiche le r?pertoire courant</span>
&nbsp;</pre></pre></div><br />
<br />
<h3 class="formatter-title">pwd et which: O? suis-je?</h3><br />
<br />
<span class="formatter-code">Code BASH :</span><div class="code"><pre style="display:inline;"><pre class="bash" style="font-family:monospace;">&nbsp;
<span style="color: #7a0874; font-weight: bold;">pwd</span> <span style="color: #666666; font-style: italic;">#renvoie le r?pertoire courant</span>
<span style="color: #c20cb9; font-weight: bold;">which</span> mysql <span style="color: #666666; font-style: italic;">#Renvoie l'emplacement du programme mysql (/usr/bin/mysql)</span>
<span style="color: #c20cb9; font-weight: bold;">which</span> <span style="color: #7a0874; font-weight: bold;">pwd</span> <span style="color: #666666; font-style: italic;">#Renvoie l'emplacement de la commande pwd (/bin/pwd)</span>
&nbsp;</pre></pre></div><br />
<br />
<h3 class="formatter-title">Lister les fichiers et dossiers</h3><br />
<br />
<span class="formatter-code">Code BASH :</span><div class="code"><pre style="display:inline;"><pre class="bash" style="font-family:monospace;">&nbsp;
<span style="color: #c20cb9; font-weight: bold;">ls</span> <span style="color: #666666; font-style: italic;">#Affiche la liste des fichiers et dossier du r?pertoire courant</span>
<span style="color: #c20cb9; font-weight: bold;">ls</span> <span style="color: #660033;">-a</span> <span style="color: #666666; font-style: italic;">#Afficher tous les fichiers et dossiers cach?s</span>
<span style="color: #c20cb9; font-weight: bold;">ls</span> <span style="color: #660033;">-F</span> <span style="color: #666666; font-style: italic;">#Rajoute ? la fin des ?l?ments un symbole pour qu'on puisse faire la distinction entre les dossiers, fichiers</span>
<span style="color: #c20cb9; font-weight: bold;">ls</span> <span style="color: #660033;">-l</span> <span style="color: #666666; font-style: italic;">#Liste d?taill?e (droits, nombre de liens physiques, propri?taire, groupe, taille en octets, date de derni?re modification, nom du fichier ou dossier)</span>
<span style="color: #c20cb9; font-weight: bold;">ls</span> <span style="color: #660033;">-lh</span> <span style="color: #666666; font-style: italic;">#Liste d?taill?e avec la taille indiqu?e en Ko, Mo, Go. (NB: h=human readable)</span>
<span style="color: #c20cb9; font-weight: bold;">ls</span> <span style="color: #660033;">-lt</span> <span style="color: #666666; font-style: italic;">#Trier par date de derni?re modification</span>
&nbsp;</pre></pre></div><br />
<br />
<span class="warning">En pratique, il est pr?f?rable de combiner -t avec -r. Ce qui renverse l'ordre d'affichage des fichiers afin d'avoir le dernier fichier modifi? en bas de la liste, c'est plus pratique ? l'usage dans la console.</span><br />
<br />
<span class="formatter-code">Code BASH :</span><div class="code"><pre style="display:inline;"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">ls</span> <span style="color: #660033;">-larth</span> <span style="color: #666666; font-style: italic;">#contient toutes les options que j'aime</span></pre></pre></div><br />
<br />
<h3 class="formatter-title">cd: Changer de dossier</h3><br />
<br />
<span class="formatter-code">Code BASH :</span><div class="code"><pre style="display:inline;"><pre class="bash" style="font-family:monospace;">&nbsp;
<span style="color: #7a0874; font-weight: bold;">cd</span> <span style="color: #000000; font-weight: bold;">/</span> <span style="color: #666666; font-style: italic;">#Aller ? la racine</span>
<span style="color: #7a0874; font-weight: bold;">cd</span> usr<span style="color: #000000; font-weight: bold;">/</span>games <span style="color: #666666; font-style: italic;">#Aller dans le dossier games</span>
<span style="color: #7a0874; font-weight: bold;">cd</span> .. <span style="color: #666666; font-style: italic;">#Revenir au dossier pr?c?dent (usr)</span>
<span style="color: #7a0874; font-weight: bold;">cd</span> ..<span style="color: #000000; font-weight: bold;">/</span>.. <span style="color: #666666; font-style: italic;">#Permet de reculer de deux dossiers parents</span>
<span style="color: #7a0874; font-weight: bold;">cd</span> ~ <span style="color: #666666; font-style: italic;">#Retour au r?pertoire parent </span>
&nbsp;</pre></pre></div><br />
<br />
<span class="warning">Le nom du dossier peut ?tre automatiquement compl?t? par la console. Taper par exemple : cd /usr/ga puis appuyer sur Tab. La commande est compl?t?e ? cd /usr/games</span><br />
<br />
<h3 class="formatter-title">du: taille occup?e par les dossiers </h3><br />
<br />
<strong>du</strong>: disk usage<br />
<br />
<br />
<span class="formatter-code">Code BASH :</span><div class="code"><pre style="display:inline;"><pre class="bash" style="font-family:monospace;">&nbsp;
<span style="color: #7a0874; font-weight: bold;">cd</span>  <span style="color: #666666; font-style: italic;">#on se place dans le r?pertoire home</span>
<span style="color: #c20cb9; font-weight: bold;">du</span> <span style="color: #666666; font-style: italic;">#Affiche la taille en octets des dossiers (uniquement) du r?pertoire actuel</span>
<span style="color: #c20cb9; font-weight: bold;">du</span> <span style="color: #660033;">-h</span> <span style="color: #666666; font-style: italic;">#taille pour les humains (en Ko, Mo, Go)</span>
<span style="color: #c20cb9; font-weight: bold;">du</span> <span style="color: #660033;">-a</span> <span style="color: #666666; font-style: italic;">#Affiche la taille des dossiers ET des fichiers</span>
<span style="color: #c20cb9; font-weight: bold;">du</span> <span style="color: #660033;">-sh</span> <span style="color: #666666; font-style: italic;">#Affiche la taille totale occup?e par le dossier actuel.</span>
&nbsp;</pre></pre></div><br />
<br />
[page]Manipuler les fichiers[/page]<br />
<!-- START HTML -->
<ul id="toc"></ul>
<!-- END HTML --><br />
<br />
<h3 class="formatter-title">cat & less : afficher un fichier </h3><br />
<br />
<h4 class="formatter-title">cat : afficher tout le fichier</h4><br />
<br />
Nous allons travailler sur un fichier qui existe d?j? : syslog (dans le dossier /var/log).<br />
<br />
<span class="formatter-code">Code BASH :</span><div class="code"><pre style="display:inline;"><pre class="bash" style="font-family:monospace;">&nbsp;
<span style="color: #7a0874; font-weight: bold;">cd</span> <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>log <span style="color: #666666; font-style: italic;">#on se place dans le dossier log</span>
<span style="color: #c20cb9; font-weight: bold;">ls</span> <span style="color: #666666; font-style: italic;">#affiche le contenu du dossier log</span>
<span style="color: #c20cb9; font-weight: bold;">cat</span> syslog <span style="color: #666666; font-style: italic;">#Affiche tout le contenu du fichier  syslog dans la console d'un coup</span>
<span style="color: #c20cb9; font-weight: bold;">cat</span> <span style="color: #660033;">-n</span> syslog <span style="color: #666666; font-style: italic;">#Affiche le contenu du fichier en indiquant le num?ro de ligne</span>
&nbsp;</pre></pre></div><br />
<br />
<span class="warning">La commande <strong>cat</strong> vous envoie tout le fichier ? la figure. Elle est plus adapt?e lorsque l'on travaille sur de petits fichiers que sur des gros.</span><br />
<br />
<h4 class="formatter-title">less : afficher le fichier page par page</h4><br />
<br />
<strong>less</strong> affiche progressivement le contenu du fichier, page par page<br />
<br />
<span class="formatter-code">Code BASH :</span><div class="code"><pre style="display:inline;"><pre class="bash" style="font-family:monospace;">&nbsp;
<span style="color: #c20cb9; font-weight: bold;">less</span> syslog
&nbsp;</pre></pre></div><br />
<br />
Pour lire la suite, il y a des raccourcis clavier ? connaitre:<br />
<br />
<ul class="formatter-ul">
<li class="formatter-li">Espace : Affiche la suite du fichier.
</li><li class="formatter-li">Entr?e : Affiche la ligne suivante.Vous pouvez aussi utiliser la fl?che vers le bas.
</li><li class="formatter-li">d : affiche les onze lignes suivantes (soit une moiti? d'?cran).
</li><li class="formatter-li">b : retourne en arri?re d'un ?cran.
</li><li class="formatter-li">y : retourne d'une ligne en arri?re. Vous pouvez aussi appuyer sur la touche Fl?che vers le haut.
</li><li class="formatter-li">u : retourne en arri?re d'une moiti? d'?cran (onze lignes).
</li><li class="formatter-li">q : arr?te la lecture du fichier. Cela met fin ? la commande less.<br />
</li></ul><br />
<br />
<h4 class="formatter-title">Quelques raccourcis plus avanc?s</h4><br />
<br />
<ul class="formatter-ul">
<li class="formatter-li">= : indique o? vous en ?tes dans le fichier (num?ro des lignes affich?es et pourcentage).
</li><li class="formatter-li">h : affiche l'aide (toutes les commandes que je vous apprends ici, je les tire de l?). Tapez q pour sortir de l'aide.
</li><li class="formatter-li">/ : tapez / suivi du texte que vous recherchez pour lancer le mode recherche. Faites Entr?e pour valider. Pour ceux qui savent s'en servir, sachez que les expressions r?guli?res sont accept?es.
</li><li class="formatter-li">n : apr?s avoir fait une recherche avec /, la touche n vous permet d'aller ? la prochaine occurrence de votre recherche.
</li><li class="formatter-li">N : pareil que n, mais pour revenir en arri?re.<br />
</li></ul><br />
<br />
<h3 class="formatter-title">head & tail : afficher le d?but et la fin d'un fichier </h3><br />
<br />
<span class="formatter-code">Code BASH :</span><div class="code"><pre style="display:inline;"><pre class="bash" style="font-family:monospace;">&nbsp;
<span style="color: #7a0874; font-weight: bold;">cd</span> <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>log <span style="color: #666666; font-style: italic;">#on se place dans le dossier log</span>
<span style="color: #c20cb9; font-weight: bold;">head</span> syslog <span style="color: #666666; font-style: italic;">#Affiche juste les premi?res lignes du fichier. Ne permet pas de se d?placer dans le fichier comme less</span>
<span style="color: #c20cb9; font-weight: bold;">head</span> <span style="color: #660033;">-n</span> <span style="color: #000000;">3</span> syslog <span style="color: #666666; font-style: italic;">#Affiche les 3 premi?res lignes du fichier</span>
<span style="color: #c20cb9; font-weight: bold;">tail</span> syslog <span style="color: #666666; font-style: italic;">#affiche les derni?res lignes du fichier</span>
<span style="color: #c20cb9; font-weight: bold;">tail</span> <span style="color: #660033;">-n</span> <span style="color: #000000;">3</span> <span style="color: #666666; font-style: italic;">#Affiche les 3 derni?res lignes du fichier</span>
&nbsp;</pre></pre></div><br />
<br />
<span class="warning">Il y a un autre param?tre pour tail: -f (f pour follow). Ce param?tre ordonne ? tail de ? suivre ? la fin du fichier au fur et ? mesure de son ?volution. C'est un bon moyen de surveiller ce qui se passe en temps r?el sur un ordinateur. </span><br />
<br />
<span class="formatter-code">Code BASH :</span><div class="code"><pre style="display:inline;"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">tail</span> <span style="color: #660033;">-f</span> syslog</pre></pre></div><br />
<br />
<span class="success">Faites Ctrl + C (Ctrl et C en m?me temps) pour arr?ter la commande tail.</span><br />
<br />
Par exemple, les logs Apache du Site permettent de voir en temps r?el qui se connecte sur le site, avec quelle IP, quel fichier a ?t? charg?, ? quelle heure, etc.<br />
<br />
<span class="notice">Notez que par d?faut, tail -f recherche les nouveaux changements dans le fichier toutes les secondes. Si vous voulez, vous pouvez rajouter le param?tre -s suivi d'un nombre. Par exemple, tail -f -s 3 syslog recherchera les changements toutes les trois secondes (plut?t que toutes les secondes).</span><br />
<br />
<h3 class="formatter-title">touch & mkdir : cr?er des fichiers et dossiers </h3><br />
<br />
La commande touch est ? la base faite pour modifier la date de derni?re modification d'un fichier. Si le fichier n'existe pas, il sera cr??.<br />
<br />
<span class="formatter-code">Code BASH :</span><div class="code"><pre style="display:inline;"><pre class="bash" style="font-family:monospace;">&nbsp;
<span style="color: #7a0874; font-weight: bold;">cd</span> <span style="color: #666666; font-style: italic;"># on se place dans le home</span>
<span style="color: #c20cb9; font-weight: bold;">touch</span> fichier1.txt <span style="color: #666666; font-style: italic;"># cr?ation du fichier 1</span>
<span style="color: #c20cb9; font-weight: bold;">touch</span> fichier1.txt fichier2.txt <span style="color: #666666; font-style: italic;">#Cr?ation de deux fichiers en m?me temps</span>
<span style="color: #c20cb9; font-weight: bold;">touch</span> <span style="color: #ff0000;">"mon fichier.txt"</span> <span style="color: #666666; font-style: italic;"># le nom du fichier contient des espaces</span>
<span style="color: #c20cb9; font-weight: bold;">mkdir</span> dossier1.txt <span style="color: #666666; font-style: italic;">#cr?ation du dossier</span>
<span style="color: #c20cb9; font-weight: bold;">mkdir</span> dossier1.txt dossier2.txt <span style="color: #666666; font-style: italic;">#Cr?ation de deux dossiers en m?me temps</span>
<span style="color: #c20cb9; font-weight: bold;">mkdir</span> <span style="color: #660033;">-p</span> animaux<span style="color: #000000; font-weight: bold;">/</span>vertebres<span style="color: #000000; font-weight: bold;">/</span>chat <span style="color: #666666; font-style: italic;"># Le param?tre -p sert ? cr?er des dossiers interm?diaires (animaux puis vertebres dans animaux, puis chat dans vertebres). </span>
&nbsp;</pre></pre></div><br />
<br />
<h3 class="formatter-title">cp & mv : copier et d?placer un fichier </h3><br />
<br />
<h4 class="formatter-title">cp: copier des fichiers</h4><br />
<br />
<span class="formatter-code">Code BASH :</span><div class="code"><pre style="display:inline;"><pre class="bash" style="font-family:monospace;">&nbsp;
<span style="color: #666666; font-style: italic;">#copier dans le m?me dossier</span>
<span style="color: #c20cb9; font-weight: bold;">cp</span> fichier1.txt fichier1_copie.txt <span style="color: #666666; font-style: italic;"># param?tre 1: nom du fichier ? copier; param?tre 2: nom de la copie</span>
<span style="color: #666666; font-style: italic;">#copier dans un autre dossier</span>
<span style="color: #c20cb9; font-weight: bold;">cp</span> fichier1.txt mondossier<span style="color: #000000; font-weight: bold;">/</span> <span style="color: #666666; font-style: italic;">#fichier1.txt est copier vers "mondossier" sous le m?me nom</span>
<span style="color: #c20cb9; font-weight: bold;">cp</span> fichier1.txt mondossier<span style="color: #000000; font-weight: bold;">/</span>fichier2.txt <span style="color: #666666; font-style: italic;"># fichier1.txt est copier vers "mondossier" sous le nom fichier2.txt</span>
&nbsp;</pre></pre></div><br />
<br />
<h4 class="formatter-title">Copier des dossiers</h4><br />
<br />
<span class="formatter-code">Code BASH :</span><div class="code"><pre style="display:inline;"><pre class="bash" style="font-family:monospace;">&nbsp;
<span style="color: #666666; font-style: italic;">#Avec l'option -R, vous pouvez copier un dossier, ainsi que tous les sous-dossiers et fichiers qu'il contient !</span>
<span style="color: #c20cb9; font-weight: bold;">cp</span> <span style="color: #660033;">-R</span> dossier1 dossier2 <span style="color: #666666; font-style: italic;">#dossier1 est copi? sous le nom dossier2</span>
&nbsp;</pre></pre></div><br />
<br />
<h4 class="formatter-title">Utiliser le joker</h4><br />
<br />
<span class="formatter-code">Code BASH :</span><div class="code"><pre style="display:inline;"><pre class="bash" style="font-family:monospace;">&nbsp;
<span style="color: #c20cb9; font-weight: bold;">cp</span> <span style="color: #000000; font-weight: bold;">*</span>.jpg mondossier<span style="color: #000000; font-weight: bold;">/</span> <span style="color: #666666; font-style: italic;"># Copier tous les fichiers image .jpg dans un sous-dossier</span>
<span style="color: #c20cb9; font-weight: bold;">cp</span> so<span style="color: #000000; font-weight: bold;">*</span> mondossier<span style="color: #000000; font-weight: bold;">/</span> <span style="color: #666666; font-style: italic;">#Copier tous les fichiers dont le nom commence par ? so ?</span>
&nbsp;</pre></pre></div><br />
<br />
<br />
<h4 class="formatter-title">mv: Renommer/D?placer un fichier</h4><br />
<br />
<span class="success">mv s'utilise pratiquement comme cp et permet de d?placer ou de renommer un fichier/dossier</span><br />
<br />
<span class="formatter-code">Code BASH :</span><div class="code"><pre style="display:inline;"><pre class="bash" style="font-family:monospace;">&nbsp;
<span style="color: #c20cb9; font-weight: bold;">mv</span> fichier1.txt fichier2.txt <span style="color: #666666; font-style: italic;">#renommer un fichier</span>
<span style="color: #c20cb9; font-weight: bold;">mv</span> fichier1.txt mondossier<span style="color: #000000; font-weight: bold;">/</span> <span style="color: #666666; font-style: italic;">#fichier1.txt est d?placer vers un sous-dossier</span>
<span style="color: #c20cb9; font-weight: bold;">mv</span> fichier1.txt mondossier<span style="color: #000000; font-weight: bold;">/</span>fichier2.txt <span style="color: #666666; font-style: italic;"># fichier1.txt est d?placer dans le sous-dossier avec changement de nom</span>
<span style="color: #c20cb9; font-weight: bold;">mv</span> <span style="color: #000000; font-weight: bold;">*</span>.jpg mondossier<span style="color: #000000; font-weight: bold;">/</span> <span style="color: #666666; font-style: italic;">#d?place tous les fichiers image .jpg dans un sous-dossier</span>
&nbsp;</pre></pre></div><br />
<br />
<h4 class="formatter-title">rm : supprimer des fichiers et dossiers</h4><br />
<br />
<span class="formatter-code">Code BASH :</span><div class="code"><pre style="display:inline;"><pre class="bash" style="font-family:monospace;">&nbsp;
<span style="color: #c20cb9; font-weight: bold;">rm</span> fichier1.txt <span style="color: #666666; font-style: italic;"># supprime le fichier</span>
<span style="color: #c20cb9; font-weight: bold;">rm</span> fichier1.txt fichier2.txt <span style="color: #666666; font-style: italic;"># supprime plusieurs fichiers en m?me temps</span>
<span style="color: #c20cb9; font-weight: bold;">rm</span> <span style="color: #660033;">-i</span> fichier1.txt <span style="color: #666666; font-style: italic;"># Demande une confirmation lors de la suppression</span>
<span style="color: #c20cb9; font-weight: bold;">rm</span> <span style="color: #660033;">-f</span> fichier1.txt <span style="color: #666666; font-style: italic;"># Force la suppression quoi qu'il arrive</span>
<span style="color: #c20cb9; font-weight: bold;">rm</span> <span style="color: #660033;">-v</span> fichier1.txt <span style="color: #666666; font-style: italic;"># Verbose (parle beaucoup), montre l'avancement</span>
<span style="color: #c20cb9; font-weight: bold;">rm</span> <span style="color: #660033;">-r</span> dossier<span style="color: #000000; font-weight: bold;">/</span> <span style="color: #666666; font-style: italic;">#supprime un dossier et son contenu</span>
<span style="color: #c20cb9; font-weight: bold;">rm</span> <span style="color: #660033;">-rf</span> <span style="color: #000000; font-weight: bold;">*</span> <span style="color: #666666; font-style: italic;">#supprime tous les fichiers et sous-dossiers du dossier dans lequel je me trouve</span>
&nbsp;</pre></pre></div><br />
<br />
<br />
<h3 class="formatter-title">ln -s : Cr?er des liens symboliques entre fichiers</h3><br />
<br />
<span class="formatter-code">Code BASH :</span><div class="code"><pre style="display:inline;"><pre class="bash" style="font-family:monospace;">&nbsp;
<span style="color: #c20cb9; font-weight: bold;">ln</span> <span style="color: #660033;">-s</span> fichier1.txt fichier2.txt <span style="color: #666666; font-style: italic;">#fichier 2 repr?sente un raccourci de fichier 1</span>
&nbsp;</pre></pre></div><br />
<br />
[page]Les utilisateurs et les droits [/page]<br />
<br />
<h4 class="formatter-title">sudo: ex?cuter une commande en root </h4><br />
<br />
<span class="formatter-code">Code BASH :</span><div class="code"><pre style="display:inline;"><pre class="bash" style="font-family:monospace;">&nbsp;
<span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">ls</span> <span style="color: #666666; font-style: italic;">#ex?cuter une commande en tant que root</span>
<span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">su</span> <span style="color: #666666; font-style: italic;">#devenir root et le rester</span>
&nbsp;</pre></pre></div><br />
<br />
<span class="success">Pour quitter le ? mode root ?, tapez exit (ou faites la combinaison Ctrl + D).</span><br />
<br />
<h3 class="formatter-title">adduser : gestion des utilisateurs</h3><br />
<br />
<span class="formatter-code">Code BASH :</span><div class="code"><pre style="display:inline;"><pre class="bash" style="font-family:monospace;">&nbsp;
adduser patrick <span style="color: #666666; font-style: italic;">#ajout de l'utilisateur patrick; le mot de pass vous sera demand?</span>
<span style="color: #c20cb9; font-weight: bold;">passwd</span> patrick <span style="color: #666666; font-style: italic;">#changer le mot de passe de patrick</span>
deluser patrick <span style="color: #666666; font-style: italic;">#supprime l'utilisateur patrick sans confirmation</span>
deluser <span style="color: #660033;">--remove-home</span> patrick<span style="color: #666666; font-style: italic;"># supprime le repertoire personnel de patrick</span>
&nbsp;</pre></pre></div><br />
<br />
<h3 class="formatter-title">addgroup : gestion des groupes </h3><br />
<br />
<span class="formatter-code">Code BASH :</span><div class="code"><pre style="display:inline;"><pre class="bash" style="font-family:monospace;">&nbsp;
addgroup amis <span style="color: #666666; font-style: italic;">#ajouter un groupe d'utilisateur</span>
usermod <span style="color: #660033;">-g</span> amis patrick <span style="color: #666666; font-style: italic;">#ajouter patrick dans le groupe amis</span>
usermod <span style="color: #660033;">-g</span> patrick patrick <span style="color: #666666; font-style: italic;">#remettre patrick dans le groupe patrick comme il l'?tait avant</span>
delgroup amis <span style="color: #666666; font-style: italic;"># supprime le groupe amis</span>
&nbsp;</pre></pre></div><br />
<br />
<span class="warning"><br />
Il est aussi possible de faire en sorte qu'un utilisateur appartienne ? plusieurs groupes. Pour ce faire, utilisez le param?tre -G (majuscule).<br />
Exemple : usermod -G amis,paris,collegues patrick.<br />
S?parez les noms des groupes par une virgule, sans espace entre chaque nom de groupe.<br />
</span><br />
<br />
<span class="error"><br />
Faites tr?s attention en utilisant usermod ! Lorsque vous avez recours ? -G, l'utilisateur change de groupe et ce peu importe les groupes auxquels il appartenait auparavant.<br />
Si vous voulez ajouter des groupes ? un utilisateur (sans perdre les groupes auxquels il appartenait avant cela), utilisez -a :<br />
usermod -aG amis patrick<br />
</span><br />
<br />
<span class="success">addgroup et delgroup n'existent que sous Debian et ses d?riv?s (m?me remarque que pour adduser et deluser).<br />
Les commandes ? traditionnelles ? qui fonctionnent partout sont groupadd et groupdel, mais elles offrent moins d'options.</span><br />
<br />
<h3 class="formatter-title">chown: gestion des propri?taires d'un fichier </h3><br />
<br />
Commande utilis?e en tant que root<br />
<br />
<span class="formatter-code">Code BASH :</span><div class="code"><pre style="display:inline;"><pre class="bash" style="font-family:monospace;">&nbsp;
<span style="color: #c20cb9; font-weight: bold;">chown</span> patrick rapport.txt <span style="color: #666666; font-style: italic;">#patrick devient le propri?taire du fichier</span>
<span style="color: #c20cb9; font-weight: bold;">chgrp</span> amis rapport.txt <span style="color: #666666; font-style: italic;">#changer le groupe propri?taire d'un fichier</span>
<span style="color: #666666; font-style: italic;">#chown peut aussi changer le groupe propri?taire d'un fichier</span>
<span style="color: #c20cb9; font-weight: bold;">chown</span> patrick:amis rapport.txt <span style="color: #666666; font-style: italic;">#Cela affectera le fichier ? l'utilisateur patrick et au groupe amis.</span>
<span style="color: #666666; font-style: italic;">#-R : affecter r?cursivement les sous-dossiers</span>
<span style="color: #666666; font-style: italic;">#donner tout le contenu du dossier personnel de patrick ? mateo21 (et au groupe mateo21)</span>
<span style="color: #c20cb9; font-weight: bold;">chown</span> <span style="color: #660033;">-R</span> mateo21:mateo21 <span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/</span>patrick<span style="color: #000000; font-weight: bold;">/</span>
&nbsp;</pre></pre></div><br />
<br />
<h3 class="formatter-title">chmod : modifier les droits d'acc?s </h3><br />
<br />
<h4 class="formatter-title">Le fonctionnement des droits</h4><br />
<br />
<span class="formatter-code">Code BASH :</span><div class="code"><pre style="display:inline;"><pre class="bash" style="font-family:monospace;">&nbsp;
<span style="color: #666666;">mateo21@mateo21-desktop:~$ </span><span style="color: #c20cb9; font-weight: bold;">ls</span> <span style="color: #660033;">-l</span>
total <span style="color: #000000;">40</span>
drwxr-xr-x <span style="color: #000000;">2</span> mateo21 mateo21 <span style="color: #000000;">4096</span> <span style="color: #000000;">2007</span>-<span style="color: #000000;">11</span>-<span style="color: #000000;">13</span> <span style="color: #000000;">21</span>:<span style="color: #000000;">53</span> Desktop
drwxr-xr-x <span style="color: #000000;">2</span> mateo21 mateo21 <span style="color: #000000;">4096</span> <span style="color: #000000;">2007</span>-<span style="color: #000000;">11</span>-<span style="color: #000000;">13</span> <span style="color: #000000;">13</span>:<span style="color: #000000;">46</span> Documents
&nbsp;</pre></pre></div><br />
<br />
On peut voir cinq lettres diff?rentes. Voici leur signification :<br />
<br />
    <strong>d</strong> (Directory) : indique si l'?l?ment est un dossier ;<br />
   <strong> l</strong> (Link) : indique si l'?l?ment est un lien (raccourci) ;<br />
   <strong> r </strong>(Read) : indique si on peut lire l'?l?ment ;<br />
    <strong>w </strong>(Write) : indique si on peut modifier l'?l?ment ;<br />
    <strong>x </strong>(eXecute) : si c'est un fichier, ? x ? indique qu'on peut l'ex?cuter. Ce n'est utile que pour les fichiers ex?cutables (programmes et scripts).<br />
  <br />
Si la lettre appara?t, c'est que le droit existe. S'il y a un tiret ? la place, c'est qu'il n'y a aucun droit.<br />
<br />
Les droits sont d?coup?s en fonction des utilisateurs:<br />
 <img src="https://www.sthda.com/french/french/upload/droit_linux.png" alt="" /><br />
<br />
<ul class="formatter-ul">
<li class="formatter-li">le premier triplet rwx indique les droits que poss?de le propri?taire du fichier sur ce dernier ;
</li><li class="formatter-li">le second triplet rwx indique les droits que poss?dent les autres membres du groupe sur ce fichier ;
</li><li class="formatter-li">enfin, le dernier triplet rwx indique les droits que poss?dent tous les autres utilisateurs de la machine sur le fichier.<br />
</li></ul><br />
<br />
<h4 class="formatter-title">chmod : modifier les droits d'acc?s</h4><br />
    <br />
<strong>Attribuer des droits avec des chiffres (chmod absolu)</strong><br />
<br />
<table class="formatter-table">
<tr class="formatter-table-row">
<th class="formatter-table-head">Droit</th>
                <th class="formatter-table-head">Chiffre</th>
</tr>
<tr class="formatter-table-row">
<td class="formatter-table-col">r</td>
<td class="formatter-table-col">4</td>
</tr>
<tr class="formatter-table-row">
<td class="formatter-table-col">w</td>
<td class="formatter-table-col">2</td>
</tr>
<tr class="formatter-table-row">
<td class="formatter-table-col">x</td>
<td class="formatter-table-col">1</td>
</tr>
</table><br />
<br />
Si vous voulez combiner ces droits, il va falloir additionner les chiffres correspondants.<br />
<br />
Voici la liste des droits possibles et la valeur correspondante :<br />
<br />
<!-- START HTML -->

<table >
<thead>
<tr>
<th>
<p>Droits</p>
</th>
<th>
<p>Chiffre</p>
</th>
<th>
<p>Calcul</p>
</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<p>---</p>
</td>
<td>
<p>0</p>
</td>
<td>
<p>0 + 0 + 0</p>
</td>
</tr>
<tr>
<td>
<p>r--</p>
</td>
<td>
<p>4</p>
</td>
<td>
<p>4 + 0 + 0</p>
</td>
</tr>
<tr>
<td>
<p>-w-</p>
</td>
<td>
<p>2</p>
</td>
<td>
<p>0 + 2 + 0</p>
</td>
</tr>
<tr>
<td>
<p>--x</p>
</td>
<td>
<p>1</p>
</td>
<td>
<p>0 + 0 + 1</p>
</td>
</tr>
<tr>
<td>
<p>rw-</p>
</td>
<td>
<p>6</p>
</td>
<td>
<p>4 + 2 + 0</p>
</td>
</tr>
<tr>
<td>
<p>-wx</p>
</td>
<td>
<p>3</p>
</td>
<td>
<p>0 + 2 + 1</p>
</td>
</tr>
<tr>
<td>
<p>r-x</p>
</td>
<td>
<p>5</p>
</td>
<td>
<p>4 + 0 + 1</p>
</td>
</tr>
<tr>
<td>
<p>rwx</p>
</td>
<td>
<p>7</p>
</td>
<td>
<p>4 + 2 + 1</p>
</td>
</tr>
</tbody>
</table>

<!-- END HTML --><br />
<br />
Par exemple, ? 640 ? indique les droits du propri?taire, du groupe et des autres (dans l'ordre).<br />
<br />
    6 : droit de lecture et d'?criture pour le propri?taire.<br />
    4 : droit de lecture pour le groupe.<br />
    0 : aucun droit pour les autres.<br />
<br />
<span class="formatter-code">Code BASH :</span><div class="code"><pre style="display:inline;"><pre class="bash" style="font-family:monospace;">&nbsp;
<span style="color: #c20cb9; font-weight: bold;">chmod</span> <span style="color: #000000;">600</span> rapport.txt
&nbsp;</pre></pre></div><br />
<br />
<strong>Attribuer des droits avec des lettres (chmod relatif)</strong><br />
<br />
Dans ce mode, il faut savoir que :<br />
    <strong>u</strong> = user (propri?taire) ;<br />
    <strong>g</strong> = group (groupe) ;<br />
    <strong>o</strong> = other (autres).<br />
<br />
 et que :<br />
<br />
    + signifie : ? Ajouter le droit ? ;<br />
    - signifie : ? Supprimer le droit ? ;<br />
    = signifie : ? Affecter le droit ?.<br />
<br />
<span class="formatter-code">Code BASH :</span><div class="code"><pre style="display:inline;"><pre class="bash" style="font-family:monospace;">&nbsp;
<span style="color: #c20cb9; font-weight: bold;">chmod</span> g+<span style="color: #c20cb9; font-weight: bold;">w</span> rapport.txt <span style="color: #666666; font-style: italic;"># Ajouter le droit d'?criture au groupe</span>
<span style="color: #c20cb9; font-weight: bold;">chmod</span> o-r rapport.txt <span style="color: #666666; font-style: italic;">#Enlever le droit de lecture aux autres</span>
<span style="color: #c20cb9; font-weight: bold;">chmod</span> g+<span style="color: #c20cb9; font-weight: bold;">w</span>,o-w rapport.txt <span style="color: #666666; font-style: italic;">#Ajouter le droit d'?criture au groupe et l'enlever aux autres</span>
<span style="color: #c20cb9; font-weight: bold;">chmod</span> go-r rapport.txt <span style="color: #666666; font-style: italic;">#Enlever le droit de lecture au groupe et aux autres </span>
<span style="color: #c20cb9; font-weight: bold;">chmod</span> +x rapport.txt <span style="color: #666666; font-style: italic;">#Ajouter le droit d'ex?cution ? tout le monde</span>
<span style="color: #c20cb9; font-weight: bold;">chmod</span> <span style="color: #007800;">u</span>=rwx,<span style="color: #007800;">g</span>=r,<span style="color: #007800;">o</span>=- rapport.txt <span style="color: #666666; font-style: italic;">#Affecter tous les droits au propri?taire, juste la lecture au groupe, rien aux autres</span>
&nbsp;</pre></pre></div><br />
<br />
<strong>Et toujours? -R pour affecter r?cursivement</strong><br />
<br />
<span class="formatter-code">Code BASH :</span><div class="code"><pre style="display:inline;"><pre class="bash" style="font-family:monospace;">&nbsp;
<span style="color: #c20cb9; font-weight: bold;">chmod</span> <span style="color: #660033;">-R</span> <span style="color: #000000;">700</span> <span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/</span>mateo21
&nbsp;</pre></pre></div><br />
<br />
[page]Nano, ?diteur de texte du d?butant[/page]<br />
<!-- START HTML -->
<ul id="toc"></ul>
<!-- END HTML --><br />
<br />
<h3 class="formatter-title">Demarrage</h3><br />
<br />
Pour d?marrer le logiciel, il vous suffit simplement de taper nano dans la console :<br />
<br />
<span class="formatter-code">Code BASH :</span><div class="code"><pre style="display:inline;"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">nano</span></pre></pre></div><br />
<br />
D?s lors, vous pouvez commencer ? taper du texte.<br />
<br />
Voici les raccourcis les plus importants :<br />
    Ctrl + G : afficher l'aide ;<br />
    Ctrl + K : couper la ligne de texte (et la mettre dans le presse-papier) ;<br />
    Ctrl + U : coller la ligne de texte que vous venez de couper ;<br />
    Ctrl + C : afficher ? quel endroit du fichier votre curseur est positionn? (num?ro de ligne?) ;<br />
    Ctrl + W : rechercher dans le fichier ;<br />
    Ctrl + O : enregistrer le fichier (?crire) ;<br />
    Ctrl + X : quitter Nano.<br />
<br />
<h3 class="formatter-title">Les param?tres de la commande Nano</h3><br />
<br />
<span class="formatter-code">Code BASH :</span><div class="code"><pre style="display:inline;"><pre class="bash" style="font-family:monospace;">&nbsp;
<span style="color: #c20cb9; font-weight: bold;">nano</span> salut.txt <span style="color: #666666; font-style: italic;">#ouvre le fichier</span>
&nbsp;</pre></pre></div><br />
<br />
<ul class="formatter-ul">
<li class="formatter-li"><strong>-m</strong>: autorise l'utilisation de la souris sous Nano.
</li><li class="formatter-li"><strong>-i</strong>: indentation automatique. L'alin?a (tabulations) de la ligne pr?c?dente sera respect? lorsque vous irez ? la ligne. Tr?s utile lorsque vous ?ditez un fichier de code source.
</li><li class="formatter-li"><strong>-A</strong>: active le retour intelligent au d?but de la ligne.<br />
</li></ul><br />
<br />
Lancer <strong>nano</strong> avec toutes les options:<br />
<br />
<span class="formatter-code">Code BASH :</span><div class="code"><pre style="display:inline;"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">nano</span> <span style="color: #660033;">-miA</span> salut.txt</pre></pre></div><br />
<br />
<h3 class="formatter-title">Configurer nano avec .nanorc</h3><br />
<br />
Chaque utilisateur de la machine peut cr?er son propre fichier de configuration .nanorc dans son r?pertoire personnel (home) : /home/personnel/.nanorc. <br />
<br />
<span class="notice">Les fichiers commen?ant par un point sont des fichiers de configuration. Ils sont cach?s. Pour les afficher, il faut utiliser la commande ls -a.</span><br />
<br />
<span class="formatter-code">Code BASH :</span><div class="code"><pre style="display:inline;"><pre class="bash" style="font-family:monospace;">&nbsp;
<span style="color: #c20cb9; font-weight: bold;">nano</span> .nanorc <span style="color: #666666; font-style: italic;"># cr?ation du fichier</span>
<span style="color: #000000; font-weight: bold;">set</span> mouse <span style="color: #666666; font-style: italic;">#Activation de la souris</span>
<span style="color: #000000; font-weight: bold;">set</span> autoindent <span style="color: #666666; font-style: italic;">#Pour ?viter d'avoir ? taper -i. Indentation automatique.</span>
<span style="color: #000000; font-weight: bold;">set</span> smarthome <span style="color: #666666; font-style: italic;">#Pour ?viter d'avoir ? taper -A. Retour ? la ligne intelligent</span>
&nbsp;</pre></pre></div><br />
<br />
<h3 class="formatter-title">Le nanorc global et la coloration syntaxique</h3><br />
<br />
Il existe un fichier nanorc <strong>global</strong> qui est pris en compte pour tous les utilisateurs: /etc/nanorc. Il contient toutes les options disponibles, mais elles sont pr?c?d?es d'un # qui signifie qu'il s'agit d'un commentaire. Il sufit de decommenter les options d'int?r?ts.<br />
<br />
Vers la fin du fichier, vous verrez une section appel?e  <strong>color setup</strong>, qui commence par ces lignes-l? :<br />
<br />
<span class="formatter-code">Code BASH :</span><div class="code"><pre style="display:inline;"><pre class="bash" style="font-family:monospace;">&nbsp;
<span style="color: #666666; font-style: italic;">## Nanorc files</span>
<span style="color: #666666; font-style: italic;"># include "/usr/share/nano/nanorc.nanorc"</span>
<span style="color: #666666; font-style: italic;">## C/C++</span>
<span style="color: #666666; font-style: italic;"># include "/usr/share/nano/c.nanorc"</span>
<span style="color: #666666; font-style: italic;">## HTML</span>
<span style="color: #666666; font-style: italic;"># include "/usr/share/nano/html.nanorc"</span>
&nbsp;</pre></pre></div><br />
<br />
Je vous invite ? d?commenter toutes les lignes d'include. Cela permettra d'activer la coloration ? intelligente ? de vos fichiers selon leur type.<br />
<br />
[page]Installer des programmes avec apt-get [/page]<br />
<!-- START HTML -->
<ul id="toc"></ul>
<!-- END HTML --><br />
<br />
Sous linux, les programmes sont regroup?s sur des serveurs appel?s d?pots.<br />
<br />
Le fichier ? ouvrir qui contient la liste des d?p?ts:<br />
<br />
<span class="formatter-code">Code BASH :</span><div class="code"><pre style="display:inline;"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">nano</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>apt<span style="color: #000000; font-weight: bold;">/</span>sources.list</pre></pre></div><br />
<br />
Il existe des outils graphiques pour ?diters les sources de d?pots:<br />
Ubuntu : allez dans Syst?me &#8594; Administration &#8594; Sources de logiciels ;<br />
KUbuntu : allez dans Menu K &#8594; Syst?me &#8594; Gestionnaire Adept &#8594; Adept &#8594; G?rer les d?p?ts ;<br />
<br />
<strong>Nous devons g?n?ralement suivre trois ?tapes pour t?l?charger un paquet :</strong><br />
<br />
   <span class="formatter-code">Code BASH :</span><div class="code"><pre style="display:inline;"><pre class="bash" style="font-family:monospace;">&nbsp;
<span style="color: #666666; font-style: italic;">#Installation</span>
<span style="color: #c20cb9; font-weight: bold;">apt-get update</span> <span style="color: #666666; font-style: italic;">#(optionnel) : pour mettre notre cache ? jour si ce n'est pas d?j? fait ;</span>
<span style="color: #c20cb9; font-weight: bold;">apt-cache search</span> monpaquet <span style="color: #666666; font-style: italic;">#(optionnel) : pour rechercher le paquet que nous voulons t?l?charger si nous ne connaissons pas son nom exact ;</span>
<span style="color: #c20cb9; font-weight: bold;">apt-get install</span> monpaquet <span style="color: #666666; font-style: italic;"># pour t?l?charger et installer notre paquet.</span>
<span style="color: #666666; font-style: italic;">#d?sinstallation</span>
<span style="color: #c20cb9; font-weight: bold;">apt-get remove</span> monpaquet <span style="color: #666666; font-style: italic;">#desinstalle un paquet</span>
<span style="color: #c20cb9; font-weight: bold;">apt-get autoremove</span>  monpaquet <span style="color: #666666; font-style: italic;">#desinstalle mon paquet ainsi que les d?pendances devenues inutiles.</span>
<span style="color: #666666; font-style: italic;">#mise ? jour</span>
<span style="color: #c20cb9; font-weight: bold;">apt-get upgrade</span> <span style="color: #666666; font-style: italic;">#met ? jour tous les paquets install?s</span>
&nbsp;</pre></pre></div><br />
<br />
<br />
<span class="notice">Les commandes pr?c?dentes doivent ?tre utilis?es en tant que root.</span><br />
<br />
<span class="success"><br />
Astuce : vous pouvez installer plusieurs paquets d'un coup en les listant un ? un :<br />
apt-get install paquet1 paquet2 paquet3<br />
</span><br />
<br />
[page]Manuel d'une commande[/page]<br />
<br />
<span class="formatter-code">Code BASH :</span><div class="code"><pre style="display:inline;"><pre class="bash" style="font-family:monospace;">&nbsp;
<span style="color: #c20cb9; font-weight: bold;">man</span> <span style="color: #c20cb9; font-weight: bold;">mkdir</span> <span style="color: #666666; font-style: italic;">#Affiche le manuel d'une commande</span>
<span style="color: #c20cb9; font-weight: bold;">apropos</span> sound <span style="color: #666666; font-style: italic;">#Rechercher toutes les commandes qui parlent de son</span>
&nbsp;</pre></pre></div><br />
<br />
[page]Rechercher des fichiers[/page]<br />
<br />
La commande <strong>locate</strong> fait une recherche rapide dans la base de donn?es des fichiers. <br />
<br />
<span class="formatter-code">Code BASH :</span><div class="code"><pre style="display:inline;"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">locate</span> monfichier.txt <span style="color: #666666; font-style: italic;">#recherche rapide</span></pre></pre></div><br />
<br />
<span class="notice">La base de donn?es est mise ? jour par le syst?me une fois par jour. Pour que la recherche tienne compte d'un fichier qui vient d'?tre cr??, il faut mettre ? jour le syst?me en utilisant la commande: sudo updatedb</span><br />
<br />
La commande <strong>find</strong> fait une recherche approfondie des fichiers actuellement pr?sents sur le disque dur.<br />
<br />
<strong>Fonctionnement de la commande find</strong><br />
<br />
find ? o? ? ? quoi ? ? que faire avec ?<br />
<br />
<ul class="formatter-ul">
<li class="formatter-li"> <strong>O?</strong> : c'est le nom du dossier dans lequel la commande va faire la recherche. Par d?faut, si ce param?tre n'est pas pr?cis?, la recherche s'effectuera dans le dossier courant et ses sous-dossiers.
</li><li class="formatter-li"><strong>Quoi </strong>: c'est le fichier ? rechercher. On peut rechercher un fichier par son nom, mais aussi en fonction de la date de sa cr?ation, de sa taille, etc. Ce param?tre est obligatoire.
</li><li class="formatter-li"> <strong>Que faire avec </strong>: il est possible d'effectuer des actions automatiquement sur chacun des fichiers trouv?s. L'action la plus courante consiste ? afficher simplement la liste des fichiers trouv?s, mais nous verrons que nous pouvons faire bien d'autres choses.  Par d?faut, la commande find affiche les r?sultats trouv?s et ne fait rien d'autre avec.<br />
</li></ul>]]></description>
			<pubDate>Sun, 16 Feb 2014 09:12:00 +0100</pubDate>
			
		</item>
		
		<item>
			<title><![CDATA[ggplot2.dotplot: Dessiner facilement un dotplot avec le package R ggplot2]]></title>
			<link>https://www.sthda.com/french/articles/21-easyggplot2/65-ggplot2-dotplot-dessiner-facilement-un-dotplot-avec-le-package-r-ggplot2/</link>
			<guid>https://www.sthda.com/french/articles/21-easyggplot2/65-ggplot2-dotplot-dessiner-facilement-un-dotplot-avec-le-package-r-ggplot2/</guid>
			<description><![CDATA[<!-- START HTML -->

<script type="text/javascript" src="../sthda/RDocumentation/style/RSyntaxHighlighter.js"></script>
<link rel="stylesheet" type="text/css" href="../sthda/RDocumentation/style/RDocStyle.css" />
<div id="rDocumentation">

<div id="toc">
<div id="toc_header">Table of Contents</div>
<ul>
<li>
<a href="#toc_0">Objectif</a>
</li>
<li>
<a href="#toc_1">Sourcer le fichier du script R</a>
</li>
<li>
<a href="#toc_2">Dotplot simple</a>
<ul>
<li>
<a href="#toc_3">Format des donn&eacute;es</a>
</li>
<li>
<a href="#toc_4">Graphiques</a>
</li>
</ul>
</li>
<li>
<a href="#toc_5">dotplot avec deux ou plusieurs variables</a>
<ul>
<li>
<a href="#toc_6">Format des donn&eacute;es</a>
</li>
<li>
<a href="#toc_7">Graphiques</a>
</li>
</ul>
</li>
</ul>
</div>


<p>++++++++++++++++++++++++++++++++++++++++++++++++++++++<br>
 <em>Documentation for ggplot2.dotplot</em><br>
 <em>Author : Alboukadel KASSAMBARA</em><br>
 <em>e-mail : <a href="mailto:alboukadel.kassambara@gmail.com">alboukadel.kassambara@gmail.com</a></em><br>
 <em>Date : 2014 - 01 - 19</em><br>
++++++++++++++++++++++++++++++++++++++++++++++++++++++</p>

<h1 id="toc_0">Objectif</h1>

<p><strong>ggplot2.dotplot</strong> est une fonction personnalis&eacute;e, pour dessiner facilement un dotplot avec le package R <strong>ggplot2</strong>.<br>
<br/></p>

<p><span class="warning"><br>
Pr&eacute;requis:  R >= 2.15.1 | ggplot2 >= 0.9.2.1<br>
</span></p>

<h1 id="toc_1">Sourcer le fichier du script R</h1>

<p><span class="success">Vous devez sourcer le fichier <strong>easyGgplot2.r</strong> en utilisant le code R suivant.</span></p>

<pre><code class="r">source("https://www.sthda.com/upload/easyggplot2.r")
</code></pre>

<p><span class="notice"><br>
Pour utiliser les fonctions contenues dans le fichier easyggplot2.r, des packages R(&#39;ggplot2&#39;, &#39;plyr&#39;, &#39;reshape2&#39; et &#39;scales) doivent  &ecirc;tre install&eacute;es. Le script R fourni dans ce document v&eacute;rifie automatiquement si les packages n&eacute;cessaires sont install&eacute;s. Dans le cas &eacute;ch&eacute;ant, ils sont install&eacute;s automatiquement par le script. Vous avez juste &agrave; attendre quelques minutes.<br>
</span></p>

<h1 id="toc_2">Dotplot simple</h1>

<h2 id="toc_3">Format des donn&eacute;es</h2>

<p>Les donn&eacute;es doivent &ecirc;tre une data.frame.</p>

<pre><code class="r">set.seed(1234)
df <- data.frame(cond = factor( rep(c("A","B"), each=200) ), 
                   rating = c(rnorm(200),rnorm(200, mean=.8)))
head(df)
</code></pre>

<pre><code>##   cond  rating
## 1    A -1.2071
## 2    A  0.2774
## 3    A  1.0844
## 4    A -2.3457
## 5    A  0.4291
## 6    A  0.5061
</code></pre>

<h2 id="toc_4">Graphiques</h2>

<pre><code class="r"># Basic dotplot from the vector "rating"
ggplot2.dotplot(data=df, xName=&#39;cond&#39;, yName=&#39;rating&#39;, dotsize=0.25, stackratio=2)
</code></pre>

<pre><code>## stat_bindot: binwidth defaulted to range/30. Use &#39;binwidth = x&#39; to adjust this.
</code></pre>

<p><img src="https://www.sthda.com/french/french/sthda/RDocumentation/figure/easyGgplot2/ggplot2_basic_dotplot.png" title="Ggplot2 basic dotplot" alt="Ggplot2 basic dotplot" style="display: block; margin: auto;" /></p>

<pre><code class="r"># change the color of dots 
ggplot2.dotplot(data=df, xName=&#39;cond&#39;,yName=&#39;rating&#39;, dotsize=0.25, stackratio=2, 
                       colour="darkred")
</code></pre>

<pre><code>## stat_bindot: binwidth defaulted to range/30. Use &#39;binwidth = x&#39; to adjust this.
</code></pre>

<p><img src="https://www.sthda.com/french/french/sthda/RDocumentation/figure/easyGgplot2/ggplot2_dotplot_colored.png" title="Ggplot2 colored dotplot" alt="Ggplot2 colored dotplot" style="display: block; margin: auto;" /></p>

<pre><code class="r"># A basic dotplot with the conditions colored
#groupName is used to color the graph
ggplot2.dotplot(data=df, xName=&#39;cond&#39;,yName=&#39;rating&#39;, dotsize=0.35, stackratio=1.5, 
                      groupName=&#39;cond&#39;)
</code></pre>

<pre><code>## stat_bindot: binwidth defaulted to range/30. Use &#39;binwidth = x&#39; to adjust this.
</code></pre>

<p><img src="https://www.sthda.com/french/french/sthda/RDocumentation/figure/easyGgplot2/ggplot2_dotplot_colored_by_group.png" title="Ggplot2 dotplot colored by group" alt="Ggplot2 dotplot colored by group" style="display: block; margin: auto;" /></p>

<pre><code class="r">#dotplot with mean point
ggplot2.dotplot(data=df, xName=&#39;cond&#39;,yName=&#39;rating&#39;, dotsize=0.35, stackratio=1.5, 
                       groupName=&#39;cond&#39;, addMean=TRUE,meanPointShape=23)
</code></pre>

<pre><code>## stat_bindot: binwidth defaulted to range/30. Use &#39;binwidth = x&#39; to adjust this.
</code></pre>

<p><img src="https://www.sthda.com/french/french/sthda/RDocumentation/figure/easyGgplot2/ggplot2_dotplot_with_mean_point.png" title="Ggplot2 dotplot with mean point" alt="Ggplot2 dotplot with mean point" style="display: block; margin: auto;" /></p>

<pre><code class="r">#add a boxplot to the dotplot
ggplot2.dotplot(data=df, xName=&#39;cond&#39;,yName=&#39;rating&#39;, dotsize=0.35, stackratio=1.5, 
                groupName=&#39;cond&#39;, addMean=TRUE,meanPointShape=23,
                addBoxplot=TRUE)
</code></pre>

<pre><code>## stat_bindot: binwidth defaulted to range/30. Use &#39;binwidth = x&#39; to adjust this.
</code></pre>

<pre><code>## Warning: Removed 3 rows containing missing values (geom_point).
## Warning: Removed 4 rows containing missing values (geom_point).
</code></pre>

<p><img src="https://www.sthda.com/french/french/sthda/RDocumentation/figure/easyGgplot2/ggplot2_dotplot_with_boxplot.png" title="Ggplot2 dotplot with boxplot" alt="Ggplot2 dotplot with boxplot" style="display: block; margin: auto;" /></p>

<h1 id="toc_5">dotplot avec deux ou plusieurs variables</h1>

<h2 id="toc_6">Format des donn&eacute;es</h2>

<p>Les donn&eacute;es doivent &ecirc;tre une data.frame.</p>

<pre><code class="r">df <- ToothGrowth
head(df, 20)
</code></pre>

<pre><code>##     len supp dose
## 1   4.2   VC  0.5
## 2  11.5   VC  0.5
## 3   7.3   VC  0.5
## 4   5.8   VC  0.5
## 5   6.4   VC  0.5
## 6  10.0   VC  0.5
## 7  11.2   VC  0.5
## 8  11.2   VC  0.5
## 9   5.2   VC  0.5
## 10  7.0   VC  0.5
## 11 16.5   VC  1.0
## 12 16.5   VC  1.0
## 13 15.2   VC  1.0
## 14 17.3   VC  1.0
## 15 22.5   VC  1.0
## 16 17.3   VC  1.0
## 17 13.6   VC  1.0
## 18 14.5   VC  1.0
## 19 18.8   VC  1.0
## 20 15.5   VC  1.0
</code></pre>

<h2 id="toc_7">Graphiques</h2>

<pre><code class="r">#plot of variable &#39;len&#39; according to xName &#39;dose&#39;. The plot is colored by the groupName &#39;supp&#39;
ggplot2.dotplot(data=df, xName=&#39;dose&#39;, yName=&#39;len&#39;,  dotsize=0.7, stackratio=2, 
                   groupName=&#39;supp&#39;
              )             
</code></pre>

<pre><code>## stat_bindot: binwidth defaulted to range/30. Use &#39;binwidth = x&#39; to adjust this.
</code></pre>

<p><img src="https://www.sthda.com/french/french/sthda/RDocumentation/figure/easyGgplot2/ggplot2_multiple_dotplot.png" title="dotplot with two or more variables" alt="dotplot with two or more variables" style="display: block; margin: auto;" /></p>

</div>

<!-- END HTML -->]]></description>
			<pubDate>Sun, 02 Feb 2014 15:42:01 +0100</pubDate>
			
		</item>
		
		<item>
			<title><![CDATA[ggplot2.boxplot: Dessiner facilement un boxplot avec le package R ggplot2]]></title>
			<link>https://www.sthda.com/french/articles/21-easyggplot2/64-ggplot2-boxplot-dessiner-facilement-un-boxplot-avec-le-package-r-ggplot2/</link>
			<guid>https://www.sthda.com/french/articles/21-easyggplot2/64-ggplot2-boxplot-dessiner-facilement-un-boxplot-avec-le-package-r-ggplot2/</guid>
			<description><![CDATA[<!-- START HTML -->

<script type="text/javascript" src="../sthda/RDocumentation/style/RSyntaxHighlighter.js"></script>
<link rel="stylesheet" type="text/css" href="../sthda/RDocumentation/style/RDocStyle.css" />
<div id="rDocumentation">
<div id="toc">
<div id="toc_header">Table of Contents</div>
<ul>
<li>
<a href="#toc_0">Objectif</a>
</li>
<li>
<a href="#toc_1">Sourcer le fichier du script R</a>
</li>
<li>
<a href="#toc_2">Boxplot simple</a>
<ul>
<li>
<a href="#toc_3">Format des donn&eacute;es</a>
</li>
<li>
<a href="#toc_4">Graphiques</a>
</li>
</ul>
</li>
<li>
<a href="#toc_5">Boxplot avec deux ou plusieurs variables</a>
<ul>
<li>
<a href="#toc_6">Format des donn&eacute;es</a>
</li>
<li>
<a href="#toc_7">Graphiques</a>
</li>
</ul>
</li>
</ul>
</div>


<p>++++++++++++++++++++++++++++++++++++++++++++++++++++++<br>
 <em>Documentation for ggplot2.boxplot</em><br>
 <em>Author : Alboukadel KASSAMBARA</em><br>
 <em>e-mail : <a href="mailto:alboukadel.kassambara@gmail.com">alboukadel.kassambara@gmail.com</a></em><br>
 <em>Date : 2014 - 01 - 19</em><br>
++++++++++++++++++++++++++++++++++++++++++++++++++++++</p>

<h1 id="toc_0">Objectif</h1>

<p><strong>ggplot2.boxplot</strong> est une fonction personnalis&eacute;e, pour dessiner facilement un boxplot avec le package R <strong>ggplot2</strong>.<br>
<br/></p>

<p><span class="warning"><br>
Pr&eacute;requis:  R >= 2.15.1 | ggplot2 >= 0.9.2.1<br>
</span></p>

<h1 id="toc_1">Sourcer le fichier du script R</h1>

<p><span class="success">Vous devez sourcer le fichier <strong>easyGgplot2.r</strong> en utilisant le code R suivant.</span></p>

<pre><code class="r">source("https://www.sthda.com/upload/easyggplot2.r")
</code></pre>

<p><span class="notice"><br>
Pour utiliser les fonctions contenues dans le fichier easyggplot2.r, des packages R(&#39;ggplot2&#39;, &#39;plyr&#39;, &#39;reshape2&#39; et &#39;scales) doivent  &ecirc;tre install&eacute;es. Le script R fourni dans ce document v&eacute;rifie automatiquement si les packages n&eacute;cessaires sont install&eacute;s. Dans le cas &eacute;ch&eacute;ant, ils sont install&eacute;s automatiquement par le script. Vous avez juste &agrave; attendre quelques minutes.<br>
</span></p>

<h1 id="toc_2">Boxplot simple</h1>

<h2 id="toc_3">Format des donn&eacute;es</h2>

<p>Les donn&eacute;es doivent &ecirc;tre une data.frame.</p>

<pre><code class="r">set.seed(1234)
df <- data.frame(cond = factor( rep(c("A","B"), each=200) ), 
                   rating = c(rnorm(200),rnorm(200, mean=.8)))
head(df)
</code></pre>

<pre><code>##   cond  rating
## 1    A -1.2071
## 2    A  0.2774
## 3    A  1.0844
## 4    A -2.3457
## 5    A  0.4291
## 6    A  0.5061
</code></pre>

<h2 id="toc_4">Graphiques</h2>

<pre><code class="r"># Basic boxplot from the vector "rating"
ggplot2.boxplot(data=df, xName=&#39;cond&#39;,yName=&#39;rating&#39;)
</code></pre>

<p><img src="https://www.sthda.com/french/french/sthda/RDocumentation/figure/easyGgplot2/ggplot2_basic_boxplot.png" title="Ggplot2 basic boxplot" alt="Ggplot2 basic boxplot" style="display: block; margin: auto;" /></p>

<pre><code class="r"># A basic boxplot with the conditions colored
#groupName is used to color the graph
ggplot2.boxplot(data=df, xName=&#39;cond&#39;,yName=&#39;rating&#39;, groupName=&#39;cond&#39;)
</code></pre>

<p><img src="https://www.sthda.com/french/french/sthda/RDocumentation/figure/easyGgplot2/ggplot2_boxplot_colored.png" title="Ggplot2 colored boxplot" alt="Ggplot2 colored boxplot" style="display: block; margin: auto;" /></p>

<h1 id="toc_5">Boxplot avec deux ou plusieurs variables</h1>

<h2 id="toc_6">Format des donn&eacute;es</h2>

<p>Les donn&eacute;es doivent &ecirc;tre une data.frame.</p>

<pre><code class="r">df <- ToothGrowth
head(df, 20)
</code></pre>

<pre><code>##     len supp dose
## 1   4.2   VC  0.5
## 2  11.5   VC  0.5
## 3   7.3   VC  0.5
## 4   5.8   VC  0.5
## 5   6.4   VC  0.5
## 6  10.0   VC  0.5
## 7  11.2   VC  0.5
## 8  11.2   VC  0.5
## 9   5.2   VC  0.5
## 10  7.0   VC  0.5
## 11 16.5   VC  1.0
## 12 16.5   VC  1.0
## 13 15.2   VC  1.0
## 14 17.3   VC  1.0
## 15 22.5   VC  1.0
## 16 17.3   VC  1.0
## 17 13.6   VC  1.0
## 18 14.5   VC  1.0
## 19 18.8   VC  1.0
## 20 15.5   VC  1.0
</code></pre>

<h2 id="toc_7">Graphiques</h2>

<pre><code class="r">#plot of variable &#39;len&#39; according to xName &#39;dose&#39;. The plot is colored by the groupName &#39;supp&#39;
ggplot2.boxplot(data=df, xName=&#39;dose&#39;,yName=&#39;len&#39;, groupName=&#39;supp&#39;, 
            position=position_dodge(0.8) #interval between boxplot of the same group
)               
</code></pre>

<p><img src="https://www.sthda.com/french/french/sthda/RDocumentation/figure/easyGgplot2/ggplot2_multiple_boxplot.png" title="Boxplot with two or more variables" alt="Boxplot with two or more variables" style="display: block; margin: auto;" /></p>

</div>

<!-- END HTML -->]]></description>
			<pubDate>Sun, 02 Feb 2014 11:56:00 +0100</pubDate>
			
		</item>
		
		<item>
			<title><![CDATA[ggplot2.density: Dessiner facilement une courbe de densit? avec le package R ggplot2]]></title>
			<link>https://www.sthda.com/french/articles/21-easyggplot2/63-ggplot2-density-dessiner-facilement-une-courbe-de-densite-avec-le-package-r-ggplot2/</link>
			<guid>https://www.sthda.com/french/articles/21-easyggplot2/63-ggplot2-density-dessiner-facilement-une-courbe-de-densite-avec-le-package-r-ggplot2/</guid>
			<description><![CDATA[<!-- START HTML -->

     
  <!--====================== start from here when you copy to sthda================-->  
  <div id="rdoc">


<div id="TOC">
<ul>
<li><a href="#objectif">Objectif</a></li>
<li><a href="#installer-et-charger-le-package-easyggplot2">Installer et charger le package easyGgplot2</a></li>
<li><a href="#format-des-donnees">Format des donn?es</a></li>
<li><a href="#courbe-de-densite-basique">Courbe de densit? basique</a></li>
<li><a href="#changer-le-type-de-ligne-de-la-courbe-de-densite">Changer le type de ligne de la courbe de densit?</a></li>
<li><a href="#courbe-de-densite-avec-plusieurs-groupes">Courbe de densit? avec plusieurs groupes</a></li>
<li><a href="#personnaliser-votre-courbe-de-densite">Personnaliser votre courbe de densit?</a><ul>
<li><a href="#titre-principal-et-etiquettes-des-axes">Titre principal et etiquettes des axes</a></li>
<li><a href="#fond-et-couleurs">Fond et couleurs</a></li>
<li><a href="#legende">L?gende</a></li>
<li><a href="#echelle-des-axes">Echelle des axes</a></li>
</ul></li>
<li><a href="#creer-un-graphique-personnalise-avec-peu-de-code-r">Cr?er un graphique personnalis? avec peu de code R</a></li>
<li><a href="#faceting-separer-un-graphique-en-plusieurs-panels-de-graphiques">Faceting : S?parer un graphique en plusieurs panels de graphiques</a><ul>
<li><a href="#faceting-avec-une-variable">Faceting avec une variable</a></li>
<li><a href="#faceting-avec-deux-variables">Faceting avec deux variables</a></li>
<li><a href="#echelle-des-pannels">Echelle des pannels</a></li>
<li><a href="#apparence-des-etiquettes-des-pannels">Apparence des ?tiquettes des pannels</a></li>
</ul></li>
<li><a href="#la-fonction-ggplot2.density">La fonction ggplot2.density</a><ul>
<li><a href="#description">Description</a></li>
<li><a href="#utilisation">utilisation</a></li>
<li><a href="#arguments">Arguments</a></li>
<li><a href="#exemples">Exemples</a></li>
<li><a href="#references">References</a></li>
</ul></li>
</ul>
</div>

<hr />
<pre class="warning"><code>Cette analyse a ?t? faite avec R (ver. 3.1.0), easyGgplot2 (ver 1.0.0) et ggplot2 (ver 1.0.0).</code></pre>
<div id="objectif" class="section level2">
<h2>Objectif</h2>
<p><strong>ggplot2.density</strong> est une fonction permettant de dessiner facilement un histogramme avec le package R <strong>ggplot2</strong>. L'objectif de ce document est de vous montrer ?tape par ?tape, comment dessiner et personnaliser une courbe de densit? avec la fonction ggplot2.density. A la fin de cet article, vous allez pouvoir faire avec peu de code R, les graphiques suivants:</p>
<p><img src="https://www.sthda.com/french/french/sthda/RDoc/figure/easyGgplot2/ggplot2_density-demo1.png" title="ggplot2 density" alt="ggplot2 density" width="432" /><img src="https://www.sthda.com/french/french/sthda/RDoc/figure/easyGgplot2/ggplot2_density-demo2.png" title="ggplot2 density" alt="ggplot2 density" width="432" /></p>
<pre class="warning"><code>Les arguments de la fonction ggplot2.density sont d?crites ? la fin de ce document.</code></pre>
</div>
<div id="installer-et-charger-le-package-easyggplot2" class="section level2">
<h2>Installer et charger le package easyGgplot2</h2>
<p>Pour installer le package, il faut utiliser le code R suivant (R >=3.1.0) :</p>
<pre class="r"><code>install.packages("devtools")
library(devtools)
install_github("easyGgplot2", "kassambara")</code></pre>
<p>Charger le package dans R:</p>
<pre class="r"><code>library(easyGgplot2)</code></pre>
</div>
<div id="format-des-donnees" class="section level2">
<h2>Format des donn?es</h2>
<p><span class="blue"><strong>Les donn?es doivent ?tre un vecteur de type num?rique ou une data.frame (les colonnes sont les variables et les lignes sont les observations).</strong></span>. Le jeu de donn?e <strong>weight</strong> du package easyGgplot2 sera utilis? dans les exemples suivants.</p>
<pre class="r"><code>#cr?er un vecteur de type num?rique
numVector<-rnorm(100)
head(numVector)</code></pre>
<pre><code>## [1] -0.7272 -0.5700 -0.9648  0.6512 -0.2485  0.6668</code></pre>
<pre class="r"><code>#data.frame
head(weight)</code></pre>
<pre><code>##      sex weight
## 1 Female  63.79
## 2 Female  65.28
## 3 Female  66.08
## 4 Female  62.65
## 5 Female  65.43
## 6 Female  65.51</code></pre>
</div>
<div id="courbe-de-densite-basique" class="section level2">
<h2>Courbe de densit? basique</h2>
<pre class="r"><code>#Courbe de densit? avec un vecteur de type num?rique
#ggplot2.density(data=numVector)

#Courbe de densit? basique avec le vecteur "Weight (Kg)"
ggplot2.density(data=weight, xName=&#39;weight&#39;)

#Ajouter la ligne de la moyenne sur la courbe
#Changer la couleur, le type et l&#39;epaisseur du trait de la courbe de densit?
ggplot2.density(data=weight, xName=&#39;weight&#39;,
                addMeanLine=TRUE, meanLineColor="red", meanLineType="dashed", meanLineSize=1,
                colour="darkblue", linetype="dotted", size=1.5)

#Changer l&#39;orientation: histogramme horizontal
ggplot2.density(data=weight, xName=&#39;weight&#39;, orientation="horizontal")

#Mettre l&#39;axe des y ? l&#39;envers
ggplot2.density(data=weight, xName=&#39;weight&#39;, orientation="yAxisReversed")</code></pre>
<p><img src="https://www.sthda.com/french/french/sthda/RDoc/figure/easyGgplot2/ggplot2_density-basic_density1.png" title="ggplot2 density" alt="ggplot2 density" width="288" /><img src="https://www.sthda.com/french/french/sthda/RDoc/figure/easyGgplot2/ggplot2_density-basic_density2.png" title="ggplot2 density" alt="ggplot2 density" width="288" /><img src="https://www.sthda.com/french/french/sthda/RDoc/figure/easyGgplot2/ggplot2_density-basic_density3.png" title="ggplot2 density" alt="ggplot2 density" width="288" /><img src="https://www.sthda.com/french/french/sthda/RDoc/figure/easyGgplot2/ggplot2_density-basic_density4.png" title="ggplot2 density" alt="ggplot2 density" width="288" /></p>
</div>
<div id="changer-le-type-de-ligne-de-la-courbe-de-densite" class="section level2">
<h2>Changer le type de ligne de la courbe de densit?</h2>
<p><span class="warning"> Diff?rents types de points et de types de lignes peuvent ?tre utilis?s. Par d?faut, ggplot2 utilise une ligne pleine (solide) et un cercle pour les points. </span></p>
<p>Les diff?rents types de points et de lignes disponibles dans R sont montr?s ci-dessous :</p>
<p><img src="https://www.sthda.com/french/french/sthda/RDoc/figure/easyGgplot2/r_point_shapes_linetypes1.png" title="plot of chunk r_point_shapes_linetypes" alt="plot of chunk r_point_shapes_linetypes" width="288" /><img src="https://www.sthda.com/french/french/sthda/RDoc/figure/easyGgplot2/r_point_shapes_linetypes2.png" title="plot of chunk r_point_shapes_linetypes" alt="plot of chunk r_point_shapes_linetypes" width="288" /></p>
<pre class="r"><code>#Changer la couleur des traits et le type de lignes de
#la courbe de densit?.
ggplot2.density(data=weight, xName=&#39;weight&#39;,linetype="longdash")</code></pre>
<p><img src="https://www.sthda.com/french/french/sthda/RDoc/figure/easyGgplot2/ggplot2_density-linetype.png" title="ggplot2 density" alt="ggplot2 density" width="288" /></p>
</div>
<div id="courbe-de-densite-avec-plusieurs-groupes" class="section level2">
<h2>Courbe de densit? avec plusieurs groupes</h2>
<pre class="r"><code>#Plusieurs courbes de densit?s sur le m?me graphique
#Colorer la courbe de densit? en fonction du nom de groupe "sex"
ggplot2.density(data=weight, xName=&#39;weight&#39;, groupName=&#39;sex&#39;)

#Courbe de densit? avec un remplissage transparent.
#alpha est le d?gr? de transparence des couleurs chevauchantes
ggplot2.density(data=weight, xName=&#39;weight&#39;, groupName=&#39;sex&#39;,
    alpha=0.5, fillGroupDensity=TRUE )

#Courbe de densit? avec la ligne des moyennes
ggplot2.density(data=weight, xName=&#39;weight&#39;, groupName=&#39;sex&#39;,
                addMeanLine=TRUE)</code></pre>
<p><img src="https://www.sthda.com/french/french/sthda/RDoc/figure/easyGgplot2/ggplot2_density-multiple_groups1.png" title="Density with multiple groups" alt="Density with multiple groups" width="384" /><img src="https://www.sthda.com/french/french/sthda/RDoc/figure/easyGgplot2/ggplot2_density-multiple_groups2.png" title="Density with multiple groups" alt="Density with multiple groups" width="384" /><img src="https://www.sthda.com/french/french/sthda/RDoc/figure/easyGgplot2/ggplot2_density-multiple_groups3.png" title="Density with multiple groups" alt="Density with multiple groups" width="384" /></p>
</div>
<div id="personnaliser-votre-courbe-de-densite" class="section level2">
<h2>Personnaliser votre courbe de densit?</h2>
<div id="titre-principal-et-etiquettes-des-axes" class="section level3">
<h3>Titre principal et etiquettes des axes</h3>
<p><span class="blue"><strong>Les param?tres qui peuvent ?tre utilis?s pour personnaliser l'axe des x et des y sont list?s ci-dessous :</strong></span></p>
<table>
<thead>
<tr class="header">
<th align="left">Param?tres</th>
<th align="left">Description</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td align="left"><strong>xShowTitle, yShowTitle</strong></td>
<td align="left">si TRUE, le titre des axes x et y sera affich?. Mettre la valeur ? FALSE pour cacher le titre des axes. La valeur par d?faut est <code>TRUE</code>.</td>
</tr>
<tr class="even">
<td align="left"><strong>xtitle, ytitle</strong></td>
<td align="left">Titres des axes x et y. La valeur par d?faut est <code>NULL</code>.</td>
</tr>
<tr class="odd">
<td align="left"><strong>xtitleFont, ytitleFont</strong></td>
<td align="left">Un vecteur de longueur 3 indiquant respectivement la taille, le style et la couleur du titre des axes x et y. Les valeurs possibles pour le <strong>style</strong> : "plain", "italic", "bold", "bold.italic". La couleur peut ?tre sp?cifi?e par le code hexad?cimal(i.e: "#FFCC00") ou par le nom (i.e : "red", "green"). Valeurs par d?faut : <code>xtitleFont=c(14,"bold", "black"), ytitleFont=c(14,"bold", "black")</code>.</td>
</tr>
<tr class="even">
<td align="left"><strong>xlim, ylim</strong></td>
<td align="left">Limite des axes x et y. Valeur par d?faut : <code>NULL</code>.</td>
</tr>
<tr class="odd">
<td align="left"><strong>xScale, yScale</strong></td>
<td align="left">Echelle des axes x et y. Valeurs possibles : c("none", "log2", "log10"). e.g: yScale="log2". Valeur par d?faut : <code>NULL</code>.</td>
</tr>
<tr class="even">
<td align="left"><strong>xShowTickLabel, yShowTickLabel</strong></td>
<td align="left">si TRUE, les ?tiquettes des graduations axes x et y seront affich?es. Valeur par d?faut : <code>TRUE</code>.</td>
</tr>
<tr class="odd">
<td align="left"><strong>xTickLabelFont, yTickLabelFont</strong></td>
<td align="left">Un vecteur de longueur 3 indiquant respectivement la taille, le style et la couleur des ?tiquettes des graduations des axes x et y. Valeur par d?faut : <code>xTickLabelFont=c(12, "bold", "black"), yTickLabelFont=c(12, "bold", "black")</code>.</td>
</tr>
<tr class="even">
<td align="left"><strong>xtickLabelRotation, ytickLabelRotation</strong></td>
<td align="left">Angle de rotation des ?tiquettes des graduations des axes x et y. Valeur par d?faut : <code>0</code>.</td>
</tr>
<tr class="odd">
<td align="left"><strong>hideAxisTicks</strong></td>
<td align="left">si TRUE, les graduations des axes x et y sont cach?es. Valeur par d?faut : <code>FALSE</code>.</td>
</tr>
<tr class="even">
<td align="left"><strong>axisLine</strong></td>
<td align="left">Un vecteur de longueur 3 indiquant respectivement, la taille, le type de ligne et la couleur des lignes des axes. Valeur par d?faut : <code>c(0.5, "solid", "#E5E5E5")</code>.</td>
</tr>
</tbody>
</table>
<div id="titres" class="section level4">
<h4>Titres</h4>
<pre class="r"><code>#Changer le titre principal et le titre des axes
ggplot2.density(data=weight, xName=&#39;weight&#39;,
                mainTitle="Plot of var density curve",
                xtitle="Weight (Kg)", ytitle="Density")

#Personnaliser le texte des titres.
#Valeurs possibles pour le style:&#39;plain&#39;, &#39;italic&#39;, &#39;bold&#39;, &#39;bold.italic&#39;.
ggplot2.density(data=weight, xName=&#39;weight&#39;,
                xtitle="Weight (Kg)", ytitle="Density",
                mainTitle="Plot of var density curve",
                mainTitleFont=c(14,"bold.italic", "red"),
                xtitleFont=c(14,"bold", "#993333"), ytitleFont=c(14,"bold", "#993333"))

#Cacher le titre des axes x et y
ggplot2.density(data=weight, xName=&#39;weight&#39;,
                xShowTitle=FALSE, yShowTitle=FALSE)</code></pre>
<p><img src="https://www.sthda.com/french/french/sthda/RDoc/figure/easyGgplot2/ggplot2_density-title1.png" title="ggplot2 density" alt="ggplot2 density" width="288" /><img src="https://www.sthda.com/french/french/sthda/RDoc/figure/easyGgplot2/ggplot2_density-title2.png" title="ggplot2 density" alt="ggplot2 density" width="288" /><img src="https://www.sthda.com/french/french/sthda/RDoc/figure/easyGgplot2/ggplot2_density-title3.png" title="ggplot2 density" alt="ggplot2 density" width="288" /></p>
</div>
<div id="graduation-des-axes" class="section level4">
<h4>Graduation des axes</h4>
<pre class="r"><code>#Orientation des etiquettes des graduations des axes
ggplot2.density(data=weight, xName=&#39;weight&#39;,
                xShowTitle=FALSE, yShowTitle=FALSE,
                xTickLabelFont=c(14,"bold", "#993333"),yTickLabelFont=c(14,"bold", "#993333"),
                xtickLabelRotation=45, ytickLabelRotation=45)

#Cacher les ?tiquettes des graduations des axes
ggplot2.density(data=weight, xName=&#39;weight&#39;,
                xShowTitle=FALSE, yShowTitle=FALSE,
                xShowTickLabel=FALSE, yShowTickLabel=FALSE)

#Cacher les graduations des axes
ggplot2.density(data=weight, xName=&#39;weight&#39;,
                xShowTitle=FALSE, yShowTitle=FALSE,
                xShowTickLabel=FALSE, yShowTickLabel=FALSE,hideAxisTicks=TRUE)

#AxisLine : Un vecteur de longueur 3 indiquant la taille,
  #le type et la couleur des lignes des axes.
ggplot2.density(data=weight, xName=&#39;weight&#39;, axisLine=c(1, "solid", "darkblue"))</code></pre>
<p><img src="https://www.sthda.com/french/french/sthda/RDoc/figure/easyGgplot2/ggplot2_density-axis_ticks1.png" title="ggplot2 density" alt="ggplot2 density" width="288" /><img src="https://www.sthda.com/french/french/sthda/RDoc/figure/easyGgplot2/ggplot2_density-axis_ticks2.png" title="ggplot2 density" alt="ggplot2 density" width="288" /><img src="https://www.sthda.com/french/french/sthda/RDoc/figure/easyGgplot2/ggplot2_density-axis_ticks3.png" title="ggplot2 density" alt="ggplot2 density" width="288" /><img src="https://www.sthda.com/french/french/sthda/RDoc/figure/easyGgplot2/ggplot2_density-axis_ticks4.png" title="ggplot2 density" alt="ggplot2 density" width="288" /></p>
</div>
</div>
<div id="fond-et-couleurs" class="section level3">
<h3>Fond et couleurs</h3>
<div id="changer-le-fond-et-la-couleur-de-remplissage-de-la-courbe-de-densite" class="section level4">
<h4>Changer le fond et la couleur de remplissage de la courbe de densit?</h4>
<pre class="r"><code>#Changer la couleur de fond en "white". Couleur par d?faut : "gray"
ggplot2.density(data=weight, xName=&#39;weight&#39;,
                backgroundColor="white")

#Changer la couleur de fond en "lightblue" 
#et la couleur du quadrillage en "white"
ggplot2.density(data=weight, xName=&#39;weight&#39;,
                backgroundColor="lightblue", gridColor="white")

#Changer la couleur de remplissage
ggplot2.density(data=weight, xName=&#39;weight&#39;,
                backgroundColor="white", densityFill=&#39;#FFAAD4&#39;)

#Supprimer le quadrillage; supprimer les bordures autour du graphique;
#Changer la ligne des axes
ggplot2.density(data=weight, xName=&#39;weight&#39;,
                backgroundColor="white", densityFill=&#39;#FFAAD4&#39;,
                removePanelGrid=TRUE,removePanelBorder=TRUE,
                axisLine=c(0.5, "solid", "black"))</code></pre>
<p><img src="https://www.sthda.com/french/french/sthda/RDoc/figure/easyGgplot2/ggplot2_density-background_color1.png" title="ggplot2 density" alt="ggplot2 density" width="288" /><img src="https://www.sthda.com/french/french/sthda/RDoc/figure/easyGgplot2/ggplot2_density-background_color2.png" title="ggplot2 density" alt="ggplot2 density" width="288" /><img src="https://www.sthda.com/french/french/sthda/RDoc/figure/easyGgplot2/ggplot2_density-background_color3.png" title="ggplot2 density" alt="ggplot2 density" width="288" /><img src="https://www.sthda.com/french/french/sthda/RDoc/figure/easyGgplot2/ggplot2_density-background_color4.png" title="ggplot2 density" alt="ggplot2 density" width="288" /></p>
</div>
<div id="specifications-des-couleurs" class="section level4">
<h4>Sp?cifications des couleurs</h4>
<p><span class="warning"> Les couleurs peuvent ?tre sp?cifi?es en utilisant du code hexad?cimal, tel que <strong>"#FFCC00"</strong>. Vous pouvez ?galement utiliser des couleurs provenant du package <strong>RColorBrewer</strong>. <span></p>
<table>
<thead>
<tr class="header">
<th align="left">Code hexad?cimal</th>
<th align="left">Palettes RColorBrewer</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td align="left"><img src="https://www.sthda.com/french/french/sthda/RDoc/images/color_codes_hex.png" alt="Hexadecimal color code" /></td>
<td align="left"><img src="https://www.sthda.com/french/french/sthda/RDoc/images/rcolorbrewer.png" alt="RColorBrewer" /></td>
</tr>
</tbody>
</table>
<p>Le code R suivant peut ?tre utilis? pour afficher les palettes RColorBrewer:</p>
<pre class="r"><code>rquery.loadPackages("RColorBrewer")
#Afficher toutes les palettes du packages
display.brewer.all()
#Afficher une seule palette en sp?cifiant le nom
display.brewer.pal(n = 8, name = &#39;Dark2&#39;)
#Afficher le code hexad?cimal d&#39;une palette
brewer.pal(n = 8, name = "Dark2")</code></pre>
<p><span class="warning"> Les couleurs peuvent ?tre sp?cifi?es en utilisant le nom, tel que <strong>"red", "blue", "lightblue"</strong>. Vous trouverez ci-dessous, un graphique de certains des noms de couleurs reconnues par R.</span></p>
<p><span class="blue"><strong>Pour voir l'ensemble des couleurs reconnues par R ( n = 657), utiliser le code R suivant:</strong></span></p>
<pre class="r"><code>colornames<-colors()
head(colornames)
showCols(cl=colornames, bg="gray33", rot=30, cex=0.75)</code></pre>
<p>Les 200 premi?res couleurs sont montr?es ci-dessous :</p>
<p><img src="https://www.sthda.com/french/french/sthda/RDoc/figure/easyGgplot2/r_colornames1.png" title="plot of chunk r_colornames" alt="plot of chunk r_colornames" width="432" /><img src="https://www.sthda.com/french/french/sthda/RDoc/figure/easyGgplot2/r_colornames2.png" title="plot of chunk r_colornames" alt="plot of chunk r_colornames" width="432" /></p>
</div>
<div id="changer-la-couleur-des-histogrammes-en-fonction-du-groupe" class="section level4">
<h4>Changer la couleur des histogrammes en fonction du groupe</h4>
<p><span class="warning">Pour changer la couleur en fonction du groupe, vous devez indiquer le nom de la colonne contenant les groupes en utilisant le param?tre <strong>groupName</strong>. Il faut utiliser l'argument <strong>groupColors</strong>, pour sp?cifier les couleurs par le code hexad?cimal ou par le nom. Dans ce cas, la longueur du param?tre groupColors devrait ?tre la m?me que le nombre de groupes. Il faut utiliser l'argument <strong>brewerPalette</strong>, pour sp?cifier la couleur en utilisant les palettes RColorBrewer.</span></p>
<pre class="r"><code>#Changer la couleur des groupes en utilisant le code hexad?cimal. 
#alpha est le d?gr? de transparence des couleurs ch?vauchantes
  #La valeur peut varier de 0 (transparence totale) ? 1 (pas de transparence)
ggplot2.density(data=weight, xName=&#39;weight&#39;, groupName=&#39;sex&#39;,
                groupColors=c(&#39;#999999&#39;,&#39;#E69F00&#39;),
                fillGroupDensity=TRUE, alpha=0.5 )

#Changer la couleur des groupes en utilisant l&#39;argument brewerPalette: "Paired"
ggplot2.density(data=weight, xName=&#39;weight&#39;, groupName=&#39;sex&#39;,
                brewerPalette="Paired",
                fillGroupDensity=TRUE, alpha=0.5)

#Changer la couleur des groupes en utilisant le nom des couleurs
ggplot2.density(data=weight, xName=&#39;weight&#39;, groupName=&#39;sex&#39;,
                groupColors=c(&#39;aquamarine3&#39;,&#39;goldenrod1&#39;),
                fillGroupDensity=TRUE, alpha=0.5 )</code></pre>
<p><img src="https://www.sthda.com/french/french/sthda/RDoc/figure/easyGgplot2/ggplot2_density-density_color1.png" title="ggplot2 density" alt="ggplot2 density" width="384" /><img src="https://www.sthda.com/french/french/sthda/RDoc/figure/easyGgplot2/ggplot2_density-density_color2.png" title="ggplot2 density" alt="ggplot2 density" width="384" /><img src="https://www.sthda.com/french/french/sthda/RDoc/figure/easyGgplot2/ggplot2_density-density_color3.png" title="ggplot2 density" alt="ggplot2 density" width="384" /></p>
</div>
</div>
<div id="legende" class="section level3">
<h3>L?gende</h3>
<div id="position-de-la-legende" class="section level4">
<h4>Position de la l?gende</h4>
<pre class="r"><code>#Changer la position de la l?gende en "top" (Valeurs possibles: "top", "left", "right", "bottom")
ggplot2.density(data=weight, xName=&#39;weight&#39;, groupName=&#39;sex&#39;,
                legendPosition="top")

#legendPosition peut ?tre aussi un vecteur de type num?rique c(x, y) indiquant les coordonn?es
#Les valeurs de x et y doivent ?tres entre 0 et 1. c(0,0) corresponds ? "bottom left"
# et c(1, 1) correspond ? "top right" position
ggplot2.density(data=weight, xName=&#39;weight&#39;, groupName=&#39;sex&#39;,
                legendPosition=c(0.8,0.2))

#Remove legend
ggplot2.density(data=weight, xName=&#39;weight&#39;, groupName=&#39;sex&#39;,
                showLegend=FALSE)</code></pre>
<p><img src="https://www.sthda.com/french/french/sthda/RDoc/figure/easyGgplot2/ggplot2_density-legend_position1.png" title="ggplot2 density" alt="ggplot2 density" width="288" /><img src="https://www.sthda.com/french/french/sthda/RDoc/figure/easyGgplot2/ggplot2_density-legend_position2.png" title="ggplot2 density" alt="ggplot2 density" width="288" /><img src="https://www.sthda.com/french/french/sthda/RDoc/figure/easyGgplot2/ggplot2_density-legend_position3.png" title="ggplot2 density" alt="ggplot2 density" width="288" /></p>
<p><span class="warning">Il est aussi possible de mettre la l?gende ? l'int?rieur du graphique. Vous avez juste ? indiquer les coordonn?es x et y de la l?gende. Les valeurs de x et y doivent ?tre entre 0 et 1. c(0,0) correspond ? <strong>"bottom left"</strong> et c(1,1) correspond ? la position <strong>"top right"</strong>.</span></p>
</div>
<div id="couleur-de-fond-de-la-legende-titre-et-style-des-textes" class="section level4">
<h4>Couleur de fond de la l?gende, titre et style des textes</h4>
<pre class="r"><code>#Changer la couleur de fond de la l?gende, le titre et le style des textes
ggplot2.density(data=weight, xName=&#39;weight&#39;, groupName=&#39;sex&#39;,
                #legendTitleFont=c(size, style, color)
                legendTitle="Groups", legendTitleFont=c(10, "bold", "blue"),
                legendTextFont=c(10, "bold.italic", "red"),#legendTextFont=c(size, style, color)
                #legendBackground: c(fill, lineSize, lineType, lineColor)
                legendBackground=c("lightblue", 0.5, "solid", "darkblue" )
                )</code></pre>
<p><img src="https://www.sthda.com/french/french/sthda/RDoc/figure/easyGgplot2/ggplot2_density-legend_background_and_title.png" title="ggplot2 density" alt="ggplot2 density" width="384" /></p>
</div>
</div>
<div id="echelle-des-axes" class="section level3">
<h3>Echelle des axes</h3>
<p>Les valeurs possibles pour l'?chelle de l'axe x sont : "none", "log2" et log10. Valeur par d?faut : "none".</p>
<pre class="r"><code>#Changer la limite des axes
ggplot2.density(data=weight, xName=&#39;weight&#39;, groupName=&#39;sex&#39;,
                showLegend=FALSE, xlim=c(60,72))

#Echelle log. xScale="log2". (valeur possible="none", "log2" and "log10")
  #Valeur par d?faut: "none"
ggplot2.density(data=weight, xName=&#39;weight&#39;, groupName=&#39;sex&#39;,
                showLegend=FALSE, xScale="log2")</code></pre>
<p><img src="https://www.sthda.com/french/french/sthda/RDoc/figure/easyGgplot2/ggplot2_density-axis_scale1.png" title="ggplot2 density" alt="ggplot2 density" width="384" /><img src="https://www.sthda.com/french/french/sthda/RDoc/figure/easyGgplot2/ggplot2_density-axis_scale2.png" title="ggplot2 density" alt="ggplot2 density" width="384" /></p>
</div>
</div>
<div id="creer-un-graphique-personnalise-avec-peu-de-code-r" class="section level2">
<h2>Cr?er un graphique personnalis? avec peu de code R</h2>
<pre class="r"><code>#Courbe de densit? personnalis?e
ggplot2.density(data=weight, xName=&#39;weight&#39;, groupName=&#39;sex&#39;,
                groupColors=c(&#39;#999999&#39;,&#39;#E69F00&#39;), showLegend=FALSE,
                backgroundColor="white", xtitle="Weight (Kg)", ytitle="Density", 
                mainTitle="Plot of weight density curve \nper sex",
                addMeanLine=TRUE
                )

#Supprimer le quadrillage; supprimer les bordures autour du graphique; 
#Remplissage de la courbe de densit? en fonction du groupe
ggplot2.density(data=weight, xName=&#39;weight&#39;, groupName=&#39;sex&#39;,
                groupColors=c(&#39;#999999&#39;,&#39;#E69F00&#39;), showLegend=FALSE,
                backgroundColor="white", xtitle="Weight (Kg)", ytitle="Density", 
                mainTitle="Plot of variable density curve \nper sex",
                removePanelGrid=TRUE,removePanelBorder=TRUE,
                axisLine=c(0.5, "solid", "black"),
                fillGroupDensity=TRUE, alpha=0.5)</code></pre>
<p><img src="https://www.sthda.com/french/french/sthda/RDoc/figure/easyGgplot2/ggplot2_density-customized_plot1.png" title="ggplot2 density" alt="ggplot2 density" width="384" /><img src="https://www.sthda.com/french/french/sthda/RDoc/figure/easyGgplot2/ggplot2_density-customized_plot2.png" title="ggplot2 density" alt="ggplot2 density" width="384" /></p>
<pre class="success"><code>L&#39;argument alpha est utilis? pour la transparence des couleurs.</code></pre>
</div>
<div id="faceting-separer-un-graphique-en-plusieurs-panels-de-graphiques" class="section level2">
<h2>Faceting : S?parer un graphique en plusieurs panels de graphiques</h2>
<p>L'approche faceting s?pare un graphique en plusieurs panels. Chaque panel repr?sente une partie du jeu de donn?es.</p>
<div id="faceting-avec-une-variable" class="section level3">
<h3>Faceting avec une variable</h3>
<pre class="r"><code>#Facet en fonction de la variable "sex"
ggplot2.density(data=weight, xName=&#39;weight&#39;, groupName=&#39;sex&#39;, legendPosition="top",
            faceting=TRUE, facetingVarNames="sex") 

#Changer la direction. Valeurs possibles : "vertical", horizontal". Valeur par d?faut: vertical.
ggplot2.density(data=weight, xName=&#39;weight&#39;, groupName=&#39;sex&#39;, legendPosition="top",
            faceting=TRUE, facetingVarNames="sex", facetingDirection="horizontal") </code></pre>
<p><img src="https://www.sthda.com/french/french/sthda/RDoc/figure/easyGgplot2/ggplot2_density-facet_with_one_variable1.png" title="ggplot2 density and faceting approch" alt="ggplot2 density and faceting approch" width="384" /><img src="https://www.sthda.com/french/french/sthda/RDoc/figure/easyGgplot2/ggplot2_density-facet_with_one_variable2.png" title="ggplot2 density and faceting approch" alt="ggplot2 density and faceting approch" width="384" /></p>
</div>
<div id="faceting-avec-deux-variables" class="section level3">
<h3>Faceting avec deux variables</h3>
<p>Les donn?es <strong>mtcars</strong> sont utilis?es dans les exemples suivants.</p>
<pre class="r"><code>data(mtcars)
head(mtcars)</code></pre>
<pre><code>##                    mpg cyl disp  hp drat    wt  qsec vs am gear carb
## Mazda RX4         21.0   6  160 110 3.90 2.620 16.46  0  1    4    4
## Mazda RX4 Wag     21.0   6  160 110 3.90 2.875 17.02  0  1    4    4
## Datsun 710        22.8   4  108  93 3.85 2.320 18.61  1  1    4    1
## Hornet 4 Drive    21.4   6  258 110 3.08 3.215 19.44  1  0    3    1
## Hornet Sportabout 18.7   8  360 175 3.15 3.440 17.02  0  0    3    2
## Valiant           18.1   6  225 105 2.76 3.460 20.22  1  0    3    1</code></pre>
<p><span class="success"> <strong>mtcars</strong> (Motor Trend Car Road Tests) comprend la consommation de carburant et 10 aspects de la conception de l'automobile et de la performance pour 32 voitures. </span></p>
<pre class="r"><code>#Facet avec deux variables : vs et am.
#En ligne on a la variable vs et en colonne la variable am
ggplot2.density(data=mtcars, xName=&#39;mpg&#39;, groupName=&#39;vs&#39;, legendPosition="top",
                faceting=TRUE, facetingVarNames=c("vs", "am"))

#Facet avec deux variables: inverser l&#39;ordre des 2 variables.
#En ligne : am et en colonne :vs
ggplot2.density(data=mtcars, xName=&#39;mpg&#39;, groupName=&#39;vs&#39;, legendPosition="top",
                faceting=TRUE, facetingVarNames=c("am", "vs"))</code></pre>
<p><img src="https://www.sthda.com/french/french/sthda/RDoc/figure/easyGgplot2/ggplot2_density-facet_with_two_variable1.png" title="ggplot2 density and faceting approch" alt="ggplot2 density and faceting approch" width="384" /><img src="https://www.sthda.com/french/french/sthda/RDoc/figure/easyGgplot2/ggplot2_density-facet_with_two_variable2.png" title="ggplot2 density and faceting approch" alt="ggplot2 density and faceting approch" width="384" /></p>
</div>
<div id="echelle-des-pannels" class="section level3">
<h3>Echelle des pannels</h3>
<p>Par d?faut, tous les panels ont la m?me ?chelle (<code>facetingScales="fixed"</code>). Les ?chelles peuvent ?tre ind?pendantes, en utilisant les valeurs <code>free</code>, <code>free_x</code>, or <code>free_y</code>.</p>
<pre class="r"><code>#Facet avec des ?chelles ind?pendantes
ggplot2.density(data=mtcars, xName=&#39;mpg&#39;, groupName=&#39;vs&#39;, legendPosition="top",
                faceting=TRUE, facetingVarNames=c("vs", "am"), facetingScales="free")</code></pre>
<p><img src="https://www.sthda.com/french/french/sthda/RDoc/figure/easyGgplot2/ggplot2_density-facet_free_scale.png" title="ggplot2 density and faceting approch" alt="ggplot2 density and faceting approch" width="384" /></p>
<pre class="success"><code>Comme vous pouvez le constater sur le graphique ci-dessus, les pannels ont des ?chelles diff?rentes sur l&#39;axe des y. </code></pre>
</div>
<div id="apparence-des-etiquettes-des-pannels" class="section level3">
<h3>Apparence des ?tiquettes des pannels</h3>
<pre class="r"><code>#Changer le texte des panels
#Valeurs possibles pour le style:&#39;plain&#39;, &#39;italic&#39;, &#39;bold&#39;, &#39;bold.italic&#39;.
ggplot2.density(data=mtcars, xName=&#39;mpg&#39;, groupName=&#39;vs&#39;, legendPosition="top",
              faceting=TRUE, facetingVarNames=c("vs", "am"),
              facetingFont=c(12, &#39;bold.italic&#39;, "red"))

#Changer l&#39;apparence du rectangle autour des ?tiquettes des pannels
ggplot2.density(data=mtcars, xName=&#39;mpg&#39;, groupName=&#39;vs&#39;, legendPosition="top",
            faceting=TRUE, facetingVarNames=c("vs", "am"),
            facetingRect=list(background="white", lineType="solid", lineColor="black", lineSize=1.5))</code></pre>
<p><img src="https://www.sthda.com/french/french/sthda/RDoc/figure/easyGgplot2/ggplot2_density-facet_label_apperance1.png" title="ggplot2 density and faceting approch" alt="ggplot2 density and faceting approch" width="384" /><img src="https://www.sthda.com/french/french/sthda/RDoc/figure/easyGgplot2/ggplot2_density-facet_label_apperance2.png" title="ggplot2 density and faceting approch" alt="ggplot2 density and faceting approch" width="384" /></p>
</div>
</div>
<div id="la-fonction-ggplot2.density" class="section level2">
<h2>La fonction ggplot2.density</h2>
<div id="description" class="section level3">
<h3>Description</h3>
<p>Dessiner facilement une courbe de densit? avec le package R ggplot2.</p>
</div>
<div id="utilisation" class="section level3">
<h3>utilisation</h3>
<pre class="r"><code>ggplot2.density(data, xName, groupName=NULL,
              addMeanLine=FALSE, meanLineColor=NULL, meanLineType="dashed", meanLineSize=1,
              densityFill=NULL,fillGroupDensity=FALSE, colorGroupDensityLine=FALSE,
              groupColors=NULL, brewerPalette=NULL,faceting=FALSE,...)</code></pre>
</div>
<div id="arguments" class="section level3">
<h3>Arguments</h3>
<table>
<thead>
<tr class="header">
<th align="left">Arguments</th>
<th align="left">Descriptions</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td align="left"><strong>data</strong></td>
<td align="left">data.frame ou vecteur de type num?rique. Les colonnes sont des variables et les lignes sont des observations.</td>
</tr>
<tr class="even">
<td align="left"><strong>xName</strong></td>
<td align="left">Nom de la colonne contenant la variable x. Valeur par d?faut : NULL.</td>
</tr>
<tr class="odd">
<td align="left"><strong>groupName</strong></td>
<td align="left">Nom de la colonne contenant la variable groupe. Cette variable est utilis?e pour colorer le graphique en fonction du groupe.</td>
</tr>
<tr class="even">
<td align="left"><strong>addMeanLine</strong></td>
<td align="left">si TRUE, la ligne de la moyenne est ajout?e au graphique pour chaque groupe. Valeur par d?faut : FALSE.</td>
</tr>
<tr class="odd">
<td align="left"><strong>meanLineColor, meanLineType, meanLineSize</strong></td>
<td align="left">Couleur, type et ?paisseur de la ligne de la moyenne.</td>
</tr>
<tr class="even">
<td align="left"><strong>densityFill</strong></td>
<td align="left">Couleur de remplissage de la courbe de densit?. Cette valeur est consid?r?e uniquement lorsque groupName=NULL.</td>
</tr>
<tr class="odd">
<td align="left"><strong>fillGroupDensity</strong></td>
<td align="left">Si TRUE, la courbe de densit? de chaque groupe est remplie. Valeur par d?faut : TRUE.</td>
</tr>
<tr class="even">
<td align="left"><strong>colorGroupDensityLine</strong></td>
<td align="left">si TRUE, la ligne de la courbe de densit? est color?e. Valeur par d?faut : FALSE.</td>
</tr>
<tr class="odd">
<td align="left"><strong>groupColors</strong></td>
<td align="left">Colore des groupes. groupColors doit avoir une longueur identique au nombre de groupes.</td>
</tr>
<tr class="even">
<td align="left"><strong>brewerPalette</strong></td>
<td align="left">Ceci peut ?tre utilis? aussi pour indiquer la couleur des groupes. Dans ce cas, le param?tre groupColors doit ?tre NULL. i.e: brewerPalette="Paired".</td>
</tr>
<tr class="odd">
<td align="left"><strong>?.</strong></td>
<td align="left">D'autres arguments ? passer ? la fonction ggplot2.customize (easyGgplot2) ou ? la fonction geom_density du package ggplot2.</td>
</tr>
</tbody>
</table>
<p><span class="warning"><strong>Les autres arguments qui peuvent ?tre utilis?s sont montr?s dans le tableau ci-dessous.</strong> Ils sont utilis?s pour personnaliser le graphique (axes, titre, arri?re plan, couleur, l?gende, ?.) g?n?rer par le package ggplot2.</span></p>
<table>
  <tr><th>
Arguments
</th><th>
Descriptions
</th> </tr>
  
<tr><td colspan=2 style="background-color:#336699; color:white;">
Personnaliser le titre du graphique
</td></tr>
  <tr><td>
<b>mainTitle</b>
</td><td>
Titre du graphique.
</td></tr>
  <tr><td>
<b>mainTitleFont</b>
</td><td>
Un vecteur de longueur 3 indiquant respectivement la taille, le style et la couleur du titre des axes x et y. Les valeurs possibles pour le style : "plain", "italic", "bold", "bold.italic". La couleur peut ?tre sp?cifi?e par le code hexad?cimal(i.e: "#FFCC00") ou par le nom (i.e : "red", "green"). <b/>Valeur par d?faut: mainTitleFont=c(14, "bold", "black").</b>
</td></tr>
  
<tr><td colspan=2 style="background-color:#336699; color:white;">
Personnaliser les axes x et y
</td></tr>
  <tr><td>
<b>xShowTitle, yShowTitle</b>
</td><td>
Si TRUE, le titre des axes x et y est affich?. <b>Valeur par d?faut : TRUE.</b>
</td></tr>
  <tr><td>
<b>xtitle, ytitle</b>
</td><td>
?tiquettes des axes x et y.
</td></tr>
  <tr><td>
<b>xtitleFont, ytitleFont</b>
</td><td> 
Un vecteur de longueur 3 indiquant respectivement la taille, le style et la couleur du titre des axes x et y. <b>Valeur par d?faut : c(14,"bold", "black").</b>
</td></tr>
  <tr><td>
<b>xlim, ylim</b>
</td><td>
Limite des axes x et y. <b>Valeur par d?faut : NULL</b>.
</td></tr>
  <tr><td>
<b>xScale, yScale</b>
</td><td>
Echelle des axes x et y. Valeurs possibles : c("none", "log2", "log10"). Exemple: yScale="log2". <b>Valeur par d?faut: "none".</b>
</td></tr>
  <tr><td>
<b>xShowTickLabel, yShowTickLabel</b>
</td><td>
si TRUE, les ?tiquettes des graduations des axes x et y seront affich?es. <b>Valeur par d?faut : TRUE.</b>
</td></tr>
  <tr><td>
<b>xTickLabelFont, yTickLabelFont</b>
</td><td>
Un vecteur de longueur 3 indiquant respectivement la taille, le style et la couleur des ?tiquettes des graduations des axes x et y. <b>Valeur par d?faut : c(12, "bold", "black").</b>
</td></tr>
  <tr><td>
<b>xtickLabelRotation, ytickLabelRotation</b>
</td><td>
Angle de rotation des ?tiquettes des graduations des axes x et y. <b>Valeurs par d?faut: 0</b>.
</td></tr>
  <tr><td>
<b>hideAxisTicks</b>
</td><td>
si TRUE, les graduations des axes x et y sont cach?es. <b>Valeur par d?faut : FALSE</b>.
</td></tr>
  <tr><td>
<b>axisLine</b>
</td><td>
Un vecteur de longueur 3 indiquant respectivement, la taille, le type de ligne et la couleur des lignes des axes.<b> Valeur par d?faut: c(0.5, "solid", "#E5E5E5").</b>
</td></tr>
  
<tr><td colspan=2 style="background-color:#336699; color:white;">
Personnaliser le fond du graphique
</td></tr>
  <tr><td>
<b>removePanelBorder</b>
</td><td>
si TRUE, supprime les bordures autour du graphique. <b>Valeur par d?faut: FALSE.</b>
</td></tr>
  <tr><td>
<b>removePanelGrid</b>
</td><td>
Si TRUE, le quadrillage est supprim?. <b>Valeur par d?faut: FALSE.</b>
</td></tr>
  <tr><td>
<b>backgroundColor</b>
</td><td>
Couleur de fond du graphique. <b>Valeur par d?faut: "gray".</b>
</td></tr>
  <tr><td>
<b>gridColor</b>
</td><td>
Couleur du quadrillage du graphique. <b>Valeur par d?faut: "white".</b>
</td></tr>
  
<tr><td colspan=2 style="background-color:#336699; color:white;">
Personnaliser la l?gende du graphique
</td></tr>
  <tr><td>
<b>showLegend</b>
</td><td>
Si TRUE, la l?gende du graphique est affich?e. <b>Valeur par d?faut TRUE</b>.
</td></tr>
  <tr><td>
<b>legendPosition</b>
</td><td>
Position de la l?gende. <b>Valeur par d?faut: "right"</b>. Valeurs possibles pour la position : "right", "left","top", "bottom". LegendPosition peut ?tre un vecteur de type num?rique c(x, y) indiquant les coordonn?es de la l?gende. x et y doivent ?tre entre 0 et 1. c(0,0) correspond ? "bottom left" et c(1,1) correspond ? la position "top right".
</td></tr>
  <tr><td>
<b>legendBackground</b>
</td><td>
Un vecteur de longueur 4 indiquant: le remplissage de la l?gende plus la taille, le type et la couleur des bordures de la l?gende. <b>Valeur par d?faut: legendBackground=c("#FFFFFF", 0.5, "blank", "black" ).</b>
</td></tr>
  <tr><td>
<b>legendTextFont</b>
</td><td>
Un vecteur de longueur 3 indiquant respectivement, la taille, le style et la couleur du texte de la l?gende. <b>Valeur par d?faut : c(10, "plain", "black")</b>. Valeurs possibles pour le style : "plain", "italic", "bold", "bold.italic".
</td></tr>
  <tr><td>
<b>legendTitleFont</b>
</td><td>
Un vecteur de longueur 3 indiquant respectivement, la taille, le style et la couleur du titre de la l?gende. <b>Valeur par d?faut : c(10, "plain", "black")</b>
</td></tr>
  <tr><td>
<b>legendItemOrder</b>
</td><td>
Un vecteur de texte indiquant l'ordre des ?l?ments de la l?gende. Exemple: c("2", "1", "0.5")
</td></tr>
  
<tr><td colspan=2 style="background-color:#336699; color:white;">
Faceting : Divise le graphique en plusieurs panels
</td></tr>
  <tr><td>
<b>faceting</b>
</td><td>
si TRUE, les donn?es sont coup?es en fonction d'une ou de deux variables, et le graphique est montr? dans diff?rents panels. Dans ce cas vous devez renseigner l'argument : facetingVarNames. <b>Valeur par d?faut : FALSE</b>.
</td></tr>
   <tr><td>
<b>facetingVarNames</b>
</td><td>
Nom des colonnes contenant les variables ? utiliser pour le faceting. <b>Valeur par d?faut: NULL</b>.
</td></tr>
   <tr><td>
<b>facetingDirection</b>
</td><td>
Valeurs possibles : "vertical" et "horizontal". <b>Valeur par d?faut : "vertical"</b>.
</td></tr>
<tr><td>
<b>facetingScales</b>
</td><td> 
Par d?faut, tous les panels ont la m?me ?chelle (<code>facetingScales="fixed"</code>). Les ?chelles peuvent ?tre ind?pendantes en utilisant les valeurs "free", "free_x", or "free_y". <b>Valeur par d?faut : "fixed"</b>.
</td></tr>
<tr><td>
<b>facetingFont</b>
</td><td>
Changer l'apparence des ?tiquettes des panels. Un vecteur de longueur 3, indiquant respectivement la taille, le style et la couleur du texte. <b>Valeur par d?faut: facetingFont=c(size=12, font="plain", color="black").</b>
</td></tr>
<tr><td>
<b>facetingRect</b>
</td><td>
Modifie l'apparence du rectangle autour des ?tiquettes des panels. <b>Valeur par d?faut : <span class="blue">list</span>(background=NULL, lineType=NULL, lineColor=NULL, lineSize=NULL).</b>
</td></tr>
<tr><td>
<b>facetingTextAngles</b>
</td><td>
Modifie l'orientation du texte des ?tiquettes des panels. Il indique les angles de rotation des textes en x et y ([0, 360]). <b>Valeur par d?faut c(NULL, NULL).</b>
</td></tr>

<tr><td colspan=2 style="background-color:#336699; color:white;">
Autres
</td></tr>
  <tr><td>
<b>orientation</b>
</td><td>
Change l'orientation du graphique. Valeurs possibles c("standard", "horizontal", "yAxisReversed"). <b>Valeur par d?faut: "standard"</b>.
</td></tr> 
</table>

<pre class="success"><code>Les valeurs possibles pour le style sont : "plain", "italic", "bold", "bold.italic". </code></pre>
</div>
<div id="exemples" class="section level3">
<h3>Exemples</h3>
<pre class="r"><code>#plot
ggplot2.density(data=weight, xName=&#39;weight&#39;,groupName=&#39;sex&#39;, groupColors=c(&#39;#999999&#39;,&#39;#E69F00&#39;),
                mainTitle="Plot of weight density curve \nper sex",
                xtitle="Weight (Kg)", ytitle="Density")

#Or use this
plot<-ggplot2.density(data=weight, xName=&#39;weight&#39;,groupName=&#39;sex&#39;, groupColors=c(&#39;#999999&#39;,&#39;#E69F00&#39;))
plot<-ggplot2.customize(plot, mainTitle="Plot of variable histogram \nper sex",
                        xtitle="Weight (Kg)", ytitle="Density")
print(plot)</code></pre>
<p><br/></p>
</div>
<div id="references" class="section level3">
<h3>References</h3>
<ul>
<li><a href="http://docs.ggplot2.org/current/">ggplot2 online documentation</a></li>
<li><a href="http://www.cookbook-r.com/Graphs/">Cookbook for R</a></li>
</ul>
</div>
</div>

<script>jQuery(document).ready(function () {jQuery('h1,h2,h3,h4').addClass('formatter-title');});//add phpboost class to header</script>
<style>.content{padding:0px;}</style>
</div><!--end rdoc-->
<!--====================== stop here when you copy to sthda================-->



<!-- END HTML -->]]></description>
			<pubDate>Sun, 02 Feb 2014 10:32:00 +0100</pubDate>
			
		</item>
		
		<item>
			<title><![CDATA[ggplot2.histogram: Dessiner facilement un histogramme avec le package R ggplot2]]></title>
			<link>https://www.sthda.com/french/articles/21-easyggplot2/62-ggplot2-histogram-dessiner-facilement-un-histogramme-avec-le-package-r-ggplot2/</link>
			<guid>https://www.sthda.com/french/articles/21-easyggplot2/62-ggplot2-histogram-dessiner-facilement-un-histogramme-avec-le-package-r-ggplot2/</guid>
			<description><![CDATA[<!-- START HTML -->


            
  <!--====================== start from here when you copy to sthda================-->  
  <div id="rdoc">


<div id="TOC">
<ul>
<li><a href="#objectif">Objectif</a></li>
<li><a href="#installer-et-charger-le-package-easyggplot2">Installer et charger le package easyGgplot2</a></li>
<li><a href="#format-des-donnees">Format des donn?es</a></li>
<li><a href="#histogramme-basic">Histogramme basic</a></li>
<li><a href="#changer-lorientation-de-lhistogramme">Changer l'orientation de l'histogramme</a></li>
<li><a href="#ajouter-la-ligne-de-la-moyenne-et-la-courbe-de-densite">Ajouter la ligne de la moyenne et la courbe de densit?</a></li>
<li><a href="#changer-le-type-de-ligne-de-lhistogramme">Changer le type de ligne de l'histogramme</a></li>
<li><a href="#histogramme-avec-plusieurs-groupes">Histogramme avec plusieurs groupes</a></li>
<li><a href="#personnaliser-votre-histogramme">Personnaliser votre histogramme</a><ul>
<li><a href="#titre-principal-et-etiquettes-des-axes">Titre principal et etiquettes des axes</a></li>
<li><a href="#fond-et-couleurs">Fond et couleurs</a></li>
<li><a href="#legende">L?gende</a></li>
<li><a href="#echelle-des-axes">Echelle des axes</a></li>
</ul></li>
<li><a href="#creer-un-graphique-personnalise-avec-peu-de-code-r">Cr?er un graphique personnalis? avec peu de code R</a></li>
<li><a href="#faceting-separer-un-graphique-en-plusieurs-panels-de-graphiques">Faceting : S?parer un graphique en plusieurs panels de graphiques</a><ul>
<li><a href="#faceting-avec-une-variable">Faceting avec une variable</a></li>
<li><a href="#faceting-avec-deux-variables">Faceting avec deux variables</a></li>
<li><a href="#echelle-des-pannels">Echelle des pannels</a></li>
<li><a href="#apparence-des-etiquettes-des-pannels">Apparence des ?tiquettes des pannels</a></li>
</ul></li>
<li><a href="#la-fonction-ggplot2.histogram">La fonction ggplot2.histogram</a><ul>
<li><a href="#description">Description</a></li>
<li><a href="#utilisation">Utilisation</a></li>
<li><a href="#arguments">Arguments</a></li>
<li><a href="#exemples">Exemples</a></li>
<li><a href="#references">R?f?rences</a></li>
</ul></li>
</ul>
</div>

<hr />
<pre class="warning"><code>Cette analyse a ?t? faite avec R (ver. 3.1.0), easyGgplot2 (ver 1.0.0) et ggplot2 (ver 1.0.0).</code></pre>
<div id="objectif" class="section level2">
<h2>Objectif</h2>
<p><strong>ggplot2.histogram</strong> est une fonction permettant de dessiner facilement un histogramme avec le package R <strong>ggplot2</strong>. L'objectif de ce document est de vous montrer ?tape par ?tape, comment dessiner et personnaliser un histogramme avec la fonction ggplot2.histogram. A la fin de cet article, vous allez pouvoir faire avec peu de code R, les graphiques suivants:</p>
<p><img src="https://www.sthda.com/french/french/sthda/RDoc/figure/easyGgplot2/ggplot2_histogram-demo1.png" title="ggplot2 histogram" alt="ggplot2 histogram" width="432" /><img src="https://www.sthda.com/french/french/sthda/RDoc/figure/easyGgplot2/ggplot2_histogram-demo2.png" title="ggplot2 histogram" alt="ggplot2 histogram" width="432" /></p>
<pre class="warning"><code>Les arguments de la fonction ggplot2.histogram sont d?crites ? la fin de ce document.</code></pre>
</div>
<div id="installer-et-charger-le-package-easyggplot2" class="section level2">
<h2>Installer et charger le package easyGgplot2</h2>
<p>Pour installer le package, il faut utiliser le code R suivant (R >=3.1.0) :</p>
<pre class="r"><code>install.packages("devtools")
library(devtools)
install_github("easyGgplot2", "kassambara")</code></pre>
<p>Charger le package dans R:</p>
<pre class="r"><code>library(easyGgplot2)</code></pre>
</div>
<div id="format-des-donnees" class="section level2">
<h2>Format des donn?es</h2>
<p><span class="blue"><strong>Les donn?es doivent ?tre un vecteur de type num?rique ou une data.frame (les colonnes sont les variables et les lignes sont les observations).</strong></span>. Le jeu de donn?e <strong>weight</strong> du package easyGgplot2 sera utilis? dans les exemples suivants.</p>
<pre class="r"><code>#cr?er un vecteur de type num?rique
numVector<-rnorm(100)
head(numVector)</code></pre>
<pre><code>## [1] -1.8365  0.1651 -0.9171  0.3255 -1.7871 -0.1263</code></pre>
<pre class="r"><code>#data.frame
head(weight)</code></pre>
<pre><code>##      sex weight
## 1 Female  63.79
## 2 Female  65.28
## 3 Female  66.08
## 4 Female  62.65
## 5 Female  65.43
## 6 Female  65.51</code></pre>
</div>
<div id="histogramme-basic" class="section level2">
<h2>Histogramme basic</h2>
<pre class="r"><code>#Histogramme avec un vecteur de type num?rique
#ggplot2.histogram(data=numVector)

#Histogramme basic avec le vecteur "weight"
ggplot2.histogram(data=weight, xName=&#39;weight&#39;)

#Changer la largeur des barres (binwidth)
ggplot2.histogram(data=weight, xName=&#39;weight&#39;, binwidth=0.1)

#Changer l&#39;axe des y pour montrer la densit?
ggplot2.histogram(data=weight, xName=&#39;weight&#39;, scale="density")</code></pre>
<p><img src="https://www.sthda.com/french/french/sthda/RDoc/figure/easyGgplot2/ggplot2_histogram-basic_histogram1.png" title="ggplot2 histogram" alt="ggplot2 histogram" width="288" /><img src="https://www.sthda.com/french/french/sthda/RDoc/figure/easyGgplot2/ggplot2_histogram-basic_histogram2.png" title="ggplot2 histogram" alt="ggplot2 histogram" width="288" /><img src="https://www.sthda.com/french/french/sthda/RDoc/figure/easyGgplot2/ggplot2_histogram-basic_histogram3.png" title="ggplot2 histogram" alt="ggplot2 histogram" width="288" /></p>
</div>
<div id="changer-lorientation-de-lhistogramme" class="section level2">
<h2>Changer l'orientation de l'histogramme</h2>
<pre class="r"><code>#Changer l&#39;orientation: histogramme horizontal
ggplot2.histogram(data=weight, xName=&#39;weight&#39;, orientation="horizontal")

#Mettre l&#39;axe des y ? l&#39;envers
ggplot2.histogram(data=weight, xName=&#39;weight&#39;, orientation="yAxisReversed")</code></pre>
<p><img src="https://www.sthda.com/french/french/sthda/RDoc/figure/easyGgplot2/ggplot2_histogram-orientation1.png" title="ggplot2 histogram" alt="ggplot2 histogram" width="288" /><img src="https://www.sthda.com/french/french/sthda/RDoc/figure/easyGgplot2/ggplot2_histogram-orientation2.png" title="ggplot2 histogram" alt="ggplot2 histogram" width="288" /></p>
</div>
<div id="ajouter-la-ligne-de-la-moyenne-et-la-courbe-de-densite" class="section level2">
<h2>Ajouter la ligne de la moyenne et la courbe de densit?</h2>
<pre class="r"><code>#Ajouter la ligne de la moyenne ? l&#39;histogram.
#Changer la couleur de remplissage (fill) et la couleur des lignes
ggplot2.histogram(data=weight, xName=&#39;weight&#39;,
                  fill="white", color="black",
                  addMeanLine=TRUE, meanLineColor="red", meanLineType="dashed", meanLineSize=1)

#Ajouter la courbe de densit?
ggplot2.histogram(data=weight, xName=&#39;weight&#39;,
                  fill="white", color="black",
                  addDensityCurve=TRUE, densityFill=&#39;#FF6666&#39;)</code></pre>
<p><img src="https://www.sthda.com/french/french/sthda/RDoc/figure/easyGgplot2/ggplot2_histogram-mean_line_and_density_curve1.png" title="plot of chunk mean_line_and_density_curve" alt="plot of chunk mean_line_and_density_curve" width="288" /><img src="https://www.sthda.com/french/french/sthda/RDoc/figure/easyGgplot2/ggplot2_histogram-mean_line_and_density_curve2.png" title="plot of chunk mean_line_and_density_curve" alt="plot of chunk mean_line_and_density_curve" width="288" /></p>
</div>
<div id="changer-le-type-de-ligne-de-lhistogramme" class="section level2">
<h2>Changer le type de ligne de l'histogramme</h2>
<p><span class="warning"> Diff?rents types de points et de types de lignes peuvent ?tre utilis?s. Par d?faut, ggplot2 utilise une ligne pleine (solide) et un cercle pour les points. </span></p>
<p>Les diff?rents types de points et de lignes disponibles dans R sont montr?s ci-dessous :</p>
<p><img src="https://www.sthda.com/french/french/sthda/RDoc/figure/easyGgplot2/r_point_shapes_linetypes1.png" title="plot of chunk r_point_shapes_linetypes" alt="plot of chunk r_point_shapes_linetypes" width="288" /><img src="https://www.sthda.com/french/french/sthda/RDoc/figure/easyGgplot2/r_point_shapes_linetypes2.png" title="plot of chunk r_point_shapes_linetypes" alt="plot of chunk r_point_shapes_linetypes" width="288" /></p>
<pre class="r"><code>#Changer la couleur des traits et le type de lignes de l&#39;histogramme.
ggplot2.histogram(data=weight, xName=&#39;weight&#39;,
                  fill="white", color="black",
                  linetype="longdash")</code></pre>
<p><img src="https://www.sthda.com/french/french/sthda/RDoc/figure/easyGgplot2/ggplot2_histogram-linetype.png" title="ggplot2 histogram" alt="ggplot2 histogram" width="288" /></p>
</div>
<div id="histogramme-avec-plusieurs-groupes" class="section level2">
<h2>Histogramme avec plusieurs groupes</h2>
<pre class="r"><code>#Plusieurs histogrammes sur le m?me graphique
#Colorer l&#39;histogramme en fonction du nom de groupe "sex"
ggplot2.histogram(data=weight, xName=&#39;weight&#39;, groupName=&#39;sex&#39;)

#Histogramme avec un remplissage transparent.
#alpha est le d?gr? de transparence des couleurs chevauchantes
ggplot2.histogram(data=weight, xName=&#39;weight&#39;, groupName=&#39;sex&#39;, alpha=0.5 )

#Histogramme avec la ligne des moyennes
ggplot2.histogram(data=weight, xName=&#39;weight&#39;, groupName=&#39;sex&#39;,
    alpha=0.5, addDensity=TRUE,
    addMeanLine=TRUE, meanLineColor="white", meanLineSize=1.5)</code></pre>
<p><img src="https://www.sthda.com/french/french/sthda/RDoc/figure/easyGgplot2/ggplot2_histogram-multiple_groups1.png" title="Histogram with multiple groups" alt="Histogram with multiple groups" width="384" /><img src="https://www.sthda.com/french/french/sthda/RDoc/figure/easyGgplot2/ggplot2_histogram-multiple_groups2.png" title="Histogram with multiple groups" alt="Histogram with multiple groups" width="384" /><img src="https://www.sthda.com/french/french/sthda/RDoc/figure/easyGgplot2/ggplot2_histogram-multiple_groups3.png" title="Histogram with multiple groups" alt="Histogram with multiple groups" width="384" /></p>
<pre class="success"><code>Ajuster la position des histogrammes superpos?s en utilisant l&#39;argument position. Les valeurs possibles pour l&#39;argument position sont "identity", "stack", "dodge".</code></pre>
<pre class="r"><code>#La valeur par d?faut de position est "identity"
ggplot2.histogram(data=weight, xName=&#39;weight&#39;, groupName=&#39;sex&#39;, alpha=0.5, position="identity")

# Histogramme entrelac?
ggplot2.histogram(data=weight, xName=&#39;weight&#39;, groupName=&#39;sex&#39;, alpha=0.5, position="dodge")

#Histogramme empil?
ggplot2.histogram(data=weight, xName=&#39;weight&#39;, groupName=&#39;sex&#39;, alpha=0.5, position="stack")</code></pre>
<p><img src="https://www.sthda.com/french/french/sthda/RDoc/figure/easyGgplot2/ggplot2_histogram-multiple_groups_position1.png" title="Histogram with multiple groups" alt="Histogram with multiple groups" width="384" /><img src="https://www.sthda.com/french/french/sthda/RDoc/figure/easyGgplot2/ggplot2_histogram-multiple_groups_position2.png" title="Histogram with multiple groups" alt="Histogram with multiple groups" width="384" /><img src="https://www.sthda.com/french/french/sthda/RDoc/figure/easyGgplot2/ggplot2_histogram-multiple_groups_position3.png" title="Histogram with multiple groups" alt="Histogram with multiple groups" width="384" /></p>
</div>
<div id="personnaliser-votre-histogramme" class="section level2">
<h2>Personnaliser votre histogramme</h2>
<div id="titre-principal-et-etiquettes-des-axes" class="section level3">
<h3>Titre principal et etiquettes des axes</h3>
<p><span class="blue"><strong>Les param?tres qui peuvent ?tre utilis?s pour personnaliser l'axe des x et des y sont list?s ci-dessous :</strong></span></p>
<table>
<thead>
<tr class="header">
<th align="left">Param?tres</th>
<th align="left">Description</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td align="left"><strong>xShowTitle, yShowTitle</strong></td>
<td align="left">si TRUE, le titre des axes x et y sera affich?. Mettre la valeur ? FALSE pour cacher le titre des axes. La valeur par d?faut est <code>TRUE</code>.</td>
</tr>
<tr class="even">
<td align="left"><strong>xtitle, ytitle</strong></td>
<td align="left">Titres des axes x et y. La valeur par d?faut est <code>NULL</code>.</td>
</tr>
<tr class="odd">
<td align="left"><strong>xtitleFont, ytitleFont</strong></td>
<td align="left">Un vecteur de longueur 3 indiquant respectivement la taille, le style et la couleur du titre des axes x et y. Les valeurs possibles pour le <strong>style</strong> : "plain", "italic", "bold", "bold.italic". La couleur peut ?tre sp?cifi?e par le code hexad?cimal(i.e: "#FFCC00") ou par le nom (i.e : "red", "green"). Valeurs par d?faut : <code>xtitleFont=c(14,"bold", "black"), ytitleFont=c(14,"bold", "black")</code>.</td>
</tr>
<tr class="even">
<td align="left"><strong>xlim, ylim</strong></td>
<td align="left">Limite des axes x et y. Valeur par d?faut : <code>NULL</code>.</td>
</tr>
<tr class="odd">
<td align="left"><strong>xScale, yScale</strong></td>
<td align="left">Echelle des axes x et y. Valeurs possibles : c("none", "log2", "log10"). e.g: yScale="log2". Valeur par d?faut : <code>NULL</code>.</td>
</tr>
<tr class="even">
<td align="left"><strong>xShowTickLabel, yShowTickLabel</strong></td>
<td align="left">si TRUE, les ?tiquettes des graduations axes x et y seront affich?es. Valeur par d?faut : <code>TRUE</code>.</td>
</tr>
<tr class="odd">
<td align="left"><strong>xTickLabelFont, yTickLabelFont</strong></td>
<td align="left">Un vecteur de longueur 3 indiquant respectivement la taille, le style et la couleur des ?tiquettes des graduations des axes x et y. Valeur par d?faut : <code>xTickLabelFont=c(12, "bold", "black"), yTickLabelFont=c(12, "bold", "black")</code>.</td>
</tr>
<tr class="even">
<td align="left"><strong>xtickLabelRotation, ytickLabelRotation</strong></td>
<td align="left">Angle de rotation des ?tiquettes des graduations des axes x et y. Valeur par d?faut : <code>0</code>.</td>
</tr>
<tr class="odd">
<td align="left"><strong>hideAxisTicks</strong></td>
<td align="left">si TRUE, les graduations des axes x et y sont cach?es. Valeur par d?faut : <code>FALSE</code>.</td>
</tr>
<tr class="even">
<td align="left"><strong>axisLine</strong></td>
<td align="left">Un vecteur de longueur 3 indiquant respectivement, la taille, le type de ligne et la couleur des lignes des axes. Valeur par d?faut : <code>c(0.5, "solid", "#E5E5E5")</code>.</td>
</tr>
</tbody>
</table>
<div id="titres" class="section level4">
<h4>Titres</h4>
<pre class="r"><code>#Graphique basic
plot<-ggplot2.histogram(data=weight, xName=&#39;weight&#39;)
#print(plot)

#Changer le titre principal et le titre des axes
ggplot2.customize(plot,mainTitle="Plot of weight histogram curve",
                xtitle="Weight (Kg)", ytitle="Histogram")

#Personnaliser le texte des titres.
#Valeurs possibles pour le style:&#39;plain&#39;, &#39;italic&#39;, &#39;bold&#39;, &#39;bold.italic&#39;.
ggplot2.customize(plot,  mainTitle="Plot of weight histogram curve",
                mainTitleFont=c(14,"bold.italic", "red"),
                xtitle="Weight (Kg)", ytitle="Histogram",
                xtitleFont=c(14,"bold", "#993333"), ytitleFont=c(14,"bold", "#993333"))

#Cacher le titre des axes x et y
ggplot2.customize(plot, xShowTitle=FALSE, yShowTitle=FALSE)</code></pre>
<p><img src="https://www.sthda.com/french/french/sthda/RDoc/figure/easyGgplot2/ggplot2_histogram-title1.png" title="ggplot2 histogram" alt="ggplot2 histogram" width="288" /><img src="https://www.sthda.com/french/french/sthda/RDoc/figure/easyGgplot2/ggplot2_histogram-title2.png" title="ggplot2 histogram" alt="ggplot2 histogram" width="288" /><img src="https://www.sthda.com/french/french/sthda/RDoc/figure/easyGgplot2/ggplot2_histogram-title3.png" title="ggplot2 histogram" alt="ggplot2 histogram" width="288" /></p>
</div>
<div id="graduation-des-axes" class="section level4">
<h4>Graduation des axes</h4>
<pre class="r"><code>#Orientation des etiquettes des graduations des axes
ggplot2.histogram(data=weight, xName=&#39;weight&#39;,
                xShowTitle=FALSE, yShowTitle=FALSE,
                xTickLabelFont=c(14,"bold", "#993333"),yTickLabelFont=c(14,"bold", "#993333"),
                xtickLabelRotation=45, ytickLabelRotation=45)

#Cacher les ?tiquettes des graduations des axes
ggplot2.histogram(data=weight, xName=&#39;weight&#39;,
                xShowTitle=FALSE, yShowTitle=FALSE,
                xShowTickLabel=FALSE, yShowTickLabel=FALSE)

#Cacher les graduations des axes
ggplot2.histogram(data=weight, xName=&#39;weight&#39;,
                xShowTitle=FALSE, yShowTitle=FALSE,
                xShowTickLabel=FALSE, yShowTickLabel=FALSE,hideAxisTicks=TRUE)

#AxisLine : Un vecteur de longueur 3 indiquant la taille,
  #le type et la couleur des lignes des axes. 
ggplot2.histogram(data=weight, xName=&#39;weight&#39;, axisLine=c(1, "solid", "darkblue"))</code></pre>
<p><img src="https://www.sthda.com/french/french/sthda/RDoc/figure/easyGgplot2/ggplot2_histogram-axis_ticks1.png" title="ggplot2 histogram" alt="ggplot2 histogram" width="288" /><img src="https://www.sthda.com/french/french/sthda/RDoc/figure/easyGgplot2/ggplot2_histogram-axis_ticks2.png" title="ggplot2 histogram" alt="ggplot2 histogram" width="288" /><img src="https://www.sthda.com/french/french/sthda/RDoc/figure/easyGgplot2/ggplot2_histogram-axis_ticks3.png" title="ggplot2 histogram" alt="ggplot2 histogram" width="288" /><img src="https://www.sthda.com/french/french/sthda/RDoc/figure/easyGgplot2/ggplot2_histogram-axis_ticks4.png" title="ggplot2 histogram" alt="ggplot2 histogram" width="288" /></p>
</div>
</div>
<div id="fond-et-couleurs" class="section level3">
<h3>Fond et couleurs</h3>
<div id="changer-le-fond-et-la-couleur-de-remplissage-de-lhistogramme" class="section level4">
<h4>Changer le fond et la couleur de remplissage de l'histogramme</h4>
<pre class="r"><code>#Changer la couleur de fond en "white". Couleur par d?faut : "gray"
ggplot2.histogram(data=weight, xName=&#39;weight&#39;,
                backgroundColor="white")

#Changer la couleur de fond en "lightblue" 
#et la couleur du quadrillage en "white"
ggplot2.histogram(data=weight, xName=&#39;weight&#39;,
                backgroundColor="lightblue", gridColor="white")

#Changer la couleur de remplissage
#color =  colore la bordure de l&#39;histogramme
ggplot2.histogram(data=weight, xName=&#39;weight&#39;,
                backgroundColor="white", color="black", fill=&#39;#FFAAD4&#39;)

#Supprimer le quadrillage; supprimer les bordures autour du graphique;
#Changer la ligne des axes
ggplot2.histogram(data=weight, xName=&#39;weight&#39;,
                backgroundColor="white", color="black", fill=&#39;#FFAAD4&#39;,
                removePanelGrid=TRUE,removePanelBorder=TRUE,
                axisLine=c(0.5, "solid", "black"))

#Remplir l&#39;histogramme en fonction de la valeur du compte (..count..)
ggplot2.histogram(data=weight, xName=&#39;weight&#39;)+
  geom_histogram(aes(fill = ..count..))

#Remplissage par gradient d&#39;intensit?
ggplot2.histogram(data=weight, xName=&#39;weight&#39;)+
  geom_histogram(aes(fill = ..count..))+
   scale_fill_gradient("Count", low = "green", high = "red")</code></pre>
<p><img src="https://www.sthda.com/french/french/sthda/RDoc/figure/easyGgplot2/ggplot2_histogram-background_color1.png" title="ggplot2 histogram" alt="ggplot2 histogram" width="288" /><img src="https://www.sthda.com/french/french/sthda/RDoc/figure/easyGgplot2/ggplot2_histogram-background_color2.png" title="ggplot2 histogram" alt="ggplot2 histogram" width="288" /><img src="https://www.sthda.com/french/french/sthda/RDoc/figure/easyGgplot2/ggplot2_histogram-background_color3.png" title="ggplot2 histogram" alt="ggplot2 histogram" width="288" /><img src="https://www.sthda.com/french/french/sthda/RDoc/figure/easyGgplot2/ggplot2_histogram-background_color4.png" title="ggplot2 histogram" alt="ggplot2 histogram" width="288" /><img src="https://www.sthda.com/french/french/sthda/RDoc/figure/easyGgplot2/ggplot2_histogram-background_color5.png" title="ggplot2 histogram" alt="ggplot2 histogram" width="288" /><img src="https://www.sthda.com/french/french/sthda/RDoc/figure/easyGgplot2/ggplot2_histogram-background_color6.png" title="ggplot2 histogram" alt="ggplot2 histogram" width="288" /></p>
</div>
<div id="specifications-des-couleurs" class="section level4">
<h4>Sp?cifications des couleurs</h4>
<p><span class="warning"> Les couleurs peuvent ?tre sp?cifi?es en utilisant du code hexad?cimal, tel que <strong>"#FFCC00"</strong>. Vous pouvez ?galement utiliser des couleurs provenant du package <strong>RColorBrewer</strong>. <span></p>
<table>
<thead>
<tr class="header">
<th align="left">Code hexad?cimal</th>
<th align="left">Palettes RColorBrewer</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td align="left"><img src="https://www.sthda.com/french/french/sthda/RDoc/images/color_codes_hex.png" alt="Hexadecimal color code" /></td>
<td align="left"><img src="https://www.sthda.com/french/french/sthda/RDoc/images/rcolorbrewer.png" alt="RColorBrewer" /></td>
</tr>
</tbody>
</table>
<p>Le code R suivant peut ?tre utilis? pour afficher les palettes RColorBrewer:</p>
<pre class="r"><code>rquery.loadPackages("RColorBrewer")
#Afficher toutes les palettes du packages
display.brewer.all()
#Afficher une seule palette en sp?cifiant le nom
display.brewer.pal(n = 8, name = &#39;Dark2&#39;)
#Afficher le code hexad?cimal d&#39;une palette
brewer.pal(n = 8, name = "Dark2")</code></pre>
<p><span class="warning"> Les couleurs peuvent ?tre sp?cifi?es en utilisant le nom, tel que <strong>"red", "blue", "lightblue"</strong>. Vous trouverez ci-dessous, un graphique de certains des noms de couleurs reconnues par R.</span></p>
<p><span class="blue"><strong>Pour voir l'ensemble des couleurs reconnues par R ( n = 657), utiliser le code R suivant:</strong></span></p>
<pre class="r"><code>colornames<-colors()
head(colornames)
showCols(cl=colornames, bg="gray33", rot=30, cex=0.75)</code></pre>
<p>Les 200 premi?res couleurs sont montr?es ci-dessous :</p>
<p><img src="https://www.sthda.com/french/french/sthda/RDoc/figure/easyGgplot2/r_colornames1.png" title="plot of chunk r_colornames" alt="plot of chunk r_colornames" width="432" /><img src="https://www.sthda.com/french/french/sthda/RDoc/figure/easyGgplot2/r_colornames2.png" title="plot of chunk r_colornames" alt="plot of chunk r_colornames" width="432" /></p>
</div>
<div id="changer-la-couleur-des-histogrammes-en-fonction-du-groupe" class="section level4">
<h4>Changer la couleur des histogrammes en fonction du groupe</h4>
<p><span class="warning">Pour changer la couleur en fonction du groupe, vous devez indiquer le nom de la colonne contenant les groupes en utilisant le param?tre <strong>groupName</strong>. Il faut utiliser l'argument <strong>groupColors</strong>, pour sp?cifier les couleurs par le code hexad?cimal ou par le nom. Dans ce cas, la longueur du param?tre groupColors devrait ?tre la m?me que le nombre de groupes. Il faut utiliser l'argument <strong>brewerPalette</strong>, pour sp?cifier la couleur en utilisant les palettes RColorBrewer.</span></p>
<pre class="r"><code>#Changer la couleur des groupes en utilisant le code hexad?cimal. 
#alpha est le d?gr? de transparence des couleurs ch?vauchantes
  #La valeur peut varier de 0 (transparence totale) ? 1 (pas de transparence)
ggplot2.histogram(data=weight, xName=&#39;weight&#39;, groupName=&#39;sex&#39;,
                groupColors=c(&#39;#999999&#39;,&#39;#E69F00&#39;),alpha=0.5 )

#Changer la couleur des groupes en utilisant l&#39;argument brewerPalette: "Paired"
ggplot2.histogram(data=weight, xName=&#39;weight&#39;, groupName=&#39;sex&#39;,
                brewerPalette="Paired",alpha=0.5)

#Changer la couleur des groupes en utilisant le nom des couleurs
ggplot2.histogram(data=weight, xName=&#39;weight&#39;, groupName=&#39;sex&#39;,
                groupColors=c(&#39;aquamarine3&#39;,&#39;goldenrod1&#39;),alpha=0.5 )</code></pre>
<p><img src="https://www.sthda.com/french/french/sthda/RDoc/figure/easyGgplot2/ggplot2_histogram-histogram_color1.png" title="ggplot2 histogram" alt="ggplot2 histogram" width="384" /><img src="https://www.sthda.com/french/french/sthda/RDoc/figure/easyGgplot2/ggplot2_histogram-histogram_color2.png" title="ggplot2 histogram" alt="ggplot2 histogram" width="384" /><img src="https://www.sthda.com/french/french/sthda/RDoc/figure/easyGgplot2/ggplot2_histogram-histogram_color3.png" title="ggplot2 histogram" alt="ggplot2 histogram" width="384" /></p>
</div>
</div>
<div id="legende" class="section level3">
<h3>L?gende</h3>
<div id="position-de-la-legende" class="section level4">
<h4>Position de la l?gende</h4>
<pre class="r"><code>#Changer la position de la l?gende en "top" (Valeurs possibles: "top", "left", "right", "bottom")
ggplot2.histogram(data=weight, xName=&#39;weight&#39;, groupName=&#39;sex&#39;, alpha=0.5,
                legendPosition="top")

#legendPosition peut ?tre aussi un vecteur de type num?rique c(x, y) indiquant les coordonn?es
#Les valeurs de x et y doivent ?tres entre 0 et 1. c(0,0) corresponds ? "bottom left"
# et c(1, 1) correspond ? "top right" position
ggplot2.histogram(data=weight, xName=&#39;weight&#39;, groupName=&#39;sex&#39;, alpha=0.5,
                legendPosition=c(0.8,0.2))

#Remove legend
ggplot2.histogram(data=weight, xName=&#39;weight&#39;, groupName=&#39;sex&#39;, alpha=0.5,
                showLegend=FALSE)</code></pre>
<p><img src="https://www.sthda.com/french/french/sthda/RDoc/figure/easyGgplot2/ggplot2_histogram-legend_position1.png" title="ggplot2 histogram" alt="ggplot2 histogram" width="288" /><img src="https://www.sthda.com/french/french/sthda/RDoc/figure/easyGgplot2/ggplot2_histogram-legend_position2.png" title="ggplot2 histogram" alt="ggplot2 histogram" width="288" /><img src="https://www.sthda.com/french/french/sthda/RDoc/figure/easyGgplot2/ggplot2_histogram-legend_position3.png" title="ggplot2 histogram" alt="ggplot2 histogram" width="288" /></p>
<p><span class="warning">Il est aussi possible de mettre la l?gende ? l'int?rieur du graphique. Vous avez juste ? indiquer les coordonn?es x et y de la l?gende. Les valeurs de x et y doivent ?tre entre 0 et 1. c(0,0) correspond ? <strong>"bottom left"</strong> et c(1,1) correspond ? la position <strong>"top right"</strong>.</span></p>
</div>
<div id="couleur-de-fond-de-la-legende-titre-et-style-des-textes" class="section level4">
<h4>Couleur de fond de la l?gende, titre et style des textes</h4>
<pre class="r"><code>#Changer la couleur de fond de la l?gende, le titre et le style des textes 
ggplot2.histogram(data=weight, xName=&#39;weight&#39;, groupName=&#39;sex&#39;, alpha=0.5,
                #legendTitleFont=c(size, style, color)
                legendTitle="Groups", legendTitleFont=c(10, "bold", "blue"),
                legendTextFont=c(10, "bold.italic", "red"),#legendTextFont=c(size, style, color)
                #legendBackground: c(fill, lineSize, lineType, lineColor)
                legendBackground=c("lightblue", 0.5, "solid", "darkblue" )
                )</code></pre>
<p><img src="https://www.sthda.com/french/french/sthda/RDoc/figure/easyGgplot2/ggplot2_histogram-legend_background_and_title.png" title="ggplot2 histogram" alt="ggplot2 histogram" width="384" /></p>
</div>
</div>
<div id="echelle-des-axes" class="section level3">
<h3>Echelle des axes</h3>
<p>Les valeurs possibles pour l'?chelle de l'axe x sont : "none", "log2" et log10. Valeur par d?faut : "none".</p>
<pre class="r"><code>#Changer la limite des axes
ggplot2.histogram(data=weight, xName=&#39;weight&#39;, groupName=&#39;sex&#39;, alpha=0.5,
                showLegend=FALSE, xlim=c(60,72))

#Echelle log. xScale="log2". (valeur possible="none", "log2" and "log10")
  #Valeur par d?faut: "none"
ggplot2.histogram(data=weight, xName=&#39;weight&#39;, groupName=&#39;sex&#39;, alpha=0.5,
                showLegend=FALSE, xScale="log2")</code></pre>
<p><img src="https://www.sthda.com/french/french/sthda/RDoc/figure/easyGgplot2/ggplot2_histogram-axis_scale1.png" title="ggplot2 histogram" alt="ggplot2 histogram" width="384" /><img src="https://www.sthda.com/french/french/sthda/RDoc/figure/easyGgplot2/ggplot2_histogram-axis_scale2.png" title="ggplot2 histogram" alt="ggplot2 histogram" width="384" /></p>
</div>
</div>
<div id="creer-un-graphique-personnalise-avec-peu-de-code-r" class="section level2">
<h2>Cr?er un graphique personnalis? avec peu de code R</h2>
<pre class="r"><code>#Graphique basic
plot<-ggplot2.histogram(data=weight, xName=&#39;weight&#39;, groupName=&#39;sex&#39;,
                addMeanLine=TRUE, showLegend=FALSE,
                groupColors=c(&#39;#999999&#39;,&#39;#E69F00&#39;), alpha=0.5,
                backgroundColor="white")
#print(plot)

#Histogramme personnalis?
plot<-ggplot2.customize(plot, xtitle="Weight (Kg)", ytitle="Count",  showLegend=FALSE, 
                mainTitle="Plot of weight histogram \nper sex")                
print(plot)


#Supprimer le quadrillage; supprimer les bordures autour du graphique; 
#Ajouter la courbe de densit? et la ligne de moyennes
ggplot2.customize(plot, removePanelGrid=TRUE,removePanelBorder=TRUE,
                 axisLine=c(0.5, "solid", "black"),
                addDensity=TRUE, showLegend=FALSE)</code></pre>
<p><img src="https://www.sthda.com/french/french/sthda/RDoc/figure/easyGgplot2/ggplot2_histogram-customized_plot1.png" title="ggplot2 histogram" alt="ggplot2 histogram" width="384" /><img src="https://www.sthda.com/french/french/sthda/RDoc/figure/easyGgplot2/ggplot2_histogram-customized_plot2.png" title="ggplot2 histogram" alt="ggplot2 histogram" width="384" /></p>
<pre class="success"><code>L&#39;argument alpha est utilis? pour la transparence des couleurs.</code></pre>
</div>
<div id="faceting-separer-un-graphique-en-plusieurs-panels-de-graphiques" class="section level2">
<h2>Faceting : S?parer un graphique en plusieurs panels de graphiques</h2>
<p>L'approche faceting s?pare un graphique en plusieurs panels. Chaque panel repr?sente une partie du jeu de donn?es.</p>
<div id="faceting-avec-une-variable" class="section level3">
<h3>Faceting avec une variable</h3>
<pre class="r"><code>#Facet en fonction de la variable "sex"
ggplot2.histogram(data=weight, xName=&#39;weight&#39;, groupName=&#39;sex&#39;, legendPosition="top",
            faceting=TRUE, facetingVarNames="sex") 

#Changer la direction. Valeurs possibles : "vertical", horizontal". Valeur par d?faut: vertical.
ggplot2.histogram(data=weight, xName=&#39;weight&#39;, groupName=&#39;sex&#39;, legendPosition="top",
            faceting=TRUE, facetingVarNames="sex", facetingDirection="horizontal") </code></pre>
<p><img src="https://www.sthda.com/french/french/sthda/RDoc/figure/easyGgplot2/ggplot2_histogram-facet_with_one_variable1.png" title="ggplot2 histogram and faceting approch" alt="ggplot2 histogram and faceting approch" width="384" /><img src="https://www.sthda.com/french/french/sthda/RDoc/figure/easyGgplot2/ggplot2_histogram-facet_with_one_variable2.png" title="ggplot2 histogram and faceting approch" alt="ggplot2 histogram and faceting approch" width="384" /></p>
</div>
<div id="faceting-avec-deux-variables" class="section level3">
<h3>Faceting avec deux variables</h3>
<p>Les donn?es <strong>mtcars</strong> sont utilis?es dans les exemples suivants.</p>
<pre class="r"><code>data(mtcars)
head(mtcars)</code></pre>
<pre><code>##                    mpg cyl disp  hp drat    wt  qsec vs am gear carb
## Mazda RX4         21.0   6  160 110 3.90 2.620 16.46  0  1    4    4
## Mazda RX4 Wag     21.0   6  160 110 3.90 2.875 17.02  0  1    4    4
## Datsun 710        22.8   4  108  93 3.85 2.320 18.61  1  1    4    1
## Hornet 4 Drive    21.4   6  258 110 3.08 3.215 19.44  1  0    3    1
## Hornet Sportabout 18.7   8  360 175 3.15 3.440 17.02  0  0    3    2
## Valiant           18.1   6  225 105 2.76 3.460 20.22  1  0    3    1</code></pre>
<p><span class="success"> <strong>mtcars</strong> (Motor Trend Car Road Tests) comprend la consommation de carburant et 10 aspects de la conception de l'automobile et de la performance pour 32 voitures. </span></p>
<pre class="r"><code>#Facet avec deux variables : vs et am.
#En ligne on a la variable vs et en colonne la variable am
ggplot2.histogram(data=mtcars, xName=&#39;mpg&#39;, groupName=&#39;vs&#39;, legendPosition="top",
                faceting=TRUE, facetingVarNames=c("vs", "am"))

#Facet avec deux variables: inverser l&#39;ordre des 2 variables.
#En ligne : am et en colonne :vs
ggplot2.histogram(data=mtcars, xName=&#39;mpg&#39;, groupName=&#39;vs&#39;, legendPosition="top",
                faceting=TRUE, facetingVarNames=c("am", "vs"))</code></pre>
<p><img src="https://www.sthda.com/french/french/sthda/RDoc/figure/easyGgplot2/ggplot2_histogram-facet_with_two_variable1.png" title="ggplot2 histogram and faceting approch" alt="ggplot2 histogram and faceting approch" width="384" /><img src="https://www.sthda.com/french/french/sthda/RDoc/figure/easyGgplot2/ggplot2_histogram-facet_with_two_variable2.png" title="ggplot2 histogram and faceting approch" alt="ggplot2 histogram and faceting approch" width="384" /></p>
</div>
<div id="echelle-des-pannels" class="section level3">
<h3>Echelle des pannels</h3>
<p>Par d?faut, tous les panels ont la m?me ?chelle (<code>facetingScales="fixed"</code>). Les ?chelles peuvent ?tre ind?pendantes, en utilisant les valeurs <code>free</code>, <code>free_x</code>, or <code>free_y</code>.</p>
<pre class="r"><code>#Facet avec des ?chelles ind?pendantes
ggplot2.histogram(data=mtcars, xName=&#39;mpg&#39;, groupName=&#39;vs&#39;, legendPosition="top",
                faceting=TRUE, facetingVarNames=c("vs", "am"), facetingScales="free")</code></pre>
<p><img src="https://www.sthda.com/french/french/sthda/RDoc/figure/easyGgplot2/ggplot2_histogram-facet_free_scale.png" title="ggplot2 histogram and faceting approch" alt="ggplot2 histogram and faceting approch" width="384" /></p>
<pre class="success"><code>Comme vous pouvez le constater sur le graphique ci-dessus, les pannels ont des ?chelles diff?rentes sur l&#39;axe des y. </code></pre>
</div>
<div id="apparence-des-etiquettes-des-pannels" class="section level3">
<h3>Apparence des ?tiquettes des pannels</h3>
<pre class="r"><code>#Changer le texte des panels
#Valeurs possibles pour le style:&#39;plain&#39;, &#39;italic&#39;, &#39;bold&#39;, &#39;bold.italic&#39;.
ggplot2.histogram(data=mtcars, xName=&#39;mpg&#39;, groupName=&#39;vs&#39;, legendPosition="top",
              faceting=TRUE, facetingVarNames=c("vs", "am"),
              facetingFont=c(12, &#39;bold.italic&#39;, "red"))

#Changer l&#39;apparence du rectangle autour des ?tiquettes des pannels
ggplot2.histogram(data=mtcars, xName=&#39;mpg&#39;, groupName=&#39;vs&#39;, legendPosition="top",
            faceting=TRUE, facetingVarNames=c("vs", "am"),
            facetingRect=list(background="white", lineType="solid", lineColor="black", lineSize=1.5))</code></pre>
<p><img src="https://www.sthda.com/french/french/sthda/RDoc/figure/easyGgplot2/ggplot2_histogram-facet_label_apperance1.png" title="ggplot2 histogram and faceting approch" alt="ggplot2 histogram and faceting approch" width="384" /><img src="https://www.sthda.com/french/french/sthda/RDoc/figure/easyGgplot2/ggplot2_histogram-facet_label_apperance2.png" title="ggplot2 histogram and faceting approch" alt="ggplot2 histogram and faceting approch" width="384" /></p>
</div>
</div>
<div id="la-fonction-ggplot2.histogram" class="section level2">
<h2>La fonction ggplot2.histogram</h2>
<div id="description" class="section level3">
<h3>Description</h3>
<p>Dessiner facilement un histogramme avec le package R ggplot2.</p>
</div>
<div id="utilisation" class="section level3">
<h3>Utilisation</h3>
<pre class="r"><code>ggplot2.histogram(data, xName=NULL, groupName=NULL,  position=c("identity", "stack", "dodge"),
                addMeanLine=FALSE, meanLineColor=NULL, meanLineType="dashed", meanLineSize=1,
                addDensityCurve=FALSE, densityFill="#FF6666", densityAlpha=0.2, 
                densityLineType="solid", densityLineColor="#2F2F2F",
                scale=c("frequency", "density"),groupColors=NULL, brewerPalette=NULL,...)</code></pre>
</div>
<div id="arguments" class="section level3">
<h3>Arguments</h3>
<table>
<thead>
<tr class="header">
<th align="left">Arguments</th>
<th align="left">Descriptions</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td align="left"><strong>data</strong></td>
<td align="left">data.frame ou vecteur de type num?rique. Les colonnes sont des variables et les lignes sont des observations.</td>
</tr>
<tr class="even">
<td align="left"><strong>xName</strong></td>
<td align="left">Nom de la colonne contenant la variable x. Valeur par d?faut : NULL.</td>
</tr>
<tr class="odd">
<td align="left"><strong>groupName</strong></td>
<td align="left">Nom de la colonne contenant la variable groupe. Cette variable est utilis?e pour colorer le graphique en fonction du groupe.</td>
</tr>
<tr class="even">
<td align="left"><strong>position</strong></td>
<td align="left">Ajuste la position des points ou des courbes chevauchantes. Valeurs possibles pour l'argument position : "identity", "stack", "dodge". Valeur par d?faut : "identity".</td>
</tr>
<tr class="odd">
<td align="left"><strong>addMeanLine</strong></td>
<td align="left">si TRUE, la ligne de la moyenne est ajout?e au graphique pour chaque groupe. Valeur par d?faut : FALSE.</td>
</tr>
<tr class="even">
<td align="left"><strong>meanLineColor, meanLineType, meanLineSize</strong></td>
<td align="left">Couleur, type et ?paisseur de la ligne de la moyenne.</td>
</tr>
<tr class="odd">
<td align="left"><strong>addDensityCurve</strong></td>
<td align="left">si TRUE, ajoute la courbe de densit?. Valeur par d?faut : FALSE.</td>
</tr>
<tr class="even">
<td align="left"><strong>densityFill</strong></td>
<td align="left">Couleur de remplissage de la courbe de densit?. Cette valeur est consid?r?e uniquement lorsque groupName=NULL. Si groupName est sp?cifi?, les courbes de densit? sont color?es en fonction de groupColors ou brewerPalette.</td>
</tr>
<tr class="odd">
<td align="left"><strong>densityAlpha</strong></td>
<td align="left">Degr? de transparence des couleurs chevauchantes pour les courbes de densit?. Valeur par d?faut : 0.2 (20%).</td>
</tr>
<tr class="even">
<td align="left"><strong>densityLineType, densityLineColor</strong></td>
<td align="left">Couleur et type de ligne pour la courbe de densit?.</td>
</tr>
<tr class="odd">
<td align="left"><strong>scale</strong></td>
<td align="left">Indique si l'axe des y doit ?tre en densit? ou en fr?quence. Valeur par d?faut : frequency.</td>
</tr>
<tr class="even">
<td align="left"><strong>groupColors</strong></td>
<td align="left">Colore des groupes. groupColors doit avoir une longueur identique au nombre de groupes.</td>
</tr>
<tr class="odd">
<td align="left"><strong>brewerPalette</strong></td>
<td align="left">Ceci peut ?tre utilis? aussi pour indiquer la couleur des groupes. Dans ce cas, le param?tre groupColors doit ?tre NULL. i.e: brewerPalette="Paired".</td>
</tr>
<tr class="even">
<td align="left"><strong>?.</strong></td>
<td align="left">D'autres arguments ? passer ? la fonction ggplot2.customize (easyGgplot2) ou aux fonctions geom_histogram et geom_density du package ggplot2.</td>
</tr>
</tbody>
</table>
<p><span class="warning"><strong>Les autres arguments qui peuvent ?tre utilis?s sont montr?s dans le tableau ci-dessous.</strong> Ils sont utilis?s pour personnaliser le graphique (axes, titre, arri?re plan, couleur, l?gende, ?.) g?n?rer par le package ggplot2.</span></p>
<table>
  <tr><th>
Arguments
</th><th>
Descriptions
</th> </tr>
  
<tr><td colspan=2 style="background-color:#336699; color:white;">
Personnaliser le titre du graphique
</td></tr>
  <tr><td>
<b>mainTitle</b>
</td><td>
Titre du graphique.
</td></tr>
  <tr><td>
<b>mainTitleFont</b>
</td><td>
Un vecteur de longueur 3 indiquant respectivement la taille, le style et la couleur du titre des axes x et y. Les valeurs possibles pour le style : "plain", "italic", "bold", "bold.italic". La couleur peut ?tre sp?cifi?e par le code hexad?cimal(i.e: "#FFCC00") ou par le nom (i.e : "red", "green"). <b/>Valeur par d?faut: mainTitleFont=c(14, "bold", "black").</b>
</td></tr>
  
<tr><td colspan=2 style="background-color:#336699; color:white;">
Personnaliser les axes x et y
</td></tr>
  <tr><td>
<b>xShowTitle, yShowTitle</b>
</td><td>
Si TRUE, le titre des axes x et y est affich?. <b>Valeur par d?faut : TRUE.</b>
</td></tr>
  <tr><td>
<b>xtitle, ytitle</b>
</td><td>
?tiquettes des axes x et y.
</td></tr>
  <tr><td>
<b>xtitleFont, ytitleFont</b>
</td><td> 
Un vecteur de longueur 3 indiquant respectivement la taille, le style et la couleur du titre des axes x et y. <b>Valeur par d?faut : c(14,"bold", "black").</b>
</td></tr>
  <tr><td>
<b>xlim, ylim</b>
</td><td>
Limite des axes x et y. <b>Valeur par d?faut : NULL</b>.
</td></tr>
  <tr><td>
<b>xScale, yScale</b>
</td><td>
Echelle des axes x et y. Valeurs possibles : c("none", "log2", "log10"). Exemple: yScale="log2". <b>Valeur par d?faut: "none".</b>
</td></tr>
  <tr><td>
<b>xShowTickLabel, yShowTickLabel</b>
</td><td>
si TRUE, les ?tiquettes des graduations des axes x et y seront affich?es. <b>Valeur par d?faut : TRUE.</b>
</td></tr>
  <tr><td>
<b>xTickLabelFont, yTickLabelFont</b>
</td><td>
Un vecteur de longueur 3 indiquant respectivement la taille, le style et la couleur des ?tiquettes des graduations des axes x et y. <b>Valeur par d?faut : c(12, "bold", "black").</b>
</td></tr>
  <tr><td>
<b>xtickLabelRotation, ytickLabelRotation</b>
</td><td>
Angle de rotation des ?tiquettes des graduations des axes x et y. <b>Valeurs par d?faut: 0</b>.
</td></tr>
  <tr><td>
<b>hideAxisTicks</b>
</td><td>
si TRUE, les graduations des axes x et y sont cach?es. <b>Valeur par d?faut : FALSE</b>.
</td></tr>
  <tr><td>
<b>axisLine</b>
</td><td>
Un vecteur de longueur 3 indiquant respectivement, la taille, le type de ligne et la couleur des lignes des axes.<b> Valeur par d?faut: c(0.5, "solid", "#E5E5E5").</b>
</td></tr>
  
<tr><td colspan=2 style="background-color:#336699; color:white;">
Personnaliser le fond du graphique
</td></tr>
  <tr><td>
<b>removePanelBorder</b>
</td><td>
si TRUE, supprime les bordures autour du graphique. <b>Valeur par d?faut: FALSE.</b>
</td></tr>
  <tr><td>
<b>removePanelGrid</b>
</td><td>
Si TRUE, le quadrillage est supprim?. <b>Valeur par d?faut: FALSE.</b>
</td></tr>
  <tr><td>
<b>backgroundColor</b>
</td><td>
Couleur de fond du graphique. <b>Valeur par d?faut: "gray".</b>
</td></tr>
  <tr><td>
<b>gridColor</b>
</td><td>
Couleur du quadrillage du graphique. <b>Valeur par d?faut: "white".</b>
</td></tr>
  
<tr><td colspan=2 style="background-color:#336699; color:white;">
Personnaliser la l?gende du graphique
</td></tr>
  <tr><td>
<b>showLegend</b>
</td><td>
Si TRUE, la l?gende du graphique est affich?e. <b>Valeur par d?faut TRUE</b>.
</td></tr>
  <tr><td>
<b>legendPosition</b>
</td><td>
Position de la l?gende. <b>Valeur par d?faut: "right"</b>. Valeurs possibles pour la position : "right", "left","top", "bottom". LegendPosition peut ?tre un vecteur de type num?rique c(x, y) indiquant les coordonn?es de la l?gende. x et y doivent ?tre entre 0 et 1. c(0,0) correspond ? "bottom left" et c(1,1) correspond ? la position "top right".
</td></tr>
  <tr><td>
<b>legendBackground</b>
</td><td>
Un vecteur de longueur 4 indiquant: le remplissage de la l?gende plus la taille, le type et la couleur des bordures de la l?gende. <b>Valeur par d?faut: legendBackground=c("#FFFFFF", 0.5, "blank", "black" ).</b>
</td></tr>
  <tr><td>
<b>legendTextFont</b>
</td><td>
Un vecteur de longueur 3 indiquant respectivement, la taille, le style et la couleur du texte de la l?gende. <b>Valeur par d?faut : c(10, "plain", "black")</b>. Valeurs possibles pour le style : "plain", "italic", "bold", "bold.italic".
</td></tr>
  <tr><td>
<b>legendTitleFont</b>
</td><td>
Un vecteur de longueur 3 indiquant respectivement, la taille, le style et la couleur du titre de la l?gende. <b>Valeur par d?faut : c(10, "plain", "black")</b>
</td></tr>
  <tr><td>
<b>legendItemOrder</b>
</td><td>
Un vecteur de texte indiquant l'ordre des ?l?ments de la l?gende. Exemple: c("2", "1", "0.5")
</td></tr>
  
<tr><td colspan=2 style="background-color:#336699; color:white;">
Faceting : Divise le graphique en plusieurs panels
</td></tr>
  <tr><td>
<b>faceting</b>
</td><td>
si TRUE, les donn?es sont coup?es en fonction d'une ou de deux variables, et le graphique est montr? dans diff?rents panels. Dans ce cas vous devez renseigner l'argument : facetingVarNames. <b>Valeur par d?faut : FALSE</b>.
</td></tr>
   <tr><td>
<b>facetingVarNames</b>
</td><td>
Nom des colonnes contenant les variables ? utiliser pour le faceting. <b>Valeur par d?faut: NULL</b>.
</td></tr>
   <tr><td>
<b>facetingDirection</b>
</td><td>
Valeurs possibles : "vertical" et "horizontal". <b>Valeur par d?faut : "vertical"</b>.
</td></tr>
<tr><td>
<b>facetingScales</b>
</td><td> 
Par d?faut, tous les panels ont la m?me ?chelle (<code>facetingScales="fixed"</code>). Les ?chelles peuvent ?tre ind?pendantes en utilisant les valeurs "free", "free_x", or "free_y". <b>Valeur par d?faut : "fixed"</b>.
</td></tr>
<tr><td>
<b>facetingFont</b>
</td><td>
Changer l'apparence des ?tiquettes des panels. Un vecteur de longueur 3, indiquant respectivement la taille, le style et la couleur du texte. <b>Valeur par d?faut: facetingFont=c(size=12, font="plain", color="black").</b>
</td></tr>
<tr><td>
<b>facetingRect</b>
</td><td>
Modifie l'apparence du rectangle autour des ?tiquettes des panels. <b>Valeur par d?faut : <span class="blue">list</span>(background=NULL, lineType=NULL, lineColor=NULL, lineSize=NULL).</b>
</td></tr>
<tr><td>
<b>facetingTextAngles</b>
</td><td>
Modifie l'orientation du texte des ?tiquettes des panels. Il indique les angles de rotation des textes en x et y ([0, 360]). <b>Valeur par d?faut c(NULL, NULL).</b>
</td></tr>

<tr><td colspan=2 style="background-color:#336699; color:white;">
Autres
</td></tr>
  <tr><td>
<b>orientation</b>
</td><td>
Change l'orientation du graphique. Valeurs possibles c("standard", "horizontal", "yAxisReversed"). <b>Valeur par d?faut: "standard"</b>.
</td></tr> 
</table>

<pre class="success"><code>Les valeurs possibles pour le style sont : "plain", "italic", "bold", "bold.italic". </code></pre>
</div>
<div id="exemples" class="section level3">
<h3>Exemples</h3>
<pre class="r"><code>#plot
plot<-ggplot2.histogram(data=weight, xName=&#39;weight&#39;,groupName=&#39;sex&#39;, groupColors=c(&#39;#999999&#39;,&#39;#E69F00&#39;))
plot<-ggplot2.customize(plot, mainTitle="Plot of weight histogram \nper sex",
                        xtitle="Weight (Kg)", ytitle="Histogram")
print(plot)</code></pre>
<p><br/></p>
</div>
<div id="references" class="section level3">
<h3>R?f?rences</h3>
<ul>
<li><a href="http://docs.ggplot2.org/current/">ggplot2 online documentation</a></li>
<li><a href="http://www.cookbook-r.com/Graphs/">Cookbook for R</a></li>
</ul>
</div>
</div>

<script>jQuery(document).ready(function () {jQuery('h1,h2,h3,h4').addClass('formatter-title');});//add phpboost class to header</script>
<style>.content{padding:0px;}</style>
</div><!--end rdoc-->
<!--====================== stop here when you copy to sthda================-->



<!-- END HTML -->]]></description>
			<pubDate>Sat, 01 Feb 2014 22:05:00 +0100</pubDate>
			
		</item>
		
		<item>
			<title><![CDATA[R2XLSX : lire, ?crire et formater un document Excel dans R]]></title>
			<link>https://www.sthda.com/french/articles/7-r/60-r2xlsx-lire-ecrire-et-formater-un-document-excel-dans-r/</link>
			<guid>https://www.sthda.com/french/articles/7-r/60-r2xlsx-lire-ecrire-et-formater-un-document-excel-dans-r/</guid>
			<description><![CDATA[<!-- START HTML -->
<ul id="toc"></ul>
<!-- END HTML --><br />
<br />
R2XLSX est un fichier  contenant un ensemble de fonctions R, que j'ai ?crite, permettant de lire et ?crire un fichier Excel dans R de mani?re simple et rapide. Il offre ?galement la possibilit? d'ajouter des graphiques et de formater les donn?es. <br />
<br />
<br />
<h3 class="formatter-title">Installation</h3><br />
<br />
Pour pouvoir utiliser les fonctions contenues dans le fichier R2XLSX, vous devez ex?cuter le code suivant ? chaque session R. Les fonctions d?pendent du package <strong>xlsx</strong>. Le package xlsx est automatiquement install? par le script dans le cas o? il n'existe pas.<br />
<br />
<span class="formatter-code">Code R :</span><div class="code"><pre style="display:inline;"><pre class="r" style="font-family:monospace;">&nbsp;
<span style="color: #0000FF; font-weight: bold;">source</span><span style="color: #080;">&#40;</span><span style="color: #ff0000;">"https://www.sthda.com/french/upload/r2xlsx.r"</span><span style="color: #080;">&#41;</span>
&nbsp;</pre></pre></div><br />
<br />
<h3 class="formatter-title">Les fonctions disponibles</h3><br />
<ul class="formatter-ul">
	<li class="formatter-li"><strong>xlsx.addPlot</strong> pour ajouter un graphique.
	</li><li class="formatter-li"><strong>xlsx.addParagraph</strong> pour ajouter un paragraphe de textes
	</li><li class="formatter-li"><strong>xlsx.addTable</strong> pour ajouter des tables.
	</li><li class="formatter-li"><strong>xlsx.addHeader</strong> pour ajouter des titres.
	</li><li class="formatter-li"><strong>xlsx.addLineBreak</strong> pour ajouter un saut de ligne.
	</li><li class="formatter-li"><strong>xlsx.addHyperlink</strong> pour ajouter un lien hypertext.
	</li><li class="formatter-li"><strong>xlsx.readFile</strong> pour lire un fichier excel.
	</li><li class="formatter-li"><strong>xlsx.writeFile</strong> pour ?crire un fichier excel.
        </li><li class="formatter-li"><strong>xlsx.openFile</strong> pour ouvrir le fichier excel.<br />
<br />
</li></ul><br />
<br />
<h3 class="formatter-title">Votre premier document Excel</h3><br />
<br />
<span class="formatter-code">Code R :</span><div class="code"><pre style="display:inline;"><pre class="r" style="font-family:monospace;">&nbsp;
<span style="color: #0000FF; font-weight: bold;">source</span><span style="color: #080;">&#40;</span><span style="color: #ff0000;">"https://www.sthda.com/french/upload/r2xlsx.r"</span><span style="color: #080;">&#41;</span>
&nbsp;
<span style="color: #228B22;">#create an Excel workbook. Both .xls and .xlsx file formats can be used.</span>
filename <span style="color: #080;"><-</span> <span style="color: #ff0000;">"Example1.xlsx"</span>
wb <span style="color: #080;"><-</span> createWorkbook<span style="color: #080;">&#40;</span>type<span style="color: #080;">=</span><span style="color: #ff0000;">"xlsx"</span><span style="color: #080;">&#41;</span>
<span style="color: #228B22;">#Create a sheet in that workbook to contain the table</span>
sheet <span style="color: #080;"><-</span> createSheet<span style="color: #080;">&#40;</span>wb, sheetName <span style="color: #080;">=</span> <span style="color: #ff0000;">"example1"</span><span style="color: #080;">&#41;</span>
&nbsp;
<span style="color: #228B22;">#Add header</span>
<span style="color: #228B22;">#+++++++++++++++++++++++++++++++</span>
xlsx.<span style="">addHeader</span><span style="color: #080;">&#40;</span>wb, sheet, value<span style="color: #080;">=</span><span style="color: #ff0000;">"Add table"</span>,level<span style="color: #080;">=</span><span style="color: #ff0000;">1</span>, color<span style="color: #080;">=</span><span style="color: #ff0000;">"black"</span>, underline<span style="color: #080;">=</span><span style="color: #ff0000;">1</span><span style="color: #080;">&#41;</span>
xlsx.<span style="">addLineBreak</span><span style="color: #080;">&#40;</span>sheet, <span style="color: #ff0000;">1</span><span style="color: #080;">&#41;</span>
&nbsp;
<span style="color: #228B22;">#Add Text :Author</span>
<span style="color: #228B22;">#+++++++++++++++++++++++++++++++</span>
xlsx.<span style="">addText</span><span style="color: #080;">&#40;</span>wb, sheet, 
             value<span style="color: #080;">=</span><span style="color: #ff0000;">"Author : Alboukadel KASSAMBARA. <span style="color: #000099; font-weight: bold;">\n</span>@:alboukadel.kassambara@gmail.com.<span style="color: #000099; font-weight: bold;">\n</span> Website : http://ww.sthda.com"</span>,
             isItalic<span style="color: #080;">=</span>TRUE, colSpan<span style="color: #080;">=</span><span style="color: #ff0000;">5</span>, rowSpan<span style="color: #080;">=</span><span style="color: #ff0000;">3</span>, fontColor<span style="color: #080;">=</span><span style="color: #ff0000;">"darkgray"</span>, fontSize<span style="color: #080;">=</span><span style="color: #ff0000;">14</span><span style="color: #080;">&#41;</span>
xlsx.<span style="">addLineBreak</span><span style="color: #080;">&#40;</span>sheet, <span style="color: #ff0000;">3</span><span style="color: #080;">&#41;</span>
&nbsp;
<span style="color: #228B22;">#Add table</span>
<span style="color: #228B22;">#+++++++++++++++++++++++++++++++</span>
xlsx.<span style="">addTable</span><span style="color: #080;">&#40;</span>wb, sheet, <span style="color: #0000FF; font-weight: bold;">head</span><span style="color: #080;">&#40;</span><span style="color: #CC9900; font-weight: bold;">iris</span><span style="color: #080;">&#41;</span>, startCol<span style="color: #080;">=</span><span style="color: #ff0000;">2</span><span style="color: #080;">&#41;</span>
xlsx.<span style="">addLineBreak</span><span style="color: #080;">&#40;</span>sheet, <span style="color: #ff0000;">2</span><span style="color: #080;">&#41;</span>
&nbsp;
<span style="color: #228B22;">#saving a workbook to an Excel file and writes the file to disk.</span>
saveWorkbook<span style="color: #080;">&#40;</span>wb, filename<span style="color: #080;">&#41;</span>
&nbsp;
<span style="color: #228B22;">#View the file</span>
xlsx.<span style="">openFile</span><span style="color: #080;">&#40;</span>filename<span style="color: #080;">&#41;</span>
&nbsp;
&nbsp;</pre></pre></div><br />
<br />
<!-- START HTML -->
<center><div class="highlight_3d" style="width:521px; height:258px"><img src="https://www.sthda.com/french/french/upload/r2xlsx_first_document.png"/></div></center>
<!-- END HTML --><br />
<br />
<h3 class="formatter-title">Ajout de titre</h3><br />
<br />
<span class="formatter-code">Code R :</span><div class="code"><pre style="display:inline;"><pre class="r" style="font-family:monospace;">&nbsp;
<span style="color: #228B22;">#......</span>
<span style="color: #228B22;">#Don't forget to create a workbook and a sheet as previously</span>
<span style="color: #228B22;">#......</span>
<span style="color: #228B22;">#Header</span>
<span style="color: #228B22;">#**************************************</span>
<span style="color: #228B22;">#header level 1</span>
xlsx.<span style="">addHeader</span><span style="color: #080;">&#40;</span>wb, sheet, value<span style="color: #080;">=</span><span style="color: #ff0000;">"Header 1"</span>,level<span style="color: #080;">=</span><span style="color: #ff0000;">1</span>, color<span style="color: #080;">=</span><span style="color: #ff0000;">"black"</span><span style="color: #080;">&#41;</span>
<span style="color: #228B22;">#header level 2</span>
xlsx.<span style="">addHeader</span><span style="color: #080;">&#40;</span>wb, sheet, value<span style="color: #080;">=</span><span style="color: #ff0000;">"Header 2"</span>,level<span style="color: #080;">=</span><span style="color: #ff0000;">2</span>, color<span style="color: #080;">=</span><span style="color: #ff0000;">"black"</span><span style="color: #080;">&#41;</span>
<span style="color: #228B22;">#header level 3</span>
xlsx.<span style="">addHeader</span><span style="color: #080;">&#40;</span>wb, sheet, value<span style="color: #080;">=</span><span style="color: #ff0000;">"Header 3"</span>,level<span style="color: #080;">=</span><span style="color: #ff0000;">3</span>, color<span style="color: #080;">=</span><span style="color: #ff0000;">"black"</span><span style="color: #080;">&#41;</span>
<span style="color: #228B22;">#header level 4</span>
xlsx.<span style="">addHeader</span><span style="color: #080;">&#40;</span>wb, sheet, value<span style="color: #080;">=</span><span style="color: #ff0000;">"Header 4"</span>,level<span style="color: #080;">=</span><span style="color: #ff0000;">4</span>, color<span style="color: #080;">=</span><span style="color: #ff0000;">"black"</span><span style="color: #080;">&#41;</span>
<span style="color: #228B22;">#header level 5</span>
xlsx.<span style="">addHeader</span><span style="color: #080;">&#40;</span>wb, sheet, value<span style="color: #080;">=</span><span style="color: #ff0000;">"Header 5"</span>,level<span style="color: #080;">=</span><span style="color: #ff0000;">5</span>, color<span style="color: #080;">=</span><span style="color: #ff0000;">"black"</span><span style="color: #080;">&#41;</span>
<span style="color: #228B22;">#header level 6</span>
xlsx.<span style="">addHeader</span><span style="color: #080;">&#40;</span>wb, sheet, value<span style="color: #080;">=</span><span style="color: #ff0000;">"Header 6"</span>,level<span style="color: #080;">=</span><span style="color: #ff0000;">6</span>, color<span style="color: #080;">=</span><span style="color: #ff0000;">"black"</span><span style="color: #080;">&#41;</span>
&nbsp;
<span style="color: #228B22;">#......</span>
<span style="color: #228B22;">#Don't forget to save the workbook</span>
<span style="color: #228B22;">#......</span>
&nbsp;</pre></pre></div><br />
<br />
<!-- START HTML -->
<center><div class="highlight_3d" style="width:266px; height:133px"><img src="https://www.sthda.com/french/french/upload/r2xlsx_header.png"/></div></center>
<!-- END HTML --><br />
<br />
<br />
<h3 class="formatter-title">Ajout de textes </h3><br />
<br />
<span class="formatter-code">Code R :</span><div class="code"><pre style="display:inline;"><pre class="r" style="font-family:monospace;">&nbsp;
<span style="color: #228B22;">#......</span>
<span style="color: #228B22;">#Don't forget to create a workbook and a sheet as previously</span>
<span style="color: #228B22;">#......</span>
&nbsp;
<span style="color: #228B22;"># Add texts</span>
<span style="color: #228B22;">#**************************************</span>
<span style="color: #228B22;">#Add Text :Author</span>
<span style="color: #228B22;">#+++++++++++++++++++++++++++++++</span>
xlsx.<span style="">addHeader</span><span style="color: #080;">&#40;</span>wb, sheet, value<span style="color: #080;">=</span><span style="color: #ff0000;">"Author"</span>,level<span style="color: #080;">=</span><span style="color: #ff0000;">2</span>, color<span style="color: #080;">=</span><span style="color: #ff0000;">"black"</span>, underline<span style="color: #080;">=</span><span style="color: #ff0000;">1</span><span style="color: #080;">&#41;</span>
xlsx.<span style="">addText</span><span style="color: #080;">&#40;</span>wb, sheet, value<span style="color: #080;">=</span><span style="color: #ff0000;">"Author : Alboukadel KASSAMBARA. <span style="color: #000099; font-weight: bold;">\n</span>@:alboukadel.kassambara@gmail.com.<span style="color: #000099; font-weight: bold;">\n</span> Website : http://ww.sthda.com"</span>,
             isItalic<span style="color: #080;">=</span>TRUE, colSpan<span style="color: #080;">=</span><span style="color: #ff0000;">5</span>, rowSpan<span style="color: #080;">=</span><span style="color: #ff0000;">3</span>, fontColor<span style="color: #080;">=</span><span style="color: #ff0000;">"darkgray"</span>, fontSize<span style="color: #080;">=</span><span style="color: #ff0000;">14</span><span style="color: #080;">&#41;</span>
xlsx.<span style="">addLineBreak</span><span style="color: #080;">&#40;</span>sheet, <span style="color: #ff0000;">3</span><span style="color: #080;">&#41;</span><span style="color: #228B22;"># Three line breaks</span>
&nbsp;
<span style="color: #228B22;">#Add paragraph</span>
<span style="color: #228B22;">#+++++++++++++++++++++++++++++</span>
xlsx.<span style="">addHeader</span><span style="color: #080;">&#40;</span>wb, sheet, <span style="color: #ff0000;">" Add paragraph"</span>, level<span style="color: #080;">=</span><span style="color: #ff0000;">2</span>, underline<span style="color: #080;">=</span><span style="color: #ff0000;">1</span><span style="color: #080;">&#41;</span>
xlsx.<span style="">addLineBreak</span><span style="color: #080;">&#40;</span>sheet, <span style="color: #ff0000;">2</span><span style="color: #080;">&#41;</span>
paragraph<span style="color: #080;">=</span><span style="color: #ff0000;">"Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged."</span>
<span style="color: #228B22;">#customized</span>
xlsx.<span style="">addParagraph</span><span style="color: #080;">&#40;</span>wb, sheet, paragraph, fontSize<span style="color: #080;">=</span><span style="color: #ff0000;">14</span>, isItalic<span style="color: #080;">=</span>TRUE, 
                  fontColor<span style="color: #080;">=</span><span style="color: #ff0000;">"darkred"</span>, backGroundColor<span style="color: #080;">=</span><span style="color: #ff0000;">"gray"</span><span style="color: #080;">&#41;</span>
xlsx.<span style="">addLineBreak</span><span style="color: #080;">&#40;</span>sheet, <span style="color: #ff0000;">2</span><span style="color: #080;">&#41;</span>
<span style="color: #228B22;">#......</span>
<span style="color: #228B22;">#Don't forget to save the workbook</span>
<span style="color: #228B22;">#......</span>
&nbsp;</pre></pre></div><br />
<br />
<!-- START HTML -->
<center><div class="highlight_3d" style="width:437px; height:263px"><img src="https://www.sthda.com/french/french/upload/r2xlsx_text.png"/></div></center>
<!-- END HTML --><br />
<br />
<h3 class="formatter-title">Ajouter un hyperlien</h3><br />
<br />
<span class="formatter-code">Code R :</span><div class="code"><pre style="display:inline;"><pre class="r" style="font-family:monospace;">&nbsp;
<span style="color: #228B22;">#......</span>
<span style="color: #228B22;">#Don't forget to create a workbook and a sheet as previously</span>
<span style="color: #228B22;">#......</span>
<span style="color: #228B22;">#Header</span>
<span style="color: #228B22;">#**************************************</span>
&nbsp;
<span style="color: #228B22;">#Add Hyperlink</span>
<span style="color: #228B22;">#+++++++++++++++++++++++++++++</span>
xlsx.<span style="">addHeader</span><span style="color: #080;">&#40;</span>wb, sheet, <span style="color: #ff0000;">" Add Hyperlink"</span>, level<span style="color: #080;">=</span><span style="color: #ff0000;">2</span>, underline<span style="color: #080;">=</span><span style="color: #ff0000;">1</span><span style="color: #080;">&#41;</span>
xlsx.<span style="">addLineBreak</span><span style="color: #080;">&#40;</span>sheet, <span style="color: #ff0000;">1</span><span style="color: #080;">&#41;</span>
xlsx.<span style="">addHyperlink</span><span style="color: #080;">&#40;</span>wb, sheet, <span style="color: #ff0000;">"https://www.sthda.com"</span>, <span style="color: #ff0000;">"Click-me!!"</span>, fontSize<span style="color: #080;">=</span><span style="color: #ff0000;">12</span><span style="color: #080;">&#41;</span>
xlsx.<span style="">addLineBreak</span><span style="color: #080;">&#40;</span>sheet, <span style="color: #ff0000;">2</span><span style="color: #080;">&#41;</span>
&nbsp;
<span style="color: #228B22;">#......</span>
<span style="color: #228B22;">#Don't forget to save the workbook</span>
<span style="color: #228B22;">#......</span>
&nbsp;</pre></pre></div><br />
<br />
<!-- START HTML -->
<center><div class="highlight_3d" style="width:231px; height:74px"><img src="https://www.sthda.com/french/french/upload/r2xlsx_hyperlink.png"/></div></center>
<!-- END HTML --><br />
<br />
<br />
<h3 class="formatter-title">Ajouter une table</h3><br />
<br />
<span class="formatter-code">Code R :</span><div class="code"><pre style="display:inline;"><pre class="r" style="font-family:monospace;">&nbsp;
<span style="color: #228B22;">#......</span>
<span style="color: #228B22;">#Don't forget to create a workbook and a sheet as previously</span>
<span style="color: #228B22;">#......</span>
&nbsp;
<span style="color: #228B22;">#Add table</span>
<span style="color: #228B22;">#+++++++++++++++++++++++++++++</span>
<span style="color: #228B22;">#add iris data using default settings</span>
<span style="color: #0000FF; font-weight: bold;">data</span><span style="color: #080;">&#40;</span><span style="color: #CC9900; font-weight: bold;">iris</span><span style="color: #080;">&#41;</span>
<span style="color: #228B22;">#header</span>
xlsx.<span style="">addHeader</span><span style="color: #080;">&#40;</span>wb, sheet, value<span style="color: #080;">=</span><span style="color: #ff0000;">"Add table"</span>,level<span style="color: #080;">=</span><span style="color: #ff0000;">2</span>, color<span style="color: #080;">=</span><span style="color: #ff0000;">"black"</span>, underline<span style="color: #080;">=</span><span style="color: #ff0000;">1</span><span style="color: #080;">&#41;</span>
xlsx.<span style="">addLineBreak</span><span style="color: #080;">&#40;</span>sheet, <span style="color: #ff0000;">1</span><span style="color: #080;">&#41;</span>
&nbsp;
<span style="color: #228B22;">#header</span>
xlsx.<span style="">addHeader</span><span style="color: #080;">&#40;</span>wb, sheet, value<span style="color: #080;">=</span><span style="color: #ff0000;">"Simple Table"</span>,level<span style="color: #080;">=</span><span style="color: #ff0000;">3</span>, color<span style="color: #080;">=</span><span style="color: #ff0000;">"black"</span><span style="color: #080;">&#41;</span>
xlsx.<span style="">addLineBreak</span><span style="color: #080;">&#40;</span>sheet, <span style="color: #ff0000;">1</span><span style="color: #080;">&#41;</span>
xlsx.<span style="">addTable</span><span style="color: #080;">&#40;</span>wb, sheet, <span style="color: #0000FF; font-weight: bold;">head</span><span style="color: #080;">&#40;</span><span style="color: #CC9900; font-weight: bold;">iris</span><span style="color: #080;">&#41;</span>, startCol<span style="color: #080;">=</span><span style="color: #ff0000;">2</span><span style="color: #080;">&#41;</span>
xlsx.<span style="">addLineBreak</span><span style="color: #080;">&#40;</span>sheet, <span style="color: #ff0000;">2</span><span style="color: #080;">&#41;</span>
&nbsp;
<span style="color: #228B22;">#Customized table : column data format</span>
xlsx.<span style="">addHeader</span><span style="color: #080;">&#40;</span>wb, sheet, value<span style="color: #080;">=</span><span style="color: #ff0000;">"Customized table : font color and size"</span>,
               level<span style="color: #080;">=</span><span style="color: #ff0000;">3</span>, color<span style="color: #080;">=</span><span style="color: #ff0000;">"black"</span><span style="color: #080;">&#41;</span>
xlsx.<span style="">addLineBreak</span><span style="color: #080;">&#40;</span>sheet, <span style="color: #ff0000;">1</span><span style="color: #080;">&#41;</span>
xlsx.<span style="">addTable</span><span style="color: #080;">&#40;</span>wb, sheet, <span style="color: #0000FF; font-weight: bold;">data</span><span style="color: #080;">=</span> <span style="color: #0000FF; font-weight: bold;">head</span><span style="color: #080;">&#40;</span><span style="color: #CC9900; font-weight: bold;">iris</span><span style="color: #080;">&#41;</span>,
              fontColor<span style="color: #080;">=</span><span style="color: #ff0000;">"darkblue"</span>, fontSize<span style="color: #080;">=</span><span style="color: #ff0000;">"16"</span>             
<span style="color: #080;">&#41;</span>
xlsx.<span style="">addLineBreak</span><span style="color: #080;">&#40;</span>sheet, <span style="color: #ff0000;">2</span><span style="color: #080;">&#41;</span>
<span style="color: #228B22;">#......</span>
<span style="color: #228B22;">#Don't forget to save the workbook</span>
<span style="color: #228B22;">#......</span>
&nbsp;</pre></pre></div><br />
<br />
<!-- START HTML -->
<center><div class="highlight_3d" style="width:519px; height:421px"><img src="https://www.sthda.com/french/french/upload/r2xlsx_table.png"/></div></center>
<!-- END HTML --><br />
<br />
<br />
<h3 class="formatter-title">Ajouter un graphique</h3><br />
<br />
<h4 class="formatter-title">Boxplot basic</h4><br />
<br />
<span class="formatter-code">Code R :</span><div class="code"><pre style="display:inline;"><pre class="r" style="font-family:monospace;">&nbsp;
<span style="color: #228B22;">#......</span>
<span style="color: #228B22;">#Don't forget to create a workbook and a sheet as previously</span>
<span style="color: #228B22;">#......</span>
<span style="color: #228B22;">#Add Plot</span>
<span style="color: #228B22;">#+++++++++++++++++++++++++++++</span>
<span style="color: #228B22;">#boxplot</span>
<span style="color: #0000FF; font-weight: bold;">data</span><span style="color: #080;">&#40;</span><span style="color: #CC9900; font-weight: bold;">ToothGrowth</span><span style="color: #080;">&#41;</span>
xlsx.<span style="">addHeader</span><span style="color: #080;">&#40;</span>wb, sheet, <span style="color: #ff0000;">" Add Plot"</span>, level<span style="color: #080;">=</span><span style="color: #ff0000;">2</span>, underline<span style="color: #080;">=</span><span style="color: #ff0000;">1</span><span style="color: #080;">&#41;</span>
xlsx.<span style="">addLineBreak</span><span style="color: #080;">&#40;</span>sheet, <span style="color: #ff0000;">1</span><span style="color: #080;">&#41;</span>
plotFunction<span style="color: #080;"><-</span><span style="color: #0000FF; font-weight: bold;">function</span><span style="color: #080;">&#40;</span><span style="color: #080;">&#41;</span><span style="color: #080;">&#123;</span><span style="color: #0000FF; font-weight: bold;">boxplot</span><span style="color: #080;">&#40;</span>len ~ dose, <span style="color: #0000FF; font-weight: bold;">data</span> <span style="color: #080;">=</span> <span style="color: #CC9900; font-weight: bold;">ToothGrowth</span>,
                                 <span style="color: #0000FF; font-weight: bold;">subset</span> <span style="color: #080;">=</span> supp <span style="color: #080;">==</span> <span style="color: #ff0000;">"VC"</span>, <span style="color: #0000FF; font-weight: bold;">col</span> <span style="color: #080;">=</span> <span style="color: #ff0000;">"yellow"</span>,
                                 main <span style="color: #080;">=</span> <span style="color: #ff0000;">"Guinea Pigs' Tooth Growth"</span>,
                                 xlab <span style="color: #080;">=</span> <span style="color: #ff0000;">"Vitamin C dose mg"</span>, ylab <span style="color: #080;">=</span> <span style="color: #ff0000;">"tooth length"</span>,
                                 xlim <span style="color: #080;">=</span> <span style="color: #0000FF; font-weight: bold;">c</span><span style="color: #080;">&#40;</span><span style="color: #ff0000;">0.5</span>, <span style="color: #ff0000;">3.5</span><span style="color: #080;">&#41;</span>, ylim <span style="color: #080;">=</span> <span style="color: #0000FF; font-weight: bold;">c</span><span style="color: #080;">&#40;</span><span style="color: #ff0000;">0</span>, <span style="color: #ff0000;">35</span><span style="color: #080;">&#41;</span>, yaxs <span style="color: #080;">=</span> <span style="color: #ff0000;">"i"</span><span style="color: #080;">&#41;</span>
<span style="color: #080;">&#125;</span>
xlsx.<span style="">addPlot</span><span style="color: #080;">&#40;</span>wb, sheet, plotFunction<span style="color: #080;">&#40;</span><span style="color: #080;">&#41;</span><span style="color: #080;">&#41;</span>
<span style="color: #228B22;">#......</span>
<span style="color: #228B22;">#Don't forget to save the workbook</span>
<span style="color: #228B22;">#......</span>
&nbsp;</pre></pre></div><br />
<br />
<!-- START HTML -->
<center><div class="highlight_3d" style="width:442px; height:397px"><img src="https://www.sthda.com/french/french/upload/r2xlsx_boxplot.png"/></div></center>
<!-- END HTML --><br />
<br />
<h4 class="formatter-title">GGPLOT2 : Courbe de densit?</h4><br />
<br />
<span class="formatter-code">Code R :</span><div class="code"><pre style="display:inline;"><pre class="r" style="font-family:monospace;">&nbsp;
<span style="color: #228B22;">#......</span>
<span style="color: #228B22;">#Don't forget to create workbook and sheet as previously</span>
<span style="color: #228B22;">#......</span>
<span style="color: #228B22;">#Add Plot</span>
<span style="color: #228B22;">#+++++++++++++++++++++++++++++</span>
<span style="color: #228B22;">#ggplot2</span>
rquery.<span style="">loadPackages</span><span style="color: #080;">&#40;</span><span style="color: #ff0000;">"ggplot2"</span><span style="color: #080;">&#41;</span><span style="color: #228B22;">#for plot</span>
<span style="color: #0000FF; font-weight: bold;">set.<span style="">seed</span></span><span style="color: #080;">&#40;</span><span style="color: #ff0000;">1234</span><span style="color: #080;">&#41;</span>
<span style="color: #0000FF; font-weight: bold;">df</span> <span style="color: #080;"><-</span> <span style="color: #0000FF; font-weight: bold;">data.<span style="">frame</span></span><span style="color: #080;">&#40;</span>cond <span style="color: #080;">=</span> <span style="color: #0000FF; font-weight: bold;">factor</span><span style="color: #080;">&#40;</span> <span style="color: #0000FF; font-weight: bold;">rep</span><span style="color: #080;">&#40;</span><span style="color: #0000FF; font-weight: bold;">c</span><span style="color: #080;">&#40;</span><span style="color: #ff0000;">"A"</span>,<span style="color: #ff0000;">"B"</span><span style="color: #080;">&#41;</span>, each<span style="color: #080;">=</span><span style="color: #ff0000;">200</span><span style="color: #080;">&#41;</span> <span style="color: #080;">&#41;</span>, 
                 rating <span style="color: #080;">=</span> <span style="color: #0000FF; font-weight: bold;">c</span><span style="color: #080;">&#40;</span><span style="color: #0000FF; font-weight: bold;">rnorm</span><span style="color: #080;">&#40;</span><span style="color: #ff0000;">200</span><span style="color: #080;">&#41;</span>,<span style="color: #0000FF; font-weight: bold;">rnorm</span><span style="color: #080;">&#40;</span><span style="color: #ff0000;">200</span>, <span style="color: #0000FF; font-weight: bold;">mean</span><span style="color: #080;">=</span>.8<span style="color: #080;">&#41;</span><span style="color: #080;">&#41;</span><span style="color: #080;">&#41;</span>
&nbsp;
<span style="color: #228B22;"># Density plots with semi-transparent fill</span>
xlsx.<span style="">addHeader</span><span style="color: #080;">&#40;</span>wb, sheet, <span style="color: #ff0000;">"Density plots with semi-transparent fill"</span>, level<span style="color: #080;">=</span><span style="color: #ff0000;">2</span>, underline<span style="color: #080;">=</span><span style="color: #ff0000;">1</span><span style="color: #080;">&#41;</span>
xlsx.<span style="">addLineBreak</span><span style="color: #080;">&#40;</span>sheet, <span style="color: #ff0000;">1</span><span style="color: #080;">&#41;</span>
&nbsp;
gg.<span style="">p</span><span style="color: #080;"><-</span>ggplot<span style="color: #080;">&#40;</span><span style="color: #0000FF; font-weight: bold;">df</span>, aes<span style="color: #080;">&#40;</span>x<span style="color: #080;">=</span>rating, fill<span style="color: #080;">=</span>cond<span style="color: #080;">&#41;</span><span style="color: #080;">&#41;</span> <span style="color: #080;">+</span> geom_density<span style="color: #080;">&#40;</span>alpha<span style="color: #080;">=</span>.3<span style="color: #080;">&#41;</span>
xlsx.<span style="">addPlot</span><span style="color: #080;">&#40;</span>wb, sheet, <span style="color: #0000FF; font-weight: bold;">function</span><span style="color: #080;">&#40;</span><span style="color: #080;">&#41;</span><span style="color: #080;">&#123;</span><span style="color: #0000FF; font-weight: bold;">print</span><span style="color: #080;">&#40;</span>gg.<span style="">p</span><span style="color: #080;">&#41;</span><span style="color: #080;">&#125;</span><span style="color: #080;">&#41;</span>
<span style="color: #228B22;">#......</span>
<span style="color: #228B22;">#Don't forget to save the workbook</span>
<span style="color: #228B22;">#......</span>
&nbsp;</pre></pre></div><br />
<br />
<!-- START HTML -->
<center><div class="highlight_3d" style="width:436px; height:395px"><img src="https://www.sthda.com/french/french/upload/r2xlsx_ggplot2.png"/></div></center>
<!-- END HTML --><br />
<br />
<br />
<h3 class="formatter-title">Lire un fichier Excel</h3><br />
<br />
<span class="formatter-code">Code R :</span><div class="code"><pre style="display:inline;"><pre class="r" style="font-family:monospace;">&nbsp;
<span style="color: #0000FF; font-weight: bold;">file</span> <span style="color: #080;"><-</span> <span style="color: #0000FF; font-weight: bold;">system.<span style="">file</span></span><span style="color: #080;">&#40;</span><span style="color: #ff0000;">"tests"</span>, <span style="color: #ff0000;">"test_import.xlsx"</span>, package <span style="color: #080;">=</span> <span style="color: #ff0000;">"xlsx"</span><span style="color: #080;">&#41;</span>
res <span style="color: #080;"><-</span> xlsx.<span style="">readFile</span><span style="color: #080;">&#40;</span><span style="color: #0000FF; font-weight: bold;">file</span>, <span style="color: #ff0000;">1</span><span style="color: #080;">&#41;</span>  <span style="color: #228B22;"># read first sheet</span>
<span style="color: #0000FF; font-weight: bold;">head</span><span style="color: #080;">&#40;</span>res<span style="color: #080;">&#41;</span>
&nbsp;</pre></pre></div><br />
<br />
<h3 class="formatter-title">Ecrire un fichier Excel</h3><br />
<br />
LA fonction suivante permet d'?crire une table de donn?es dans un fichier excel.<br />
<br />
<span class="formatter-code">Code R :</span><div class="code"><pre style="display:inline;"><pre class="r" style="font-family:monospace;">&nbsp;
res <span style="color: #080;"><-</span> xlsx.<span style="">writeFile</span><span style="color: #080;">&#40;</span><span style="color: #CC9900; font-weight: bold;">USArrests</span>, <span style="color: #0000FF; font-weight: bold;">file</span><span style="color: #080;">=</span><span style="color: #ff0000;">"USArrests.xlsx"</span>, sheetName<span style="color: #080;">=</span><span style="color: #ff0000;">"USArrests"</span><span style="color: #080;">&#41;</span>
&nbsp;</pre></pre></div><br />
<br />
<h3 class="formatter-title">Un document Excel complet</h3><br />
<br />
<span class="success">Le script complet utilis? pour cr?e le document word suivant est t?l?chargeable ici : <a href="https://www.sthda.com/french/french/upload/howtouse_r2xlsx.r">howToUse_R2XLSX.R</a></span><br />
<br />
Le fichier Excel est t?l?chargeable en cliquant sur le lien suivant:<a href="https://www.sthda.com/french/french/upload/r2xlsx_example1.xlsx">R2XLSX_Example1.xlsx</a><br />
<br />
<!-- START HTML -->
<a href="https://www.sthda.com/french/french/upload/r2xlsx_example1.pdf" class="embed" >Document Excel complet</a>
<!-- END HTML --><br />
<br />
<br />
<h3 class="formatter-title">Utilisation avanc?e - prototype des fonctions</h3><br />
<br />
Les prototypes des fonctions sont montr?es ci-dessous pour une utilisation avanc?e.<br />
<br />
<h4 class="formatter-title">xlsx.addHeader</h4><br />
<br />
<span class="formatter-code">Code R :</span><div class="code"><pre style="display:inline;"><pre class="r" style="font-family:monospace;">&nbsp;
<span style="color: #228B22;">#****************************************</span>
<span style="color: #228B22;">#Add header :sheet title and subtitle</span>
<span style="color: #228B22;">#****************************************</span>
<span style="color: #228B22;">#wb :workbook object</span>
<span style="color: #228B22;">#sheet : sheet object</span>
<span style="color: #228B22;">#value : your header value</span>
<span style="color: #228B22;">#level : header level; possible value (1 to 6)</span>
<span style="color: #228B22;">#startRow : row index to start to write</span>
<span style="color: #228B22;">#startCol : col index to start to write</span>
<span style="color: #228B22;">#rowBreak : number of rows to jump before appending the data</span>
<span style="color: #228B22;">#underline : a numeric value specifying the thickness of the underline.</span>
<span style="color: #228B22;">#Allowed values are 0, 1, 2.</span>
xlsx.<span style="">addHeader</span><span style="color: #080;">&#40;</span>wb, sheet, value<span style="color: #080;">=</span><span style="color: #ff0000;">"Header"</span>, level<span style="color: #080;">=</span><span style="color: #ff0000;">1</span>, color<span style="color: #080;">=</span><span style="color: #ff0000;">"#FFFFFF"</span>,
                         startRow<span style="color: #080;">=</span>NULL, startCol<span style="color: #080;">=</span><span style="color: #ff0000;">2</span>, underline<span style="color: #080;">=</span><span style="color: #0000FF; font-weight: bold;">c</span><span style="color: #080;">&#40;</span><span style="color: #ff0000;">0</span>,<span style="color: #ff0000;">1</span>,<span style="color: #ff0000;">2</span><span style="color: #080;">&#41;</span><span style="color: #080;">&#41;</span>
&nbsp;</pre></pre></div><br />
<br />
<br />
<h4 class="formatter-title">xlsx.addText</h4><br />
<br />
<span class="formatter-code">Code R :</span><div class="code"><pre style="display:inline;"><pre class="r" style="font-family:monospace;">&nbsp;
<span style="color: #228B22;">#****************************************</span>
<span style="color: #228B22;">#Add Text : add a simple line text</span>
<span style="color: #228B22;">#****************************************</span>
<span style="color: #228B22;">#the function is similar to xlsx.addParagraph</span>
<span style="color: #228B22;">#wb :workbook object</span>
<span style="color: #228B22;">#sheet : sheet object</span>
<span style="color: #228B22;">#value : paragraph text</span>
<span style="color: #228B22;">#fontColor: text color. default is black. value : all colors returned by colors() can be used</span>
<span style="color: #228B22;">#backGroundColor : fill color of the cell</span>
<span style="color: #228B22;">#fontSize : text size</span>
<span style="color: #228B22;">#isBold : if TRUE, the text is written in bold format</span>
<span style="color: #228B22;">#isItalic : if TRUE, the text is written in italic format</span>
<span style="color: #228B22;">#startRow : row index to start to write</span>
<span style="color: #228B22;">#startCol : col index to start to write</span>
<span style="color: #228B22;">#colSpan : number of column to be merged (paragraph : width)</span>
<span style="color: #228B22;">#rowSpan : number of rows to be merged corresponding to paragrath height</span>
xlsx.<span style="">addText</span><span style="color: #080;">&#40;</span>wb,sheet, value, fontColor<span style="color: #080;">=</span><span style="color: #ff0000;">"#FFFFFF"</span>, fontSize<span style="color: #080;">=</span><span style="color: #ff0000;">12</span>, backGroundColor<span style="color: #080;">=</span><span style="color: #ff0000;">"#FFFFFF"</span>,
                            isBold<span style="color: #080;">=</span>FALSE, isItalic<span style="color: #080;">=</span>FALSE,
                            startRow<span style="color: #080;">=</span>NULL, startCol<span style="color: #080;">=</span><span style="color: #ff0000;">2</span>, colSpan<span style="color: #080;">=</span><span style="color: #ff0000;">1</span>, rowSpan<span style="color: #080;">=</span><span style="color: #ff0000;">1</span><span style="color: #080;">&#41;</span>
&nbsp;</pre></pre></div><br />
<br />
<h4 class="formatter-title">xlsx.addParagraph</h4><br />
<br />
<span class="formatter-code">Code R :</span><div class="code"><pre style="display:inline;"><pre class="r" style="font-family:monospace;">&nbsp;
<span style="color: #228B22;">#****************************************</span>
<span style="color: #228B22;">#Add paragraph</span>
<span style="color: #228B22;">#****************************************</span>
<span style="color: #228B22;">#wb :workbook object</span>
<span style="color: #228B22;">#sheet : sheet object</span>
<span style="color: #228B22;">#value : paragraph text</span>
<span style="color: #228B22;">#fontColor: text color. default is black. value : all colors returned by colors() can be used</span>
<span style="color: #228B22;">#fontSize : text size</span>
<span style="color: #228B22;">#backGroundColor : fill color of the cell</span>
<span style="color: #228B22;">#isBold : if TRUE, the text is written in bold format</span>
<span style="color: #228B22;">#isItalic : if TRUE, the text is written in italic format</span>
<span style="color: #228B22;">#startRow : row index to start to write</span>
<span style="color: #228B22;">#startCol : col index to start to write</span>
<span style="color: #228B22;">#colSpan : number of column to be merged (paragraph : width)</span>
<span style="color: #228B22;">#rowSapn : number of rows to be merged corresponding to paragrath height</span>
xlsx.<span style="">addParagraph</span><span style="color: #080;">&#40;</span>wb,sheet, value, fontColor<span style="color: #080;">=</span><span style="color: #ff0000;">"#FFFFFF"</span>, fontSize<span style="color: #080;">=</span><span style="color: #ff0000;">12</span>, backGroundColor<span style="color: #080;">=</span><span style="color: #ff0000;">"#FFFFFF"</span>,
                            isBold<span style="color: #080;">=</span>FALSE, isItalic<span style="color: #080;">=</span>FALSE,
                            startRow<span style="color: #080;">=</span>NULL, startCol<span style="color: #080;">=</span><span style="color: #ff0000;">2</span>, colSpan<span style="color: #080;">=</span><span style="color: #ff0000;">10</span>, rowSpan<span style="color: #080;">=</span><span style="color: #ff0000;">5</span><span style="color: #080;">&#41;</span>
&nbsp;</pre></pre></div><br />
<br />
<br />
<h4 class="formatter-title">xlsx.addHyperlink</h4><br />
<br />
<span class="formatter-code">Code R :</span><div class="code"><pre style="display:inline;"><pre class="r" style="font-family:monospace;">&nbsp;
<span style="color: #228B22;">#****************************************</span>
<span style="color: #228B22;">#Add Hyperlink</span>
<span style="color: #228B22;">#****************************************</span>
<span style="color: #228B22;">#wb :workbook object</span>
<span style="color: #228B22;">#sheet : sheet object</span>
<span style="color: #228B22;">#value : paragraph text</span>
<span style="color: #228B22;">#fontColor: text color. default is black. value : all colors returned by colors() can be used</span>
<span style="color: #228B22;">#fontSize : text size</span>
<span style="color: #228B22;">#isBold : if TRUE, the text is written in bold format</span>
<span style="color: #228B22;">#isItalic : if TRUE, the text is written in italic format</span>
<span style="color: #228B22;">#startRow : row index to start to write</span>
<span style="color: #228B22;">#startCol : col index to start to write</span>
xlsx.<span style="">addHyperlink</span><span style="color: #080;">&#40;</span>wb,sheet, address, friendlyName, 
                            fontColor<span style="color: #080;">=</span><span style="color: #ff0000;">"blue"</span>, fontSize<span style="color: #080;">=</span><span style="color: #ff0000;">12</span>,
                            isBold<span style="color: #080;">=</span>FALSE, isItalic<span style="color: #080;">=</span>FALSE, startRow<span style="color: #080;">=</span>NULL, startCol<span style="color: #080;">=</span><span style="color: #ff0000;">2</span><span style="color: #080;">&#41;</span> 
&nbsp;</pre></pre></div><br />
<br />
<br />
<h4 class="formatter-title">xlsx.addLineBreak</h4><br />
<br />
<span class="formatter-code">Code R :</span><div class="code"><pre style="display:inline;"><pre class="r" style="font-family:monospace;">&nbsp;
<span style="color: #228B22;">#****************************************</span>
<span style="color: #228B22;">#Add Line break to the sheet</span>
<span style="color: #228B22;">#****************************************</span>
<span style="color: #228B22;">#wb :workbook object</span>
<span style="color: #228B22;">#sheet : sheet object</span>
<span style="color: #228B22;">#value : your header value</span>
<span style="color: #228B22;">#level : header level; possible value (1 to 6)</span>
<span style="color: #228B22;">#startRow : row index to start to write</span>
<span style="color: #228B22;">#startCol : col index to start to write</span>
<span style="color: #228B22;">#numberOfLine : number of rows to jump before appending the data</span>
xlsx.<span style="">addLineBreak</span><span style="color: #080;">&#40;</span>sheet, numberOfLine<span style="color: #080;">=</span><span style="color: #ff0000;">1</span><span style="color: #080;">&#41;</span>
&nbsp;</pre></pre></div><br />
<br />
<br />
<h4 class="formatter-title">xlsx.addTable</h4><br />
<br />
<span class="formatter-code">Code R :</span><div class="code"><pre style="display:inline;"><pre class="r" style="font-family:monospace;">&nbsp;
<span style="color: #228B22;">#****************************************</span>
<span style="color: #228B22;">#add table </span>
<span style="color: #228B22;">#****************************************</span>
<span style="color: #228B22;">#wb :workbook object</span>
<span style="color: #228B22;">#sheet : sheet object</span>
<span style="color: #228B22;">#data : data frame</span>
<span style="color: #228B22;">#level : header level; possible value (1 to 6)</span>
<span style="color: #228B22;">#startRow : row index to start to write</span>
<span style="color: #228B22;">#startCol : col index to start to write</span>
<span style="color: #228B22;">#rowBreak : nimber of rows to jum before appending the data</span>
<span style="color: #228B22;">#if col.names and row.names : column and row names  are written</span>
<span style="color: #228B22;">#fontColor : color of text</span>
<span style="color: #228B22;">#fontSize : text size</span>
<span style="color: #228B22;">#rownamesFill: background color of table row names</span>
<span style="color: #228B22;">#colnamesFill : background color of table column names</span>
<span style="color: #228B22;">#rowFill : background color of pair rows (i.e : 2, 4, 6). For table styling.</span>
<span style="color: #228B22;">#mergedColumnForRownames : number of column to merge for rownames. </span>
<span style="color: #228B22;">#Be carrefull : using mergedColumnForRownames is a  very slow process</span>
xlsx.<span style="">addTable</span><span style="color: #080;">&#40;</span>wb, sheet, <span style="color: #0000FF; font-weight: bold;">data</span>, startRow<span style="color: #080;">=</span>NULL,startCol<span style="color: #080;">=</span><span style="color: #ff0000;">2</span>,
                        col.<span style="">names</span><span style="color: #080;">=</span>TRUE, <span style="color: #0000FF; font-weight: bold;">row.<span style="">names</span></span><span style="color: #080;">=</span>TRUE, columnWidth<span style="color: #080;">=</span><span style="color: #ff0000;">14</span>,
                        fontColor<span style="color: #080;">=</span><span style="color: #ff0000;">"#FFFFFF"</span>, fontSize<span style="color: #080;">=</span><span style="color: #ff0000;">12</span>, rownamesFill<span style="color: #080;">=</span><span style="color: #ff0000;">"white"</span>, colnamesFill<span style="color: #080;">=</span><span style="color: #ff0000;">"white"</span>, rowFill<span style="color: #080;">=</span><span style="color: #ff0000;">"white"</span>,
                        mergedColumnForRownames<span style="color: #080;">=</span><span style="color: #ff0000;">1</span>,   ...<span style="color: #080;">&#41;</span>
&nbsp;</pre></pre></div><br />
<br />
<h4 class="formatter-title">xlsx.addPlot</h4><br />
<br />
<span class="formatter-code">Code R :</span><div class="code"><pre style="display:inline;"><pre class="r" style="font-family:monospace;">&nbsp;
<span style="color: #228B22;">#****************************************</span>
<span style="color: #228B22;">#add Plot </span>
<span style="color: #228B22;">#****************************************</span>
<span style="color: #228B22;">#wb :workbook object</span>
<span style="color: #228B22;">#sheet : sheet object</span>
<span style="color: #228B22;">#startRow : row index to start to write</span>
<span style="color: #228B22;">#startCol : col index to start to write</span>
<span style="color: #228B22;">#plotFunction: plot function</span>
xlsx.<span style="">addPlot</span><span style="color: #080;">&#40;</span> wb, sheet, plotFunction, startRow<span style="color: #080;">=</span>NULL,startCol<span style="color: #080;">=</span><span style="color: #ff0000;">2</span>,
               width<span style="color: #080;">=</span><span style="color: #ff0000;">480</span>, height<span style="color: #080;">=</span><span style="color: #ff0000;">480</span>,... <span style="color: #080;">&#41;</span>
&nbsp;</pre></pre></div><br />
<br />
<h4 class="formatter-title">xlsx.writeFile</h4><br />
<br />
<span class="formatter-code">Code R :</span><div class="code"><pre style="display:inline;"><pre class="r" style="font-family:monospace;">&nbsp;
<span style="color: #228B22;">#****************************************</span>
<span style="color: #228B22;">#Write a data.frame to an Excel workbook</span>
<span style="color: #228B22;">#****************************************</span>
<span style="color: #228B22;">#data : data frame</span>
<span style="color: #228B22;">#file : output file name</span>
<span style="color: #228B22;">#if col.names and row.names : column and row names  are written</span>
<span style="color: #228B22;">#append :if TRUE data should be appended to an existing file. </span>
<span style="color: #228B22;">#usage : res <- xlsx.writeFile(USArrests, file="USArrests.xlsx", sheetName="USArrests")</span>
xlsx.<span style="">writeFile</span><span style="color: #080;">&#40;</span><span style="color: #0000FF; font-weight: bold;">data</span>, <span style="color: #0000FF; font-weight: bold;">file</span>, sheetName<span style="color: #080;">=</span><span style="color: #ff0000;">"Sheet1"</span>,
               col.<span style="">names</span><span style="color: #080;">=</span>TRUE, <span style="color: #0000FF; font-weight: bold;">row.<span style="">names</span></span><span style="color: #080;">=</span>TRUE, <span style="color: #0000FF; font-weight: bold;">append</span><span style="color: #080;">=</span>FALSE, ...<span style="color: #080;">&#41;</span>
&nbsp;</pre></pre></div><br />
<br />
<h4 class="formatter-title">xlsx.readFile</h4><br />
<br />
<span class="formatter-code">Code R :</span><div class="code"><pre style="display:inline;"><pre class="r" style="font-family:monospace;">&nbsp;
<span style="color: #228B22;">#****************************************</span>
<span style="color: #228B22;">#Read a data.frame from an Excel workbook</span>
<span style="color: #228B22;">#****************************************</span>
<span style="color: #228B22;">#file :the path to the file to read</span>
<span style="color: #228B22;">#sheetIndex: a number representing the sheet index in the workbook.</span>
<span style="color: #228B22;">#startRow : index of starting row</span>
<span style="color: #228B22;">#colIndex: a numeric vector indicating the cols you want to extract. If NULL, all columns found will be extracted</span>
<span style="color: #228B22;">#endRow: The index of the last row to pull. If NULL, read all the rows in the sheet.</span>
<span style="color: #228B22;">#header : if TRUE, the first row is considered as row names</span>
<span style="color: #228B22;">#usage : </span>
<span style="color: #228B22;">#file <- system.file("tests", "test_import.xlsx", package = "xlsx")</span>
<span style="color: #228B22;">#res <- xlsx.readFile(file, 1)  # read first sheet</span>
<span style="color: #228B22;">#head(res)</span>
xlsx.<span style="">readFile</span><span style="color: #080;">&#40;</span><span style="color: #0000FF; font-weight: bold;">file</span>, sheetIndex<span style="color: #080;">=</span><span style="color: #ff0000;">1</span>, startRow<span style="color: #080;">=</span><span style="color: #ff0000;">1</span>, colIndex<span style="color: #080;">=</span>NULL, endRow<span style="color: #080;">=</span>NULL, header<span style="color: #080;">=</span>TRUE,...<span style="color: #080;">&#41;</span>
&nbsp;</pre></pre></div><br />
<br />
<br />
<h4 class="formatter-title">xlsx.openFile</h4><br />
<span class="formatter-code">Code R :</span><div class="code"><pre style="display:inline;"><pre class="r" style="font-family:monospace;">&nbsp;
<span style="color: #228B22;">#++++++++++++++++++++++++++++</span>
<span style="color: #228B22;">#Open file</span>
<span style="color: #228B22;">#++++++++++++++++++++++++++++</span>
xlsx.<span style="">openFile</span><span style="color: #080;">&#40;</span>filename<span style="color: #080;">&#41;</span>
&nbsp;</pre></pre></div><br />
<br />
<br />
<br />
<h3 class="formatter-title">Voir aussi</h3><br />
<a href="https://www.sthda.com/french/french/articles/articles-7-36+xlconnect-lire-ecrire-et-manipuler-des-fichiers-microsoft-excel-a-partir-de-r.php">XLConnect: lire, ?crire et manipuler des fichiers Microsoft Excel ? partir de R</a>]]></description>
			<pubDate>Sun, 28 Jul 2013 07:35:00 +0200</pubDate>
			
		</item>
		
		<item>
			<title><![CDATA[R2DOCX : Cr?er un document word avec R]]></title>
			<link>https://www.sthda.com/french/articles/7-r/57-r2docx-creer-un-document-word-avec-r/</link>
			<guid>https://www.sthda.com/french/articles/7-r/57-r2docx-creer-un-document-word-avec-r/</guid>
			<description><![CDATA[<!-- START HTML -->
<ul id="toc"></ul>
<!-- END HTML --><br />
<br />
Deux possibilit?s pour g?n?rer un document word. Soit avec <a href="http://yihui.name/knitr/demo/pandoc/">Knitr et pandoc</a> ou avec <a href="https://github.com/davidgohel/R2DOCX">R2DOCX</a>.<br />
<br />
<h3 class="formatter-title">Pandoc : Convertir un document Markdown vers d'autres formats</h3><br />
<br />
Pour plus de d?tails <a href="http://yihui.name/knitr/demo/pandoc/">cliquez-ici</a><br />
<br />
La fonction pandoc() est incluse dans le package knitr (version 1.2) permettant de convertir des documents Markdown ? d'autres formats tels que Latex/PDF, HTML et word (.doc, .docx).<br />
<br />
Cette fonction permet juste d?ex?cuter de mani?re simple la ligne de commande suivante:<br />
<span class="formatter-code">Code R :</span><div class="code"><pre style="display:inline;"><pre class="r" style="font-family:monospace;">&nbsp;
FILE <span style="color: #080;"><-</span> <span style="color: #ff0000;">"example"</span>
<span style="color: #0000FF; font-weight: bold;">system</span><span style="color: #080;">&#40;</span>paste0<span style="color: #080;">&#40;</span><span style="color: #ff0000;">"pandoc -o "</span>, FILE, <span style="color: #ff0000;">".docx "</span>, FILE, <span style="color: #ff0000;">".md"</span><span style="color: #080;">&#41;</span><span style="color: #080;">&#41;</span>
&nbsp;</pre></pre></div><br />
<br />
<span class="warning"><br />
Pour le fichier.md, le chemin absolu est necessaire. <br />
Utilisez donc la commande :<br />
<span class="formatter-code">Code R :</span><div class="code"><pre style="display:inline;"><pre class="r" style="font-family:monospace;">&nbsp;
commande<span style="color: #080;"><-</span><span style="color: #0000FF; font-weight: bold;">paste</span><span style="color: #080;">&#40;</span><span style="color: #ff0000;">"pandoc -o "</span>,  <span style="color: #ff0000;">"myfile.docx "</span>, <span style="color: #0000FF; font-weight: bold;">getwd</span><span style="color: #080;">&#40;</span><span style="color: #080;">&#41;</span>, <span style="color: #ff0000;">"/myfile.md "</span>, sep<span style="color: #080;">=</span><span style="color: #ff0000;">""</span><span style="color: #080;">&#41;</span>
<span style="color: #0000FF; font-weight: bold;">system</span><span style="color: #080;">&#40;</span>commande<span style="color: #080;">&#41;</span>
&nbsp;</pre></pre></div><br />
</span><br />
<br />
Pour installer pandoc <a href="http://johnmacfarlane.net/pandoc/index.html">suivre ce lien</a><br />
<br />
<strong><span style="color:blue;">Utilisation simple</span></strong><br />
<br />
<span class="formatter-code">Code R :</span><div class="code"><pre style="display:inline;"><pre class="r" style="font-family:monospace;">&nbsp;
<span style="color: #0000FF; font-weight: bold;">library</span><span style="color: #080;">&#40;</span>knitr<span style="color: #080;">&#41;</span>
pandoc<span style="color: #080;">&#40;</span><span style="color: #ff0000;">'foo.md'</span>, <span style="color: #0000FF; font-weight: bold;">format</span><span style="color: #080;">=</span><span style="color: #ff0000;">'html'</span><span style="color: #080;">&#41;</span>  <span style="color: #228B22;"># HTML</span>
pandoc<span style="color: #080;">&#40;</span><span style="color: #ff0000;">'foo.md'</span>, <span style="color: #0000FF; font-weight: bold;">format</span><span style="color: #080;">=</span><span style="color: #ff0000;">'latex'</span><span style="color: #080;">&#41;</span> <span style="color: #228B22;"># LaTeX/PDF</span>
pandoc<span style="color: #080;">&#40;</span><span style="color: #ff0000;">'foo.md'</span>, <span style="color: #0000FF; font-weight: bold;">format</span><span style="color: #080;">=</span><span style="color: #ff0000;">'docx'</span><span style="color: #080;">&#41;</span>  <span style="color: #228B22;"># MS Word</span>
pandoc<span style="color: #080;">&#40;</span><span style="color: #ff0000;">'foo.md'</span>, <span style="color: #0000FF; font-weight: bold;">format</span><span style="color: #080;">=</span><span style="color: #ff0000;">'odt'</span><span style="color: #080;">&#41;</span>   <span style="color: #228B22;"># OpenDocument</span>
&nbsp;</pre></pre></div><br />
<br />
<br />
<h3 class="formatter-title">Cr?er un document word avec R2DOCX</h3><br />
<br />
R2DOCX permet de cr?er, de mani?re simple, un document word ? partir d'un template ou pas, d'ins?rer des graphiques et des tables.<br />
<br />
Une documentation est compl?te est fournie <a href="https://github.com/davidgohel/R2DOCX">ici</a><br />
Un exemple est montr? <a href="http://blog.revolutionanalytics.com/2013/06/create-word-documents-from-r-with-r2docx.html">ici</a><br />
<br />
 <h4 class="formatter-title">Installation</h4> <br />
<br />
<strong>Compatibilit? R >= 3.0</strong><br />
<br />
<span class="formatter-code">Code R :</span><div class="code"><pre style="display:inline;"><pre class="r" style="font-family:monospace;">&nbsp;
<span style="color: #0000FF; font-weight: bold;">install.<span style="">packages</span></span><span style="color: #080;">&#40;</span><span style="color: #ff0000;">"devtools"</span><span style="color: #080;">&#41;</span>
devtools<span style="color: #080;">::</span><span style="">install_github</span><span style="color: #080;">&#40;</span><span style="color: #ff0000;">'R2DOC'</span>, <span style="color: #ff0000;">'davidgohel'</span><span style="color: #080;">&#41;</span>
devtools<span style="color: #080;">::</span><span style="">install_github</span><span style="color: #080;">&#40;</span><span style="color: #ff0000;">'R2DOCX'</span>, <span style="color: #ff0000;">'davidgohel'</span><span style="color: #080;">&#41;</span>
&nbsp;</pre></pre></div><br />
<br />
<strong><span style="color:blue;">Pour les utilisateurs de Mac :</span></strong><br />
<br />
<span class="formatter-code">Code R :</span><div class="code"><pre style="display:inline;"><pre class="r" style="font-family:monospace;">&nbsp;
<span style="color: #0000FF; font-weight: bold;">Sys.<span style="">setenv</span></span><span style="color: #080;">&#40;</span>NOAWT<span style="color: #080;">=</span><span style="color: #ff0000;">1</span><span style="color: #080;">&#41;</span> <span style="color: #228B22;">#prevents usage of awt.[http://cran.r-project.org/doc/manuals/r-devel/R-admin.html#Java-_0028OS-X_0029]</span>
<span style="color: #0000FF; font-weight: bold;">install.<span style="">packages</span></span><span style="color: #080;">&#40;</span><span style="color: #ff0000;">"devtools"</span><span style="color: #080;">&#41;</span>
devtools<span style="color: #080;">::</span><span style="">install_github</span><span style="color: #080;">&#40;</span><span style="color: #ff0000;">'R2DOC'</span>, <span style="color: #ff0000;">'davidgohel'</span><span style="color: #080;">&#41;</span>
devtools<span style="color: #080;">::</span><span style="">install_github</span><span style="color: #080;">&#40;</span><span style="color: #ff0000;">'R2DOCX'</span>, <span style="color: #ff0000;">'davidgohel'</span><span style="color: #080;">&#41;</span>
&nbsp;</pre></pre></div><br />
<br />
<br />
 <h4 class="formatter-title">Les fonctions disponibles</h4> <br />
<ul class="formatter-ul">
<li class="formatter-li"><strong>addPlot</strong> pour ajouter un graphique.
</li><li class="formatter-li"><strong>addParagraph</strong> pour ajouter un paragraphe de textes
</li><li class="formatter-li"><strong>addTable</strong> pour ajouter des tables.
</li><li class="formatter-li"><strong>addHeader</strong> pour ajouter des titres.
</li><li class="formatter-li"><strong>addTOC</strong> pour ajouter une table des mati?res.
</li><li class="formatter-li"><strong>addPageBreak</strong> pour ajouter un saut de page.
</li><li class="formatter-li"><strong>addLineBreak</strong> pour ajouter un saut de ligne.
</li><li class="formatter-li"><strong>replaceText</strong> pour remplacer du texte.<br />
</li></ul><br />
<br />
 <h4 class="formatter-title">Votre premier document</h4> <br />
<br />
<span class="formatter-code">Code R :</span><div class="code"><pre style="display:inline;"><pre class="r" style="font-family:monospace;">&nbsp;
<span style="color: #0000FF; font-weight: bold;">Sys.<span style="">setenv</span></span><span style="color: #080;">&#40;</span>NOAWT<span style="color: #080;">=</span><span style="color: #ff0000;">1</span><span style="color: #080;">&#41;</span> <span style="color: #228B22;">#prevents usage of awt - required on Mac</span>
<span style="color: #0000FF; font-weight: bold;">library</span><span style="color: #080;">&#40;</span>R2DOCX<span style="color: #080;">&#41;</span>
<span style="color: #228B22;"># Nom du fichier ? cr?er</span>
docx.<span style="">file</span> <span style="color: #080;"><-</span> <span style="color: #ff0000;">"document.docx"</span>
<span style="color: #228B22;"># Objet Docx ? manipuler</span>
doc <span style="color: #080;"><-</span> <span style="color: #0000FF; font-weight: bold;">new</span> <span style="color: #080;">&#40;</span><span style="color: #ff0000;">"Docx"</span>, <span style="color: #0000FF; font-weight: bold;">title</span> <span style="color: #080;">=</span> <span style="color: #ff0000;">"My example"</span> <span style="color: #080;">&#41;</span>
<span style="color: #228B22;">#ajouter une table</span>
doc <span style="color: #080;">=</span> addTable<span style="color: #080;">&#40;</span> doc, <span style="color: #CC9900; font-weight: bold;">iris</span><span style="color: #080;">&#91;</span><span style="color: #ff0000;">1</span><span style="color: #080;">:</span><span style="color: #ff0000;">10</span>,<span style="color: #080;">&#93;</span> <span style="color: #080;">&#41;</span>
<span style="color: #228B22;"># Ajouter du texte</span>
doc <span style="color: #080;"><-</span> addParagraph<span style="color: #080;">&#40;</span> doc, value <span style="color: #080;">=</span> <span style="color: #ff0000;">"Hello World!"</span>, stylename <span style="color: #080;">=</span> <span style="color: #ff0000;">"Normal"</span> <span style="color: #080;">&#41;</span>
<span style="color: #228B22;"># ajouter un graphique</span>
doc <span style="color: #080;">=</span> addPlot<span style="color: #080;">&#40;</span> doc, <span style="color: #0000FF; font-weight: bold;">function</span><span style="color: #080;">&#40;</span><span style="color: #080;">&#41;</span> <span style="color: #0000FF; font-weight: bold;">plot</span><span style="color: #080;">&#40;</span> <span style="color: #0000FF; font-weight: bold;">rnorm</span><span style="color: #080;">&#40;</span><span style="color: #ff0000;">10</span><span style="color: #080;">&#41;</span>, <span style="color: #0000FF; font-weight: bold;">rnorm</span><span style="color: #080;">&#40;</span><span style="color: #ff0000;">10</span><span style="color: #080;">&#41;</span> <span style="color: #080;">&#41;</span>
               , width <span style="color: #080;">=</span> <span style="color: #ff0000;">10</span>, height <span style="color: #080;">=</span> <span style="color: #ff0000;">8</span>
<span style="color: #080;">&#41;</span>
<span style="color: #228B22;"># Ecriture du fichier </span>
writeDoc<span style="color: #080;">&#40;</span> doc, docx.<span style="">file</span> <span style="color: #080;">&#41;</span>
&nbsp;</pre></pre></div><br />
<br />
 <h4 class="formatter-title">Cr?er un document word ? partir d'un template</h4> <br />
<span class="formatter-code">Code R :</span><div class="code"><pre style="display:inline;"><pre class="r" style="font-family:monospace;">&nbsp;
<span style="color: #228B22;"># document word ? cr?er</span>
docx.<span style="">file</span> <span style="color: #080;">=</span> <span style="color: #ff0000;">"document.docx"</span>
<span style="color: #228B22;"># Document word ? utiliser comme template</span>
template.<span style="">file</span> <span style="color: #080;">=</span> <span style="color: #0000FF; font-weight: bold;">file.<span style="">path</span></span><span style="color: #080;">&#40;</span> find.<span style="">package</span><span style="color: #080;">&#40;</span><span style="color: #ff0000;">"R2DOCX"</span><span style="color: #080;">&#41;</span>, <span style="color: #ff0000;">"templates/TEMPLATE_01.docx"</span>, fsep <span style="color: #080;">=</span> <span style="color: #ff0000;">"/"</span> <span style="color: #080;">&#41;</span>
<span style="color: #228B22;"># Cr?er un nouveau objet</span>
doc <span style="color: #080;">=</span> <span style="color: #0000FF; font-weight: bold;">new</span><span style="color: #080;">&#40;</span><span style="color: #ff0000;">"Docx"</span>
, <span style="color: #0000FF; font-weight: bold;">title</span> <span style="color: #080;">=</span> <span style="color: #ff0000;">"My example"</span> 
, basefile <span style="color: #080;">=</span> template.<span style="">file</span>
<span style="color: #080;">&#41;</span>
<span style="color: #228B22;"># Dans le document de base, 2 mots cl?s existent- Rempla?ons les</span>
doc <span style="color: #080;">=</span> replaceText<span style="color: #080;">&#40;</span> doc, pattern <span style="color: #080;">=</span> <span style="color: #ff0000;">"AUTHOR"</span>, replacement <span style="color: #080;">=</span> <span style="color: #ff0000;">"John Doe"</span> <span style="color: #080;">&#41;</span>
doc <span style="color: #080;">=</span> replaceText<span style="color: #080;">&#40;</span> doc, pattern <span style="color: #080;">=</span> <span style="color: #ff0000;">"DATE"</span>, replacement <span style="color: #080;">=</span> <span style="color: #0000FF; font-weight: bold;">date</span><span style="color: #080;">&#40;</span><span style="color: #080;">&#41;</span> <span style="color: #080;">&#41;</span>
&nbsp;</pre></pre></div><br />
<br />
<br />
 <h4 class="formatter-title">Titre principal</h4> <br />
<br />
<span class="formatter-code">Code R :</span><div class="code"><pre style="display:inline;"><pre class="r" style="font-family:monospace;">&nbsp;
<span style="color: #228B22;">#Titre principale</span>
<span style="color: #228B22;">#**************************************</span>
doc <span style="color: #080;">=</span> addParagraph<span style="color: #080;">&#40;</span> doc, value <span style="color: #080;">=</span> <span style="color: #ff0000;">"Exemple"</span>, stylename <span style="color: #080;">=</span> <span style="color: #ff0000;">"TitleDoc"</span> <span style="color: #080;">&#41;</span>
doc <span style="color: #080;">=</span> addPageBreak<span style="color: #080;">&#40;</span> doc <span style="color: #080;">&#41;</span> <span style="color: #228B22;">#saut de page</span>
&nbsp;</pre></pre></div><br />
<br />
<!-- START HTML -->
<center><div class="highlight_3d" style="width:500px; height:70px"><img src="https://www.sthda.com/french/french/upload/r2docx_titre.png"/></div></center>
<!-- END HTML --><br />
<br />
 <h4 class="formatter-title">Table des mati?res</h4> <br />
<br />
<span class="formatter-code">Code R :</span><div class="code"><pre style="display:inline;"><pre class="r" style="font-family:monospace;">&nbsp;
<span style="color: #228B22;">#Table des mati?re (table of content : TOC)</span>
<span style="color: #228B22;">#**************************************</span>
<span style="color: #228B22;">#On vous demandera de mettre ? jour la table de mati?res</span>
<span style="color: #228B22;">#la pr?mi?re fois que le document sera ouvert</span>
doc <span style="color: #080;">=</span> addHeader<span style="color: #080;">&#40;</span>doc, <span style="color: #ff0000;">"Table des mati?res"</span>, <span style="color: #ff0000;">1</span><span style="color: #080;">&#41;</span><span style="color: #080;">;</span>
doc <span style="color: #080;">=</span> addTOC<span style="color: #080;">&#40;</span>doc<span style="color: #080;">&#41;</span>
doc <span style="color: #080;">=</span> addPageBreak<span style="color: #080;">&#40;</span> doc <span style="color: #080;">&#41;</span><span style="color: #228B22;">#saut de page</span>
&nbsp;</pre></pre></div><br />
<br />
<!-- START HTML -->
<center><div class="highlight_3d" style="width:520px; height:185px"><img src="https://www.sthda.com/french/french/upload/r2docx_toc.png"/></div></center>
<!-- END HTML --><br />
<br />
 <h4 class="formatter-title">Ajout de textes (Normal et liste)</h4> <br />
<br />
<span class="formatter-code">Code R :</span><div class="code"><pre style="display:inline;"><pre class="r" style="font-family:monospace;">&nbsp;
<span style="color: #228B22;"># Ajout de textes (normal and liste)</span>
<span style="color: #228B22;">#**************************************</span>
doc <span style="color: #080;">=</span> addHeader<span style="color: #080;">&#40;</span>doc, <span style="color: #ff0000;">"Dataset presentation"</span>, <span style="color: #ff0000;">1</span><span style="color: #080;">&#41;</span><span style="color: #080;">;</span>
<span style="color: #228B22;">#texte normal</span>
doc <span style="color: #080;">=</span> addParagraph<span style="color: #080;">&#40;</span> doc, value <span style="color: #080;">=</span> <span style="color: #ff0000;">"Dataset 'measured.weights' is set of weights measurements collected on few people before savate training."</span>, stylename <span style="color: #080;">=</span> <span style="color: #ff0000;">"Normal"</span> <span style="color: #080;">&#41;</span>
<span style="color: #228B22;">#liste non ordonn?e</span>
texts <span style="color: #080;">=</span> <span style="color: #0000FF; font-weight: bold;">c</span><span style="color: #080;">&#40;</span> <span style="color: #ff0000;">"Column 'gender' is the subject gender."</span> 
           , <span style="color: #ff0000;">"Column 'id' is the unique subject identifier."</span> 
           , <span style="color: #ff0000;">"Column 'cat' is the subject weight category."</span> 
           , <span style="color: #ff0000;">"Column 'competitor' tells wether or not subject practice competition."</span> 
           , <span style="color: #ff0000;">"Column 'day' is the day of measurement."</span> 
           , <span style="color: #ff0000;">"Column 'weight' is the measured weight."</span> 
<span style="color: #080;">&#41;</span>
doc <span style="color: #080;">=</span> addParagraph<span style="color: #080;">&#40;</span> doc, value <span style="color: #080;">=</span> texts, stylename <span style="color: #080;">=</span> <span style="color: #ff0000;">"BulletList"</span> <span style="color: #080;">&#41;</span>
&nbsp;</pre></pre></div><br />
<br />
<!-- START HTML -->
<center><div class="highlight_3d" style="width:515px; height:220px"><img src="https://www.sthda.com/french/french/upload/r2docx_texte.png"/></div></center>
<!-- END HTML --><br />
<br />
 <h4 class="formatter-title">Formatage conditionnel du texte</h4> <br />
<br />
La fonction <strong>addParagraph</strong> permet d'ajouter simplement du texte comme montr? ci-dessus. Elle peut ?galement ?tre utilis?e pour faire du remplacement de textes et du formatage conditionnel.<br />
<br />
<span class="formatter-code">Code R :</span><div class="code"><pre style="display:inline;"><pre class="r" style="font-family:monospace;">&nbsp;
<span style="color: #228B22;"># template text</span>
x <span style="color: #080;">=</span> <span style="color: #ff0000;">"[animal] eats [food]."</span>
<span style="color: #228B22;"># define formatting properties for replacement text ? see chapter "styles"</span>
textProp <span style="color: #080;">=</span> textProperties<span style="color: #080;">&#40;</span> color <span style="color: #080;">=</span> <span style="color: #ff0000;">"blue"</span> <span style="color: #080;">&#41;</span>
replacement.<span style="">styles</span> <span style="color: #080;">=</span> <span style="color: #0000FF; font-weight: bold;">list</span><span style="color: #080;">&#40;</span> animal<span style="color: #080;">=</span> textProp, food<span style="color: #080;">=</span> textProp <span style="color: #080;">&#41;</span>
<span style="color: #228B22;"># define replacement text</span>
replacements <span style="color: #080;">=</span> <span style="color: #0000FF; font-weight: bold;">list</span><span style="color: #080;">&#40;</span> animal <span style="color: #080;">=</span> <span style="color: #ff0000;">"donkey"</span>, food <span style="color: #080;">=</span> <span style="color: #ff0000;">"grass"</span> <span style="color: #080;">&#41;</span>
doc <span style="color: #080;"><-</span> addParagraph<span style="color: #080;">&#40;</span> doc, value <span style="color: #080;">=</span> x, stylename <span style="color: #080;">=</span> <span style="color: #ff0000;">"Normal"</span>
                     , replacements <span style="color: #080;">=</span> replacements
                     , replacement.<span style="">styles</span> <span style="color: #080;">=</span> replacement.<span style="">styles</span>
<span style="color: #080;">&#41;</span>
&nbsp;</pre></pre></div><br />
<br />
<!-- START HTML -->
<center><div class="highlight_3d" style="width:218px; height:45px"><img src="https://www.sthda.com/french/french/upload/r2docx_replacement.png"/></div></center>
<!-- END HTML --><br />
<br />
<span class="notice"><strong>La fonction textProperties</strong><br />
<span class="formatter-code">Code R :</span><div class="code"><pre style="display:inline;"><pre class="r" style="font-family:monospace;">textProperties<span style="color: #080;">&#40;</span>color <span style="color: #080;">=</span> <span style="color: #ff0000;">"black"</span>, font.<span style="">size</span> <span style="color: #080;">=</span> <span style="color: #ff0000;">10</span>
, font.<span style="">weight</span> <span style="color: #080;">=</span> <span style="color: #ff0000;">"normal"</span>, font.<span style="">style</span> <span style="color: #080;">=</span> <span style="color: #ff0000;">"normal"</span>
, font.<span style="">family</span> <span style="color: #080;">=</span> <span style="color: #ff0000;">"Arial"</span> <span style="color: #080;">&#41;</span></pre></pre></div><br />
<br />
<strong>color</strong>: couleur de la police; <strong>font.size</strong>: taille en pixel; <strong>font.weight</strong> : "normal" ou "bold"; <strong>font.style</strong>: "normal" ou "italic"; <strong>font.family</strong>: police.<br />
</span><br />
 <h4 class="formatter-title">Ajouter une table</h4> <br />
<br />
<strong><span style="color:blue;">Table simple: </span></strong><br />
<br />
<span class="formatter-code">Code R :</span><div class="code"><pre style="display:inline;"><pre class="r" style="font-family:monospace;">&nbsp;
<span style="color: #228B22;"># Ajouter une table</span>
<span style="color: #228B22;">#**************************************</span>
<span style="color: #228B22;"># Table utilisee</span>
<span style="color: #0000FF; font-weight: bold;">data</span><span style="color: #080;">&#40;</span> measured.<span style="">weights</span> <span style="color: #080;">&#41;</span>
doc <span style="color: #080;">=</span> addHeader<span style="color: #080;">&#40;</span>doc, <span style="color: #ff0000;">"Dataset"</span>, <span style="color: #ff0000;">1</span><span style="color: #080;">&#41;</span><span style="color: #080;">;</span>
doc <span style="color: #080;">=</span> addHeader<span style="color: #080;">&#40;</span>doc, <span style="color: #ff0000;">"Dataset first lines"</span>, <span style="color: #ff0000;">2</span><span style="color: #080;">&#41;</span><span style="color: #080;">;</span>
<span style="color: #228B22;">#Table simple</span>
doc <span style="color: #080;">=</span> addTable<span style="color: #080;">&#40;</span> doc
                , <span style="color: #0000FF; font-weight: bold;">data</span> <span style="color: #080;">=</span> <span style="color: #0000FF; font-weight: bold;">head</span><span style="color: #080;">&#40;</span> measured.<span style="">weights</span>, n <span style="color: #080;">=</span> <span style="color: #ff0000;">10</span> <span style="color: #080;">&#41;</span>
                , formats <span style="color: #080;">=</span> get.<span style="">light</span>.<span style="">formats</span><span style="color: #080;">&#40;</span><span style="color: #080;">&#41;</span>
<span style="color: #080;">&#41;</span>
doc <span style="color: #080;">=</span> addLineBreak<span style="color: #080;">&#40;</span> doc <span style="color: #080;">&#41;</span><span style="color: #228B22;">#saut de ligne</span>
&nbsp;</pre></pre></div><br />
<br />
<!-- START HTML -->
<center><div class="highlight_3d" style="width:511px; height:278px"><img src="https://www.sthda.com/french/french/upload/r2docx_table.png"/></div></center>
<!-- END HTML --><br />
<br />
<strong><span style="color:blue;">Renommer les ent?tes de la table:</span></strong><br />
<br />
<strong>Avant</strong> d'avoir renomm? :<br />
<br />
<span class="formatter-code">Code R :</span><div class="code"><pre style="display:inline;"><pre class="r" style="font-family:monospace;">&nbsp;
doc <span style="color: #080;">=</span> addTable<span style="color: #080;">&#40;</span> doc, <span style="color: #0000FF; font-weight: bold;">data</span> <span style="color: #080;">=</span> weights.<span style="">summary</span><span style="color: #080;">&#41;</span>
&nbsp;</pre></pre></div><br />
<br />
<!-- START HTML -->
<center><div class="highlight_3d" style="width:312px; height:147px"><img src="https://www.sthda.com/french/french/upload/r2docx_table2.png"/></div></center>
<!-- END HTML --><br />
<br />
<strong>Apr?s</strong> avoir renomm? :<br />
<br />
<span class="formatter-code">Code R :</span><div class="code"><pre style="display:inline;"><pre class="r" style="font-family:monospace;">&nbsp;
doc <span style="color: #080;">=</span> addTable<span style="color: #080;">&#40;</span> doc
, <span style="color: #0000FF; font-weight: bold;">data</span> <span style="color: #080;">=</span> weights.<span style="">summary</span>
, header.<span style="">labels</span> <span style="color: #080;">=</span> <span style="color: #0000FF; font-weight: bold;">list</span><span style="color: #080;">&#40;</span><span style="color: #ff0000;">"id"</span> <span style="color: #080;">=</span> <span style="color: #ff0000;">"Subject Identifier"</span>, <span style="color: #ff0000;">"avg.weight"</span> <span style="color: #080;">=</span> <span style="color: #ff0000;">"Average Weight"</span>
, <span style="color: #ff0000;">"regularity"</span> <span style="color: #080;">=</span> <span style="color: #ff0000;">"Regularity"</span>, <span style="color: #ff0000;">"visit.n"</span> <span style="color: #080;">=</span> <span style="color: #ff0000;">"Number of visits"</span>, <span style="color: #ff0000;">"last.day"</span> <span style="color: #080;">=</span> <span style="color: #ff0000;">"Last visit"</span>
<span style="color: #080;">&#41;</span> <span style="color: #228B22;"># columns labels to display</span>
<span style="color: #080;">&#41;</span>
&nbsp;</pre></pre></div><br />
<br />
<!-- START HTML -->
<center><div class="highlight_3d" style="width:462px; height:182px"><img src="https://www.sthda.com/french/french/upload/r2docx_table_header_label.png"/></div></center>
<!-- END HTML --><br />
<br />
<strong><span style="color:blue;">Table simple personnalis?e avec fusion des lignes :</span></strong><br />
<br />
Dans la table ci-dessous, les lignes sont fusionn?es sur la colonne 'day'. La colonne 'gender' est color?e en fonction du genre.<br />
<br />
<span class="formatter-code">Code R :</span><div class="code"><pre style="display:inline;"><pre class="r" style="font-family:monospace;">&nbsp;
<span style="color: #228B22;"># simple addTable with row merging on 'day' column</span>
doc <span style="color: #080;">=</span> addHeader<span style="color: #080;">&#40;</span>doc, <span style="color: #ff0000;">"Dataset last lines"</span>, <span style="color: #ff0000;">2</span><span style="color: #080;">&#41;</span><span style="color: #080;">;</span>
sampledata <span style="color: #080;">=</span> <span style="color: #0000FF; font-weight: bold;">tail</span><span style="color: #080;">&#40;</span> measured.<span style="">weights</span><span style="color: #080;">&#91;</span> <span style="color: #0000FF; font-weight: bold;">order</span><span style="color: #080;">&#40;</span>measured.<span style="">weights</span>$day<span style="color: #080;">&#41;</span>, <span style="color: #080;">&#93;</span>, n <span style="color: #080;">=</span> <span style="color: #ff0000;">20</span> <span style="color: #080;">&#41;</span>
doc <span style="color: #080;">=</span> addTable<span style="color: #080;">&#40;</span> doc
, <span style="color: #0000FF; font-weight: bold;">data</span> <span style="color: #080;">=</span> sampledata
, span.<span style="">columns</span> <span style="color: #080;">=</span> <span style="color: #0000FF; font-weight: bold;">c</span><span style="color: #080;">&#40;</span><span style="color: #ff0000;">"day"</span><span style="color: #080;">&#41;</span>
, col.<span style="">colors</span> <span style="color: #080;">=</span> <span style="color: #0000FF; font-weight: bold;">list</span><span style="color: #080;">&#40;</span> <span style="color: #ff0000;">"gender"</span> <span style="color: #080;">=</span> <span style="color: #0000FF; font-weight: bold;">ifelse</span><span style="color: #080;">&#40;</span> sampledata$gender <span style="color: #080;">==</span> <span style="color: #ff0000;">"male"</span> , <span style="color: #ff0000;">"#00c2ff"</span>, <span style="color: #ff0000;">"#ffcdd1"</span><span style="color: #080;">&#41;</span> <span style="color: #080;">&#41;</span>
<span style="color: #080;">&#41;</span>
&nbsp;</pre></pre></div><br />
<br />
<!-- START HTML -->
<center><div class="highlight_3d" style="width:311px; height:453px"><img src="https://www.sthda.com/french/french/upload/r2docx_table_merge_row.png"/></div></center>
<!-- END HTML --><br />
<br />
<strong><span style="color:blue;">Table personnalis?e avec ent?tes group?es:</span></strong><br />
<br />
Dans cette table les ent?tes ont ?t? renomm?es, des ent?tes group?es sont cr?es, le type des colonnes est pr?cis? (%, entier, caract?re, nombre d?cimal, date). Les valeurs de la colonne "Regularity" ont ?t? color?es en fonction de la valeur (couleur grise si < 0.5 et bleu si >= 0.5).<br />
<br />
<span class="formatter-code">Code R :</span><div class="code"><pre style="display:inline;"><pre class="r" style="font-family:monospace;">&nbsp;
<span style="color: #228B22;"># customized table</span>
doc <span style="color: #080;">=</span> addHeader<span style="color: #080;">&#40;</span>doc, <span style="color: #ff0000;">"Dataset summary"</span>, <span style="color: #ff0000;">1</span><span style="color: #080;">&#41;</span><span style="color: #080;">;</span>
doc <span style="color: #080;">=</span> addTable<span style="color: #080;">&#40;</span> doc
, <span style="color: #0000FF; font-weight: bold;">data</span> <span style="color: #080;">=</span> weights.<span style="">summary</span>
, header.<span style="">labels</span> <span style="color: #080;">=</span> <span style="color: #0000FF; font-weight: bold;">list</span><span style="color: #080;">&#40;</span><span style="color: #ff0000;">"id"</span> <span style="color: #080;">=</span> <span style="color: #ff0000;">"Subject Identifier"</span>, <span style="color: #ff0000;">"avg.weight"</span> <span style="color: #080;">=</span> <span style="color: #ff0000;">"Average Weight"</span>
, <span style="color: #ff0000;">"regularity"</span> <span style="color: #080;">=</span> <span style="color: #ff0000;">"Regularity"</span>, <span style="color: #ff0000;">"visit.n"</span> <span style="color: #080;">=</span> <span style="color: #ff0000;">"Number of visits"</span>, <span style="color: #ff0000;">"last.day"</span> <span style="color: #080;">=</span> <span style="color: #ff0000;">"Last visit"</span>
<span style="color: #080;">&#41;</span> <span style="color: #228B22;"># columns labels to display</span>
, grouped.<span style="">cols</span><span style="color: #080;">=</span><span style="color: #0000FF; font-weight: bold;">list</span><span style="color: #080;">&#40;</span> <span style="color: #ff0000;">"id"</span> <span style="color: #080;">=</span> <span style="color: #ff0000;">"id"</span>
, <span style="color: #ff0000;">"Summary"</span> <span style="color: #080;">=</span> <span style="color: #0000FF; font-weight: bold;">c</span><span style="color: #080;">&#40;</span> <span style="color: #ff0000;">"avg.weight"</span>,  <span style="color: #ff0000;">"regularity"</span>, <span style="color: #ff0000;">"visit.n"</span>, <span style="color: #ff0000;">"last.day"</span> <span style="color: #080;">&#41;</span> 
<span style="color: #080;">&#41;</span> <span style="color: #228B22;"># grouped headers line to add before headers line</span>
, col.<span style="">types</span> <span style="color: #080;">=</span> <span style="color: #0000FF; font-weight: bold;">list</span><span style="color: #080;">&#40;</span> <span style="color: #ff0000;">"id"</span> <span style="color: #080;">=</span> <span style="color: #ff0000;">"character"</span>, <span style="color: #ff0000;">"avg.weight"</span> <span style="color: #080;">=</span> <span style="color: #ff0000;">"double"</span>
, <span style="color: #ff0000;">"regularity"</span> <span style="color: #080;">=</span> <span style="color: #ff0000;">"percent"</span>, <span style="color: #ff0000;">"visit.n"</span> <span style="color: #080;">=</span> <span style="color: #ff0000;">"integer"</span>
, <span style="color: #ff0000;">"last.day"</span> <span style="color: #080;">=</span> <span style="color: #ff0000;">"date"</span> <span style="color: #080;">&#41;</span> <span style="color: #228B22;"># reporting types of each columns </span>
, col.<span style="">fontcolors</span> <span style="color: #080;">=</span> <span style="color: #0000FF; font-weight: bold;">list</span><span style="color: #080;">&#40;</span> <span style="color: #ff0000;">"regularity"</span> <span style="color: #080;">=</span> <span style="color: #0000FF; font-weight: bold;">ifelse</span><span style="color: #080;">&#40;</span> weights.<span style="">summary</span>$regularity <span style="color: #080;"><</span> <span style="color: #ff0000;">0.5</span> , <span style="color: #ff0000;">"gray"</span>, <span style="color: #ff0000;">"blue"</span><span style="color: #080;">&#41;</span> <span style="color: #080;">&#41;</span> <span style="color: #228B22;"># customized font colors for column "regularity"</span>
<span style="color: #080;">&#41;</span>
&nbsp;</pre></pre></div><br />
<br />
<!-- START HTML -->
<center><div class="highlight_3d" style="width:530px; height:266px"><img src="https://www.sthda.com/french/french/upload/r2docx_table_customized.png"/></div></center>
<!-- END HTML --><br />
<br />
 <h4 class="formatter-title">Ajouter un graphique</h4> <br />
<br />
<span class="formatter-code">Code R :</span><div class="code"><pre style="display:inline;"><pre class="r" style="font-family:monospace;">&nbsp;
<span style="color: #228B22;"># Ajouter un grahique</span>
<span style="color: #228B22;">#**************************************</span>
doc <span style="color: #080;">=</span> addPageBreak<span style="color: #080;">&#40;</span> doc <span style="color: #080;">&#41;</span>
doc <span style="color: #080;">=</span> addHeader<span style="color: #080;">&#40;</span>doc, <span style="color: #ff0000;">"Graphics"</span>, <span style="color: #ff0000;">1</span><span style="color: #080;">&#41;</span><span style="color: #080;">;</span>
doc <span style="color: #080;">=</span> addPlot<span style="color: #080;">&#40;</span> doc,
               <span style="color: #0000FF; font-weight: bold;">function</span><span style="color: #080;">&#40;</span><span style="color: #080;">&#41;</span> <span style="color: #0000FF; font-weight: bold;">boxplot</span><span style="color: #080;">&#40;</span>measured.<span style="">weights</span>$weight ~ measured.<span style="">weights</span>$id,
                                  xlab <span style="color: #080;">=</span> <span style="color: #ff0000;">"Subjects"</span>, ylab <span style="color: #080;">=</span> <span style="color: #ff0000;">"Weights"</span> , <span style="color: #0000FF; font-weight: bold;">col</span> <span style="color: #080;">=</span> <span style="color: #ff0000;">"#0088cc"</span>,
                                  <span style="color: #0000FF; font-weight: bold;">legend</span> <span style="color: #080;">=</span> <span style="color: #ff0000;">"My boxplot"</span><span style="color: #080;">&#41;</span>,
               width<span style="color: #080;">=</span><span style="color: #ff0000;">7</span>, height<span style="color: #080;">=</span><span style="color: #ff0000;">7</span>
              <span style="color: #080;">&#41;</span>
&nbsp;</pre></pre></div><br />
<br />
<!-- START HTML -->
<center><div class="highlight_3d" style="width:516px; height:534px"><img src="https://www.sthda.com/french/french/upload/r2docx_plot.png"/></div></center>
<!-- END HTML --><br />
<br />
 <h4 class="formatter-title">Remplacement de texte</h4> <br />
<br />
Pour remplacer le mot cl? "AUTHOR", dans le document word, avec "Pearson" :<br />
<br />
<span class="formatter-code">Code R :</span><div class="code"><pre style="display:inline;"><pre class="r" style="font-family:monospace;">&nbsp;
doc <span style="color: #080;">=</span> replaceText<span style="color: #080;">&#40;</span> doc, <span style="color: #ff0000;">"AUTHOR"</span>, <span style="color: #ff0000;">"Pearson"</span><span style="color: #080;">&#41;</span>
&nbsp;</pre></pre></div><br />
<br />
 <h4 class="formatter-title">Les styles de titres disponibles dans votre document</h4> <br />
<br />
<span class="formatter-code">Code R :</span><div class="code"><pre style="display:inline;"><pre class="r" style="font-family:monospace;">&nbsp;
doc <span style="color: #080;"><-</span> <span style="color: #0000FF; font-weight: bold;">new</span><span style="color: #080;">&#40;</span><span style="color: #ff0000;">"Docx"</span>, <span style="color: #0000FF; font-weight: bold;">title</span> <span style="color: #080;">=</span> <span style="color: #ff0000;">"My example"</span> <span style="color: #080;">&#41;</span>
styles<span style="color: #080;">&#40;</span> doc <span style="color: #080;">&#41;</span>
<span style="color: #228B22;"># [1] "Normal"                  "Titre1"                  "Titre2"                 </span>
<span style="color: #228B22;"># [4] "Titre3"                  "Titre4"                  "Titre5"                 </span>
<span style="color: #228B22;"># [7] "Titre6"                  "Titre7"                  "Titre8"                 </span>
<span style="color: #228B22;">#[10] "Titre9"                  "Policepardfaut"          "TableauNormal"          </span>
<span style="color: #228B22;"># ...</span>
doc <span style="color: #080;"><-</span> setHeaderStyle<span style="color: #080;">&#40;</span>doc, stylenames <span style="color: #080;">=</span> <span style="color: #0000FF; font-weight: bold;">c</span><span style="color: #080;">&#40;</span><span style="color: #ff0000;">"Titre1"</span>, <span style="color: #ff0000;">"Titre2"</span>, <span style="color: #ff0000;">"Titre3"</span>, <span style="color: #ff0000;">"Titre4"</span>, <span style="color: #ff0000;">"Titre5"</span>, <span style="color: #ff0000;">"Titre6"</span>, <span style="color: #ff0000;">"Titre7"</span>, <span style="color: #ff0000;">"Titre8"</span>, <span style="color: #ff0000;">"Titre9"</span> <span style="color: #080;">&#41;</span> <span style="color: #080;">&#41;</span> 
doc <span style="color: #080;">=</span> addHeader<span style="color: #080;">&#40;</span> doc, <span style="color: #ff0000;">"title 1"</span>, <span style="color: #ff0000;">1</span> <span style="color: #080;">&#41;</span>
&nbsp;</pre></pre></div><br />
<br />
<br />
 <h4 class="formatter-title">Un document word complet</h4> <br />
<br />
<span class="success">Le script complet utilis? pour cr?e le document word suivant est t?l?chargeable ici : <a href="https://www.sthda.com/french/french/upload/r2docx.r">R2DOCX.r</a></span><br />
<br />
<!-- START HTML -->
<a href="https://www.sthda.com/french/french/upload/r2docx_word.pdf" class="embed" >Document word complet</a>
<!-- END HTML --><br />
<br />
 <h4 class="formatter-title">Voir Aussi</h4> <br />
<br />
<a href="https://www.sthda.com/french/french/articles/articles-7-60+r2xlsx-lire-ecrire-et-formater-un-document.php">R2XLSX : lire, ?crire et formater un document Excel dans R </a>]]></description>
			<pubDate>Sat, 06 Jul 2013 08:26:00 +0200</pubDate>
			
		</item>
		
	</channel>
</rss>
