% Options for packages loaded elsewhere
\PassOptionsToPackage{unicode}{hyperref}
\PassOptionsToPackage{hyphens}{url}
%
\documentclass[
]{article}
\usepackage{lmodern}
\usepackage{amssymb,amsmath}
\usepackage{ifxetex,ifluatex}
\ifnum 0\ifxetex 1\fi\ifluatex 1\fi=0 % if pdftex
  \usepackage[T1]{fontenc}
  \usepackage[utf8]{inputenc}
  \usepackage{textcomp} % provide euro and other symbols
\else % if luatex or xetex
  \usepackage{unicode-math}
  \defaultfontfeatures{Scale=MatchLowercase}
  \defaultfontfeatures[\rmfamily]{Ligatures=TeX,Scale=1}
\fi
% Use upquote if available, for straight quotes in verbatim environments
\IfFileExists{upquote.sty}{\usepackage{upquote}}{}
\IfFileExists{microtype.sty}{% use microtype if available
  \usepackage[]{microtype}
  \UseMicrotypeSet[protrusion]{basicmath} % disable protrusion for tt fonts
}{}
\makeatletter
\@ifundefined{KOMAClassName}{% if non-KOMA class
  \IfFileExists{parskip.sty}{%
    \usepackage{parskip}
  }{% else
    \setlength{\parindent}{0pt}
    \setlength{\parskip}{6pt plus 2pt minus 1pt}}
}{% if KOMA class
  \KOMAoptions{parskip=half}}
\makeatother
\usepackage{xcolor}
\IfFileExists{xurl.sty}{\usepackage{xurl}}{} % add URL line breaks if available
\IfFileExists{bookmark.sty}{\usepackage{bookmark}}{\usepackage{hyperref}}
\hypersetup{
  pdftitle={Exo4 module 2},
  pdfauthor={Marc},
  hidelinks,
  pdfcreator={LaTeX via pandoc}}
\urlstyle{same} % disable monospaced font for URLs
\usepackage[margin=1in]{geometry}
\usepackage{color}
\usepackage{fancyvrb}
\newcommand{\VerbBar}{|}
\newcommand{\VERB}{\Verb[commandchars=\\\{\}]}
\DefineVerbatimEnvironment{Highlighting}{Verbatim}{commandchars=\\\{\}}
% Add ',fontsize=\small' for more characters per line
\usepackage{framed}
\definecolor{shadecolor}{RGB}{248,248,248}
\newenvironment{Shaded}{\begin{snugshade}}{\end{snugshade}}
\newcommand{\AlertTok}[1]{\textcolor[rgb]{0.94,0.16,0.16}{#1}}
\newcommand{\AnnotationTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{\textbf{\textit{#1}}}}
\newcommand{\AttributeTok}[1]{\textcolor[rgb]{0.77,0.63,0.00}{#1}}
\newcommand{\BaseNTok}[1]{\textcolor[rgb]{0.00,0.00,0.81}{#1}}
\newcommand{\BuiltInTok}[1]{#1}
\newcommand{\CharTok}[1]{\textcolor[rgb]{0.31,0.60,0.02}{#1}}
\newcommand{\CommentTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{\textit{#1}}}
\newcommand{\CommentVarTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{\textbf{\textit{#1}}}}
\newcommand{\ConstantTok}[1]{\textcolor[rgb]{0.00,0.00,0.00}{#1}}
\newcommand{\ControlFlowTok}[1]{\textcolor[rgb]{0.13,0.29,0.53}{\textbf{#1}}}
\newcommand{\DataTypeTok}[1]{\textcolor[rgb]{0.13,0.29,0.53}{#1}}
\newcommand{\DecValTok}[1]{\textcolor[rgb]{0.00,0.00,0.81}{#1}}
\newcommand{\DocumentationTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{\textbf{\textit{#1}}}}
\newcommand{\ErrorTok}[1]{\textcolor[rgb]{0.64,0.00,0.00}{\textbf{#1}}}
\newcommand{\ExtensionTok}[1]{#1}
\newcommand{\FloatTok}[1]{\textcolor[rgb]{0.00,0.00,0.81}{#1}}
\newcommand{\FunctionTok}[1]{\textcolor[rgb]{0.00,0.00,0.00}{#1}}
\newcommand{\ImportTok}[1]{#1}
\newcommand{\InformationTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{\textbf{\textit{#1}}}}
\newcommand{\KeywordTok}[1]{\textcolor[rgb]{0.13,0.29,0.53}{\textbf{#1}}}
\newcommand{\NormalTok}[1]{#1}
\newcommand{\OperatorTok}[1]{\textcolor[rgb]{0.81,0.36,0.00}{\textbf{#1}}}
\newcommand{\OtherTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{#1}}
\newcommand{\PreprocessorTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{\textit{#1}}}
\newcommand{\RegionMarkerTok}[1]{#1}
\newcommand{\SpecialCharTok}[1]{\textcolor[rgb]{0.00,0.00,0.00}{#1}}
\newcommand{\SpecialStringTok}[1]{\textcolor[rgb]{0.31,0.60,0.02}{#1}}
\newcommand{\StringTok}[1]{\textcolor[rgb]{0.31,0.60,0.02}{#1}}
\newcommand{\VariableTok}[1]{\textcolor[rgb]{0.00,0.00,0.00}{#1}}
\newcommand{\VerbatimStringTok}[1]{\textcolor[rgb]{0.31,0.60,0.02}{#1}}
\newcommand{\WarningTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{\textbf{\textit{#1}}}}
\usepackage{graphicx}
\makeatletter
\def\maxwidth{\ifdim\Gin@nat@width>\linewidth\linewidth\else\Gin@nat@width\fi}
\def\maxheight{\ifdim\Gin@nat@height>\textheight\textheight\else\Gin@nat@height\fi}
\makeatother
% Scale images if necessary, so that they will not overflow the page
% margins by default, and it is still possible to overwrite the defaults
% using explicit options in \includegraphics[width, height, ...]{}
\setkeys{Gin}{width=\maxwidth,height=\maxheight,keepaspectratio}
% Set default figure placement to htbp
\makeatletter
\def\fps@figure{htbp}
\makeatother
\setlength{\emergencystretch}{3em} % prevent overfull lines
\providecommand{\tightlist}{%
  \setlength{\itemsep}{0pt}\setlength{\parskip}{0pt}}
\setcounter{secnumdepth}{-\maxdimen} % remove section numbering

\title{Exo4 module 2}
\author{Marc}
\date{07/04/2020}

\begin{document}
\maketitle

\hypertarget{luxe9tude}{%
\subsection{L'étude}\label{luxe9tude}}

Cette étude consiste à évaluer mon usage du téléphone depuis le 25
février 2020 pour établir un lien entre la mise en place du confinement
le 17 mars 2020 et mon usage téléphonique.

\hypertarget{le-fichier-de-donnuxe9es}{%
\subsection{Le fichier de données}\label{le-fichier-de-donnuxe9es}}

Le fichier de données ci-après est une table représentant différents
paramètres chaque jour depuis le 25/02/2020 :\\
- Le nombre d'appels émis : Appels\_emis\\
- Le nombre d'appels reçus : Appels\_recus (Comprends aussi les appels
manqués)\\
- La durée totale des appels de la journée en seconde : Duree\_appels\\
- Le nombre de messages reçus : Messages\_recus\\
- Le nombre de messages envoyés : Messages\_envoyes

Le fichier peut être importé comme ceci :

\begin{Shaded}
\begin{Highlighting}[]
\NormalTok{df\textless{}{-}}\KeywordTok{read.csv}\NormalTok{(}\StringTok{"C:/Users/Marc/Desktop/MOOC/mooc{-}rr/module2/exo4/Book1.csv"}\NormalTok{, }\DataTypeTok{sep =} \StringTok{";"}\NormalTok{)}
\KeywordTok{head}\NormalTok{(df)}
\end{Highlighting}
\end{Shaded}

\begin{verbatim}
##      ï..Date Appels_emis Appels_recus Duree_appel Messages_recus
## 1 25/02/2020           0            0           0              6
## 2 26/02/2020           1            1           5              3
## 3 27/02/2020           0            0           0              3
## 4 28/02/2020           0            0           0              0
## 5 29/02/2020           3            1        3470              1
## 6 01/03/2020           1            1         141             15
##   Messages_envoyes
## 1                4
## 2                4
## 3                2
## 4                0
## 5                0
## 6                7
\end{verbatim}

\hypertarget{lanalyse-de-lusage-tuxe9luxe9phonique}{%
\subsection{L'analyse de l'usage
téléphonique}\label{lanalyse-de-lusage-tuxe9luxe9phonique}}

Tout d'abord on peut plotter les différents paramètres au cours du temps
pour se donner un aperçu de mon usage :

\begin{enumerate}
\def\labelenumi{\arabic{enumi}.}
\tightlist
\item
  Les appels émis
\end{enumerate}

\begin{Shaded}
\begin{Highlighting}[]
\KeywordTok{barplot}\NormalTok{(df}\OperatorTok{$}\NormalTok{Appels\_emis, }\DataTypeTok{names.arg =}\NormalTok{ df}\OperatorTok{$}\NormalTok{ï..Date)}
\end{Highlighting}
\end{Shaded}

\includegraphics{Calcul_téléphone_files/figure-latex/unnamed-chunk-2-1.pdf}

Les dates sont mal positionnées mais c'est pas grave. Il semble que j'ai
beaucoup appelé autour de la date du 17 mars.

\begin{enumerate}
\def\labelenumi{\arabic{enumi}.}
\setcounter{enumi}{1}
\tightlist
\item
  Appels reçus
\end{enumerate}

\begin{Shaded}
\begin{Highlighting}[]
\KeywordTok{barplot}\NormalTok{(df}\OperatorTok{$}\NormalTok{Appels\_recus, }\DataTypeTok{names.arg =}\NormalTok{ df}\OperatorTok{$}\NormalTok{ï..Date)}
\end{Highlighting}
\end{Shaded}

\includegraphics{Calcul_téléphone_files/figure-latex/unnamed-chunk-3-1.pdf}

Il semble que j'ai reçu beaucoup d'appels la veille du 17 mars puis que
j'ai reçu + d'appels en général après cette période qu'avant.

\begin{enumerate}
\def\labelenumi{\arabic{enumi}.}
\setcounter{enumi}{2}
\tightlist
\item
  Durée appel
\end{enumerate}

\begin{Shaded}
\begin{Highlighting}[]
\KeywordTok{barplot}\NormalTok{(df}\OperatorTok{$}\NormalTok{Duree\_appel, }\DataTypeTok{names.arg =}\NormalTok{ df}\OperatorTok{$}\NormalTok{ï..Date)}
\end{Highlighting}
\end{Shaded}

\includegraphics{Calcul_téléphone_files/figure-latex/unnamed-chunk-4-1.pdf}

Là c'est très voyant. J'ai passé beaucoup de temps au téléphone après le
16 mars comparé à avant (sauf 2 fois).

\begin{enumerate}
\def\labelenumi{\arabic{enumi}.}
\setcounter{enumi}{3}
\tightlist
\item
  Messages reçus
\end{enumerate}

\begin{Shaded}
\begin{Highlighting}[]
\KeywordTok{barplot}\NormalTok{(df}\OperatorTok{$}\NormalTok{Messages\_recus, }\DataTypeTok{names.arg =}\NormalTok{ df}\OperatorTok{$}\NormalTok{ï..Date)}
\end{Highlighting}
\end{Shaded}

\includegraphics{Calcul_téléphone_files/figure-latex/unnamed-chunk-5-1.pdf}

\begin{enumerate}
\def\labelenumi{\arabic{enumi}.}
\setcounter{enumi}{4}
\tightlist
\item
  Messages envoyés
\end{enumerate}

\begin{Shaded}
\begin{Highlighting}[]
\KeywordTok{barplot}\NormalTok{(df}\OperatorTok{$}\NormalTok{Messages\_envoyes, }\DataTypeTok{names.arg =}\NormalTok{ df}\OperatorTok{$}\NormalTok{ï..Date)}
\end{Highlighting}
\end{Shaded}

\includegraphics{Calcul_téléphone_files/figure-latex/unnamed-chunk-6-1.pdf}

Pour les messages, la tendance est inverse aux appels : je reçois et
envoie - de sms depuis le 17 mars comparé à avant.\\
J'ai eput être changé mon usage de l'un à l'autre.\\
Sauf autour du 16-17 mars où j'ai beaucoup communiqué.

\hypertarget{repruxe9sentation-des-moyennes-avant-et-apruxe8s-le-17-mars}{%
\subsubsection{Représentation des moyennes avant et après le 17
mars}\label{repruxe9sentation-des-moyennes-avant-et-apruxe8s-le-17-mars}}

Je vais rajouté une colonne pour indiqué avant ou après le 17 mars.

\begin{Shaded}
\begin{Highlighting}[]
\NormalTok{add\textless{}{-}}\KeywordTok{c}\NormalTok{(}\KeywordTok{rep}\NormalTok{(}\StringTok{"avant"}\NormalTok{,}\DecValTok{21}\NormalTok{), }\KeywordTok{rep}\NormalTok{(}\StringTok{"après"}\NormalTok{,}\DecValTok{21}\NormalTok{))}
\NormalTok{df}\OperatorTok{$}\NormalTok{add\textless{}{-}add}
\end{Highlighting}
\end{Shaded}

Oui je sais c'est vraiment nul mais en gros je sais qu'il y a 42 lignes
dans mon tableau (je peux le vérifier avec
\texttt{length(df\$Appels\_emis)} par exemple) et que le 17 mars est la
22ème ligne.\\
J'ai donc ajouté 21 fois ``avant'' et 21 fois ``après'' sur une colonne
dans mon data frame df.

Maintenant on va pouvoir calculer les moyennes des paramètres avant et
après (inclus) le 17 mars 2020.

\begin{Shaded}
\begin{Highlighting}[]
\NormalTok{m\_appels\_emis\textless{}{-}}\KeywordTok{c}\NormalTok{(}\KeywordTok{mean}\NormalTok{(df}\OperatorTok{$}\NormalTok{Appels\_emis[df}\OperatorTok{$}\NormalTok{add}\OperatorTok{==}\StringTok{"avant"}\NormalTok{]), }\KeywordTok{mean}\NormalTok{(df}\OperatorTok{$}\NormalTok{Appels\_emis[df}\OperatorTok{$}\NormalTok{add}\OperatorTok{==}\StringTok{"après"}\NormalTok{]))}
\NormalTok{m\_appels\_recus\textless{}{-}}\KeywordTok{c}\NormalTok{(}\KeywordTok{mean}\NormalTok{(df}\OperatorTok{$}\NormalTok{Appels\_recus[df}\OperatorTok{$}\NormalTok{add}\OperatorTok{==}\StringTok{"avant"}\NormalTok{]), }\KeywordTok{mean}\NormalTok{(df}\OperatorTok{$}\NormalTok{Appels\_recus[df}\OperatorTok{$}\NormalTok{add}\OperatorTok{==}\StringTok{"après"}\NormalTok{]))}
\NormalTok{m\_duree\_appel\textless{}{-}}\KeywordTok{c}\NormalTok{(}\KeywordTok{mean}\NormalTok{(df}\OperatorTok{$}\NormalTok{Duree\_appel[df}\OperatorTok{$}\NormalTok{add}\OperatorTok{==}\StringTok{"avant"}\NormalTok{]), }\KeywordTok{mean}\NormalTok{(df}\OperatorTok{$}\NormalTok{Duree\_appel[df}\OperatorTok{$}\NormalTok{add}\OperatorTok{==}\StringTok{"après"}\NormalTok{]))}
\NormalTok{m\_messages\_recus\textless{}{-}}\KeywordTok{c}\NormalTok{(}\KeywordTok{mean}\NormalTok{(df}\OperatorTok{$}\NormalTok{Messages\_recus[df}\OperatorTok{$}\NormalTok{add}\OperatorTok{==}\StringTok{"avant"}\NormalTok{]), }\KeywordTok{mean}\NormalTok{(df}\OperatorTok{$}\NormalTok{Messages\_recus[df}\OperatorTok{$}\NormalTok{add}\OperatorTok{==}\StringTok{"après"}\NormalTok{]))}
\NormalTok{m\_messages\_envoyes\textless{}{-}}\KeywordTok{c}\NormalTok{(}\KeywordTok{mean}\NormalTok{(df}\OperatorTok{$}\NormalTok{Messages\_envoyes[df}\OperatorTok{$}\NormalTok{add}\OperatorTok{==}\StringTok{"avant"}\NormalTok{]), }\KeywordTok{mean}\NormalTok{(df}\OperatorTok{$}\NormalTok{Messages\_envoyes[df}\OperatorTok{$}\NormalTok{add}\OperatorTok{==}\StringTok{"après"}\NormalTok{]))}
\NormalTok{m\_appels\_emis}
\end{Highlighting}
\end{Shaded}

\begin{verbatim}
## [1] 1.142857 1.523810
\end{verbatim}

\begin{Shaded}
\begin{Highlighting}[]
\NormalTok{m\_appels\_recus}
\end{Highlighting}
\end{Shaded}

\begin{verbatim}
## [1] 0.8095238 1.1904762
\end{verbatim}

\begin{Shaded}
\begin{Highlighting}[]
\NormalTok{m\_messages\_recus}
\end{Highlighting}
\end{Shaded}

\begin{verbatim}
## [1] 6.285714 2.761905
\end{verbatim}

\begin{Shaded}
\begin{Highlighting}[]
\NormalTok{m\_messages\_envoyes}
\end{Highlighting}
\end{Shaded}

\begin{verbatim}
## [1] 5.285714 1.523810
\end{verbatim}

Et les écarts-types :

\begin{Shaded}
\begin{Highlighting}[]
\NormalTok{sd\_appels\_emis\textless{}{-}}\KeywordTok{c}\NormalTok{(}\KeywordTok{sd}\NormalTok{(df}\OperatorTok{$}\NormalTok{Appels\_emis[df}\OperatorTok{$}\NormalTok{add}\OperatorTok{==}\StringTok{"avant"}\NormalTok{]), }\KeywordTok{sd}\NormalTok{(df}\OperatorTok{$}\NormalTok{Appels\_emis[df}\OperatorTok{$}\NormalTok{add}\OperatorTok{==}\StringTok{"après"}\NormalTok{]))}
\NormalTok{sd\_appels\_recus\textless{}{-}}\KeywordTok{c}\NormalTok{(}\KeywordTok{sd}\NormalTok{(df}\OperatorTok{$}\NormalTok{Appels\_recus[df}\OperatorTok{$}\NormalTok{add}\OperatorTok{==}\StringTok{"avant"}\NormalTok{]), }\KeywordTok{sd}\NormalTok{(df}\OperatorTok{$}\NormalTok{Appels\_recus[df}\OperatorTok{$}\NormalTok{add}\OperatorTok{==}\StringTok{"après"}\NormalTok{]))}
\NormalTok{sd\_duree\_appel\textless{}{-}}\KeywordTok{c}\NormalTok{(}\KeywordTok{sd}\NormalTok{(df}\OperatorTok{$}\NormalTok{Duree\_appel[df}\OperatorTok{$}\NormalTok{add}\OperatorTok{==}\StringTok{"avant"}\NormalTok{]), }\KeywordTok{sd}\NormalTok{(df}\OperatorTok{$}\NormalTok{Duree\_appel[df}\OperatorTok{$}\NormalTok{add}\OperatorTok{==}\StringTok{"après"}\NormalTok{]))}
\NormalTok{sd\_messages\_recus\textless{}{-}}\KeywordTok{c}\NormalTok{(}\KeywordTok{sd}\NormalTok{(df}\OperatorTok{$}\NormalTok{Messages\_recus[df}\OperatorTok{$}\NormalTok{add}\OperatorTok{==}\StringTok{"avant"}\NormalTok{]), }\KeywordTok{sd}\NormalTok{(df}\OperatorTok{$}\NormalTok{Messages\_recus[df}\OperatorTok{$}\NormalTok{add}\OperatorTok{==}\StringTok{"après"}\NormalTok{]))}
\NormalTok{sd\_messages\_envoyes\textless{}{-}}\KeywordTok{c}\NormalTok{(}\KeywordTok{sd}\NormalTok{(df}\OperatorTok{$}\NormalTok{Messages\_envoyes[df}\OperatorTok{$}\NormalTok{add}\OperatorTok{==}\StringTok{"avant"}\NormalTok{]), }\KeywordTok{sd}\NormalTok{(df}\OperatorTok{$}\NormalTok{Messages\_envoyes[df}\OperatorTok{$}\NormalTok{add}\OperatorTok{==}\StringTok{"après"}\NormalTok{]))}
\end{Highlighting}
\end{Shaded}

Maintenant on va pouvoir plotter les moyennes de tous les paramètres
avant et après (inclus) le 17 mars 2020.\\
Le mieux c'est d'utiliser ggplot.

\begin{Shaded}
\begin{Highlighting}[]
\CommentTok{\#install.packages("ggplot2")}
\KeywordTok{library}\NormalTok{(ggplot2)}
\NormalTok{a\textless{}{-}}\KeywordTok{data.frame}\NormalTok{(m\_appels\_emis, sd\_appels\_emis, }\KeywordTok{c}\NormalTok{(}\StringTok{"aa"}\NormalTok{, }\StringTok{"ap"}\NormalTok{))}
\KeywordTok{ggplot}\NormalTok{(a, }\KeywordTok{aes}\NormalTok{(}\DataTypeTok{x =}\NormalTok{ a}\OperatorTok{$}\NormalTok{c..aa....ap.., }\DataTypeTok{y =}\NormalTok{ m\_appels\_emis))}\OperatorTok{+}
\StringTok{    }\KeywordTok{geom\_bar}\NormalTok{(}\DataTypeTok{stat =} \StringTok{"identity"}\NormalTok{)}\OperatorTok{+}
\StringTok{    }\KeywordTok{geom\_errorbar}\NormalTok{(}\DataTypeTok{ymin =}\NormalTok{ a}\OperatorTok{$}\NormalTok{m\_appels\_emis}\OperatorTok{{-}}\NormalTok{a}\OperatorTok{$}\NormalTok{sd\_appels\_emis, }\DataTypeTok{ymax =}\NormalTok{ a}\OperatorTok{$}\NormalTok{m\_appels\_emis}\OperatorTok{+}\NormalTok{a}\OperatorTok{$}\NormalTok{sd\_appels\_emis)}\OperatorTok{+}\StringTok{ }
\StringTok{    }\KeywordTok{ylim}\NormalTok{(}\OperatorTok{{-}}\DecValTok{1}\NormalTok{,}\DecValTok{4}\NormalTok{)}\OperatorTok{+}
\StringTok{    }\KeywordTok{labs}\NormalTok{(}\DataTypeTok{title=}\StringTok{"Appels émis"}\NormalTok{)}
\end{Highlighting}
\end{Shaded}

\begin{verbatim}
## Warning: Use of `a$c..aa....ap..` is discouraged. Use `c..aa....ap..` instead.

## Warning: Use of `a$c..aa....ap..` is discouraged. Use `c..aa....ap..` instead.
\end{verbatim}

\includegraphics{Calcul_téléphone_files/figure-latex/unnamed-chunk-10-1.pdf}

\begin{Shaded}
\begin{Highlighting}[]
\NormalTok{b\textless{}{-}}\KeywordTok{data.frame}\NormalTok{(m\_appels\_recus, sd\_appels\_recus, }\KeywordTok{c}\NormalTok{(}\StringTok{"aa"}\NormalTok{, }\StringTok{"ap"}\NormalTok{))}
\KeywordTok{ggplot}\NormalTok{(b, }\KeywordTok{aes}\NormalTok{(}\DataTypeTok{x =}\NormalTok{ b}\OperatorTok{$}\NormalTok{c..aa....ap.., }\DataTypeTok{y =}\NormalTok{ b}\OperatorTok{$}\NormalTok{m\_appels\_recus))}\OperatorTok{+}
\StringTok{    }\KeywordTok{geom\_bar}\NormalTok{(}\DataTypeTok{stat =} \StringTok{"identity"}\NormalTok{)}\OperatorTok{+}
\StringTok{    }\KeywordTok{geom\_errorbar}\NormalTok{(}\DataTypeTok{ymin =}\NormalTok{ b}\OperatorTok{$}\NormalTok{m\_appels\_recus}\OperatorTok{{-}}\NormalTok{b}\OperatorTok{$}\NormalTok{sd\_appels\_recus, }\DataTypeTok{ymax =}\NormalTok{ b}\OperatorTok{$}\NormalTok{m\_appels\_recus}\OperatorTok{+}\NormalTok{b}\OperatorTok{$}\NormalTok{sd\_appels\_recus)}\OperatorTok{+}\StringTok{ }
\StringTok{    }\KeywordTok{ylim}\NormalTok{(}\OperatorTok{{-}}\DecValTok{1}\NormalTok{,}\DecValTok{3}\NormalTok{)}\OperatorTok{+}
\StringTok{    }\KeywordTok{labs}\NormalTok{(}\DataTypeTok{title=}\StringTok{"Appels recus"}\NormalTok{)}
\end{Highlighting}
\end{Shaded}

\begin{verbatim}
## Warning: Use of `b$c..aa....ap..` is discouraged. Use `c..aa....ap..` instead.
\end{verbatim}

\begin{verbatim}
## Warning: Use of `b$m_appels_recus` is discouraged. Use `m_appels_recus` instead.
\end{verbatim}

\begin{verbatim}
## Warning: Use of `b$c..aa....ap..` is discouraged. Use `c..aa....ap..` instead.
\end{verbatim}

\begin{verbatim}
## Warning: Use of `b$m_appels_recus` is discouraged. Use `m_appels_recus` instead.
\end{verbatim}

\includegraphics{Calcul_téléphone_files/figure-latex/unnamed-chunk-11-1.pdf}

\begin{Shaded}
\begin{Highlighting}[]
\NormalTok{c\textless{}{-}}\KeywordTok{data.frame}\NormalTok{(m\_duree\_appel, sd\_duree\_appel, }\KeywordTok{c}\NormalTok{(}\StringTok{"aa"}\NormalTok{, }\StringTok{"ap"}\NormalTok{))}
\KeywordTok{ggplot}\NormalTok{(c, }\KeywordTok{aes}\NormalTok{(}\DataTypeTok{x =}\NormalTok{ c}\OperatorTok{$}\NormalTok{c..aa....ap.., }\DataTypeTok{y =}\NormalTok{ c}\OperatorTok{$}\NormalTok{m\_duree\_appel))}\OperatorTok{+}
\StringTok{    }\KeywordTok{geom\_bar}\NormalTok{(}\DataTypeTok{stat =} \StringTok{"identity"}\NormalTok{)}\OperatorTok{+}
\StringTok{    }\KeywordTok{geom\_errorbar}\NormalTok{(}\DataTypeTok{ymin =}\NormalTok{ c}\OperatorTok{$}\NormalTok{m\_duree\_appel}\OperatorTok{{-}}\NormalTok{c}\OperatorTok{$}\NormalTok{sd\_duree\_appel, }\DataTypeTok{ymax =}\NormalTok{ c}\OperatorTok{$}\NormalTok{m\_duree\_appel}\OperatorTok{+}\NormalTok{c}\OperatorTok{$}\NormalTok{sd\_duree\_appel)}\OperatorTok{+}\StringTok{ }
\StringTok{    }\KeywordTok{ylim}\NormalTok{(}\OperatorTok{{-}}\DecValTok{500}\NormalTok{,}\DecValTok{2000}\NormalTok{)}\OperatorTok{+}
\StringTok{    }\KeywordTok{labs}\NormalTok{(}\DataTypeTok{title=}\StringTok{"Duree appel"}\NormalTok{)}
\end{Highlighting}
\end{Shaded}

\begin{verbatim}
## Warning: Use of `c$c..aa....ap..` is discouraged. Use `c..aa....ap..` instead.
\end{verbatim}

\begin{verbatim}
## Warning: Use of `c$m_duree_appel` is discouraged. Use `m_duree_appel` instead.
\end{verbatim}

\begin{verbatim}
## Warning: Use of `c$c..aa....ap..` is discouraged. Use `c..aa....ap..` instead.
\end{verbatim}

\begin{verbatim}
## Warning: Use of `c$m_duree_appel` is discouraged. Use `m_duree_appel` instead.
\end{verbatim}

\includegraphics{Calcul_téléphone_files/figure-latex/unnamed-chunk-12-1.pdf}

\begin{Shaded}
\begin{Highlighting}[]
\NormalTok{d\textless{}{-}}\KeywordTok{data.frame}\NormalTok{(m\_messages\_envoyes, sd\_messages\_envoyes, }\KeywordTok{c}\NormalTok{(}\StringTok{"aa"}\NormalTok{, }\StringTok{"ap"}\NormalTok{))}
\KeywordTok{ggplot}\NormalTok{(d, }\KeywordTok{aes}\NormalTok{(}\DataTypeTok{x =}\NormalTok{ d}\OperatorTok{$}\NormalTok{c..aa....ap.., }\DataTypeTok{y =}\NormalTok{ d}\OperatorTok{$}\NormalTok{m\_messages\_envoyes))}\OperatorTok{+}
\StringTok{    }\KeywordTok{geom\_bar}\NormalTok{(}\DataTypeTok{stat =} \StringTok{"identity"}\NormalTok{)}\OperatorTok{+}
\StringTok{    }\KeywordTok{geom\_errorbar}\NormalTok{(}\DataTypeTok{ymin =}\NormalTok{ d}\OperatorTok{$}\NormalTok{m\_messages\_envoyes}\OperatorTok{{-}}\NormalTok{d}\OperatorTok{$}\NormalTok{sd\_messages\_envoyes, }\DataTypeTok{ymax =}\NormalTok{ d}\OperatorTok{$}\NormalTok{m\_messages\_envoyes}\OperatorTok{+}\NormalTok{d}\OperatorTok{$}\NormalTok{sd\_messages\_envoyes)}\OperatorTok{+}\StringTok{ }
\StringTok{    }\KeywordTok{ylim}\NormalTok{(}\DecValTok{0}\NormalTok{,}\DecValTok{12}\NormalTok{)}\OperatorTok{+}
\StringTok{    }\KeywordTok{labs}\NormalTok{(}\DataTypeTok{title=}\StringTok{"Messages envoyes"}\NormalTok{)}
\end{Highlighting}
\end{Shaded}

\begin{verbatim}
## Warning: Use of `d$c..aa....ap..` is discouraged. Use `c..aa....ap..` instead.
\end{verbatim}

\begin{verbatim}
## Warning: Use of `d$m_messages_envoyes` is discouraged. Use `m_messages_envoyes`
## instead.
\end{verbatim}

\begin{verbatim}
## Warning: Use of `d$c..aa....ap..` is discouraged. Use `c..aa....ap..` instead.
\end{verbatim}

\begin{verbatim}
## Warning: Use of `d$m_messages_envoyes` is discouraged. Use `m_messages_envoyes`
## instead.
\end{verbatim}

\includegraphics{Calcul_téléphone_files/figure-latex/unnamed-chunk-13-1.pdf}

\begin{Shaded}
\begin{Highlighting}[]
\NormalTok{e\textless{}{-}}\KeywordTok{data.frame}\NormalTok{(m\_messages\_recus, sd\_messages\_recus, }\KeywordTok{c}\NormalTok{(}\StringTok{"aa"}\NormalTok{, }\StringTok{"ap"}\NormalTok{))}
\KeywordTok{ggplot}\NormalTok{(e, }\KeywordTok{aes}\NormalTok{(}\DataTypeTok{x =}\NormalTok{ e}\OperatorTok{$}\NormalTok{c..aa....ap.., }\DataTypeTok{y =}\NormalTok{ e}\OperatorTok{$}\NormalTok{m\_messages\_recus))}\OperatorTok{+}
\StringTok{    }\KeywordTok{geom\_bar}\NormalTok{(}\DataTypeTok{stat =} \StringTok{"identity"}\NormalTok{)}\OperatorTok{+}
\StringTok{    }\KeywordTok{geom\_errorbar}\NormalTok{(}\DataTypeTok{ymin =}\NormalTok{ e}\OperatorTok{$}\NormalTok{m\_messages\_recus}\OperatorTok{{-}}\NormalTok{e}\OperatorTok{$}\NormalTok{sd\_messages\_recus, }\DataTypeTok{ymax =}\NormalTok{ e}\OperatorTok{$}\NormalTok{m\_messages\_recus}\OperatorTok{+}\NormalTok{e}\OperatorTok{$}\NormalTok{sd\_messages\_recus)}\OperatorTok{+}\StringTok{ }
\StringTok{    }\KeywordTok{ylim}\NormalTok{(}\OperatorTok{{-}}\DecValTok{2}\NormalTok{,}\DecValTok{12}\NormalTok{)}\OperatorTok{+}
\StringTok{    }\KeywordTok{labs}\NormalTok{(}\DataTypeTok{title=}\StringTok{"Messages recus"}\NormalTok{)}
\end{Highlighting}
\end{Shaded}

\begin{verbatim}
## Warning: Use of `e$c..aa....ap..` is discouraged. Use `c..aa....ap..` instead.
\end{verbatim}

\begin{verbatim}
## Warning: Use of `e$m_messages_recus` is discouraged. Use `m_messages_recus`
## instead.
\end{verbatim}

\begin{verbatim}
## Warning: Use of `e$c..aa....ap..` is discouraged. Use `c..aa....ap..` instead.
\end{verbatim}

\begin{verbatim}
## Warning: Use of `e$m_messages_recus` is discouraged. Use `m_messages_recus`
## instead.
\end{verbatim}

\includegraphics{Calcul_téléphone_files/figure-latex/unnamed-chunk-14-1.pdf}

\textbf{Bilan : On voit des augmentations dans les appels et une
diminution dans les messages mais les écarts types sont énormes}

A mon avis, rien n'est significatif mais on peut s'entrainer sur un
cas.\\
Comme il n'y a que 21 valeurs dans chaque groupe, je ne peux pas
appliquer le théorème central limite. Je vais donc vérifier la
distribution normale de chaque groupe ainsi que l'égalité des variances
pour voir quel test statistique appliqué.\\
Prenons comme exemple la durée de l'appel.

\begin{Shaded}
\begin{Highlighting}[]
\KeywordTok{shapiro.test}\NormalTok{(df}\OperatorTok{$}\NormalTok{Duree\_appel[df}\OperatorTok{$}\NormalTok{add}\OperatorTok{==}\StringTok{"avant"}\NormalTok{])}
\end{Highlighting}
\end{Shaded}

\begin{verbatim}
## 
##  Shapiro-Wilk normality test
## 
## data:  df$Duree_appel[df$add == "avant"]
## W = 0.53087, p-value = 3.968e-07
\end{verbatim}

\begin{Shaded}
\begin{Highlighting}[]
\KeywordTok{shapiro.test}\NormalTok{(df}\OperatorTok{$}\NormalTok{Duree\_appel[df}\OperatorTok{$}\NormalTok{add}\OperatorTok{==}\StringTok{"après"}\NormalTok{])}
\end{Highlighting}
\end{Shaded}

\begin{verbatim}
## 
##  Shapiro-Wilk normality test
## 
## data:  df$Duree_appel[df$add == "après"]
## W = 0.88753, p-value = 0.0202
\end{verbatim}

Les tests de Shapiro-Wilk sont significatifs donc les distributions ne
sont pas normales.\\
Utilisation de tests non paramétriques type Mann-Whitney :

\begin{Shaded}
\begin{Highlighting}[]
\KeywordTok{wilcox.test}\NormalTok{(df}\OperatorTok{$}\NormalTok{Duree\_appel[df}\OperatorTok{$}\NormalTok{add}\OperatorTok{==}\StringTok{"avant"}\NormalTok{],df}\OperatorTok{$}\NormalTok{Duree\_appel[df}\OperatorTok{$}\NormalTok{add}\OperatorTok{==}\StringTok{"après"}\NormalTok{])}
\end{Highlighting}
\end{Shaded}

\begin{verbatim}
## Warning in wilcox.test.default(df$Duree_appel[df$add == "avant"],
## df$Duree_appel[df$add == : cannot compute exact p-value with ties
\end{verbatim}

\begin{verbatim}
## 
##  Wilcoxon rank sum test with continuity correction
## 
## data:  df$Duree_appel[df$add == "avant"] and df$Duree_appel[df$add == "après"]
## W = 140.5, p-value = 0.03965
## alternative hypothesis: true location shift is not equal to 0
\end{verbatim}

Ah ben en fait la durée des appels a significativement augmentée après
le 17 mars 2020. Je ne suis pas super fort en statistiques donc j'espère
que c'est correct. Aussi, 21 échantillons par groupe c'est pas mal pour
un test non paramétrique.

Du coup on va essayer de mettre une étoile sur le plot (ce qui n'est pas
compris dans les fonctions ggplot).\\
Pour cela on va donc tester le code d'un ami disponible sur
\href{https://github.com/EvenStar69/significativity.bar}{Github}.

\begin{Shaded}
\begin{Highlighting}[]
\CommentTok{\#install.packages("devtools")}
\KeywordTok{library}\NormalTok{(devtools)}
\end{Highlighting}
\end{Shaded}

\begin{verbatim}
## Loading required package: usethis
\end{verbatim}

\begin{Shaded}
\begin{Highlighting}[]
\CommentTok{\#Besoin de Rtools 3.5}
\CommentTok{\#install\_github("EvenStar69/significativity.bar/significativity.bar")}
\KeywordTok{library}\NormalTok{(significativity.bar)}
\end{Highlighting}
\end{Shaded}

Bon j'ai dû un peu changer sa fonction parce qu'elle n'est plus
compatible avec ggplot 3.3.\\
J'ai changé la manière de retrouver les coordonnées y : The position of
ymax in ggplot\_build(plot)\$data{[}{[}1{]}{]} changed from column 6 to
7.\\
Et j'ai changé la manière de retrouver l'échalle en y : panel\_ranges in
ggplot\_build(plot)\$layout does not exist anymore \ldots{} use
panel\_scale\_y instead.\\
J'ai aussi dû mettre à jour R vers la version 3.6.3.\\
Voici le code modifié de sa fonction :

\begin{Shaded}
\begin{Highlighting}[]
\NormalTok{significativity\_bar \textless{}{-}}\StringTok{ }\ControlFlowTok{function}\NormalTok{(plot, groups, }\DataTypeTok{text =} \StringTok{"*"}\NormalTok{, }\DataTypeTok{text\_height =} \FloatTok{0.0275}\NormalTok{, }\DataTypeTok{size\_bar =} \DecValTok{1}\NormalTok{, }\DataTypeTok{color\_bar =} \StringTok{"black"}\NormalTok{, }\DataTypeTok{size\_text =} \DecValTok{8}\NormalTok{, }\DataTypeTok{color\_text =} \StringTok{"black"}\NormalTok{, }\DataTypeTok{font\_face =} \DecValTok{1}\NormalTok{, }\DataTypeTok{font\_style =} \StringTok{"serif"}\NormalTok{, }\DataTypeTok{line\_type =} \StringTok{"solid"}\NormalTok{)\{}
  
  
  
  \ControlFlowTok{if}\NormalTok{ (}\OperatorTok{!}\KeywordTok{require}\NormalTok{(}\StringTok{"ggplot2"}\NormalTok{, }\DataTypeTok{character.only=}\NormalTok{T, }\DataTypeTok{quietly=}\NormalTok{T))\{ }\CommentTok{\# use library ggplot}
    
    \KeywordTok{install.packages}\NormalTok{(}\StringTok{"ggplot2"}\NormalTok{)}
    
    \KeywordTok{library}\NormalTok{(ggplot2, }\DataTypeTok{character.only=}\NormalTok{T)}
    
\NormalTok{  \}}
  
  
  
  \ControlFlowTok{if}\NormalTok{ (}\KeywordTok{class}\NormalTok{(plot)[}\DecValTok{1}\NormalTok{] }\OperatorTok{!=}\StringTok{ "gg"}\NormalTok{)\{}
    
    \KeywordTok{stop}\NormalTok{(}\StringTok{"Your input plot is not a ggplot"}\NormalTok{)}
    
\NormalTok{  \}}
  
  \ControlFlowTok{if}\NormalTok{ (}\KeywordTok{length}\NormalTok{(groups) }\OperatorTok{!=}\StringTok{ }\DecValTok{2}\NormalTok{)\{}
    
    \KeywordTok{stop}\NormalTok{(}\StringTok{"Please select only 2 groups between which you want the error bar"}\NormalTok{)}
    
\NormalTok{  \}}
  
  \ControlFlowTok{if}\NormalTok{ (}\OperatorTok{!}\KeywordTok{is.vector}\NormalTok{(groups))\{}
    
    \KeywordTok{stop}\NormalTok{(}\StringTok{"Please input your 2 selected groups in a vector"}\NormalTok{)}
    
\NormalTok{  \}}
  
  \ControlFlowTok{if}\NormalTok{ (}\OperatorTok{!}\KeywordTok{is.character}\NormalTok{(text)) \{}
    
    \KeywordTok{stop}\NormalTok{(}\StringTok{"Please input the text above the bar as character"}\NormalTok{)}
    
\NormalTok{  \}}
  
  \ControlFlowTok{if}\NormalTok{ (}\OperatorTok{!}\KeywordTok{is.numeric}\NormalTok{(text\_height) }\OperatorTok{|}\StringTok{ }\KeywordTok{length}\NormalTok{(text\_height) }\OperatorTok{\textgreater{}}\StringTok{ }\DecValTok{1}\NormalTok{)\{}
    
    \KeywordTok{stop}\NormalTok{(}\StringTok{"Please input one numeric value for the text height"}\NormalTok{)}
    
\NormalTok{  \}}
  
  \ControlFlowTok{if}\NormalTok{ (}\OperatorTok{!}\KeywordTok{is.numeric}\NormalTok{(size\_bar) }\OperatorTok{|}\StringTok{ }\KeywordTok{length}\NormalTok{(size\_bar) }\OperatorTok{\textgreater{}}\StringTok{ }\DecValTok{1}\NormalTok{)\{}
    
    \KeywordTok{stop}\NormalTok{(}\StringTok{"Please input one numeric value for the bar size"}\NormalTok{)}
    
\NormalTok{  \}}
  
  \ControlFlowTok{if}\NormalTok{ (}\OperatorTok{!}\KeywordTok{is.character}\NormalTok{(color\_bar))\{}
    
    \KeywordTok{stop}\NormalTok{(}\StringTok{"Please input an existing R color, as a character, for the color of the bar"}\NormalTok{)}
    
\NormalTok{  \}}
  
  \ControlFlowTok{if}\NormalTok{ (}\OperatorTok{!}\KeywordTok{is.numeric}\NormalTok{(size\_text) }\OperatorTok{|}\StringTok{ }\KeywordTok{length}\NormalTok{(size\_text) }\OperatorTok{\textgreater{}}\StringTok{ }\DecValTok{1}\NormalTok{)\{}
    
    \KeywordTok{stop}\NormalTok{(}\StringTok{"Please input one numeric value for the text size"}\NormalTok{)}
    
\NormalTok{  \}}
  
  \ControlFlowTok{if}\NormalTok{ (}\OperatorTok{!}\KeywordTok{is.numeric}\NormalTok{(font\_face) }\OperatorTok{|}\StringTok{ }\KeywordTok{length}\NormalTok{(font\_face) }\OperatorTok{\textgreater{}}\StringTok{ }\DecValTok{1}\NormalTok{)\{}
    
    \KeywordTok{stop}\NormalTok{(}\StringTok{"Please input one numeric value for the font face"}\NormalTok{)}
    
\NormalTok{  \}}
  
  \ControlFlowTok{if}\NormalTok{ (}\OperatorTok{!}\KeywordTok{is.character}\NormalTok{(color\_text))\{}
    
    \KeywordTok{stop}\NormalTok{(}\StringTok{"Please input an existing R color, as a character, for the color of the text"}\NormalTok{)}
    
\NormalTok{  \}}
  
  \ControlFlowTok{if}\NormalTok{ (}\OperatorTok{!}\KeywordTok{is.character}\NormalTok{(font\_style))\{}
    
    \KeywordTok{stop}\NormalTok{(}\StringTok{"Please input an existing font family, as a character, for the color of the bar"}\NormalTok{)}
    
\NormalTok{  \}}
  
  \ControlFlowTok{if}\NormalTok{ (}\OperatorTok{!}\KeywordTok{is.character}\NormalTok{(line\_type))\{}
    
    \KeywordTok{stop}\NormalTok{(}\StringTok{"Please input an existing line style, as a character, for the color of the bar"}\NormalTok{)}
    
\NormalTok{  \}}
  
  
  
  \ControlFlowTok{if}\NormalTok{ (text\_height }\OperatorTok{\textgreater{}=}\DecValTok{1}\NormalTok{)\{}
    
    \KeywordTok{warning}\NormalTok{(}\StringTok{"text\_height should be between 0 and 1, default value for * and around 0.04 for text are advised"}\NormalTok{)}
    
\NormalTok{  \}}
  
  
  
  
  
  \ControlFlowTok{if}\NormalTok{ (}\KeywordTok{class}\NormalTok{(}\KeywordTok{as.list.environment}\NormalTok{(plot}\OperatorTok{$}\NormalTok{layers[[}\DecValTok{1}\NormalTok{]])}\OperatorTok{$}\NormalTok{geom)[}\DecValTok{1}\NormalTok{] }\OperatorTok{==}\StringTok{ "GeomPoint"}\NormalTok{)\{ }\CommentTok{\# if the ggplot is a dotplot}
    
\NormalTok{    coords =}\StringTok{ }\KeywordTok{ggplot\_build}\NormalTok{(plot)}\OperatorTok{$}\NormalTok{data[[}\DecValTok{1}\NormalTok{]] }\CommentTok{\# get the coordinates of the points}
    
\NormalTok{    xcoords =}\StringTok{ }\KeywordTok{c}\NormalTok{()}
    
\NormalTok{    ycoords =}\StringTok{ }\KeywordTok{c}\NormalTok{()}
    
    \ControlFlowTok{for}\NormalTok{ (i }\ControlFlowTok{in}\NormalTok{ groups)\{ }\CommentTok{\# get the x coordinates of all coordinates in a vector, for the 2 selected groups}
      
\NormalTok{      xcoord\_temp =}\StringTok{ }\KeywordTok{unique}\NormalTok{(coords}\OperatorTok{$}\NormalTok{x)[i]}
      
\NormalTok{      xcoords =}\StringTok{ }\KeywordTok{append}\NormalTok{(xcoords, xcoord\_temp)}
      
\NormalTok{    \}}
    
    \ControlFlowTok{for}\NormalTok{ (i }\ControlFlowTok{in} \KeywordTok{c}\NormalTok{(}\DecValTok{1}\NormalTok{,}\DecValTok{2}\NormalTok{))\{}
      
\NormalTok{      ycoord\_temp =}\StringTok{ }\KeywordTok{max}\NormalTok{(coords[coords}\OperatorTok{$}\NormalTok{x }\OperatorTok{==}\StringTok{ }\NormalTok{xcoords[i],]}\OperatorTok{$}\NormalTok{y) }\CommentTok{\# get the y coordinate of the upper point of each group}
      
\NormalTok{      ycoords =}\StringTok{ }\KeywordTok{append}\NormalTok{(ycoords, ycoord\_temp)}
      
\NormalTok{    \}}
    
    
    
\NormalTok{    y\_range =}\StringTok{ }\KeywordTok{ggplot\_build}\NormalTok{(plot)}\OperatorTok{$}\NormalTok{layout}\OperatorTok{$}\NormalTok{panel\_scales\_y[[}\DecValTok{1}\NormalTok{]]}\OperatorTok{$}\NormalTok{limits }\CommentTok{\# get the total height of the y scale}
    \CommentTok{\# panel\_ranges in ggplot\_build(plot)$layout does not exist anymore ... use panel\_scale\_y instead}
    
\NormalTok{    y\_sum =}\StringTok{ }\KeywordTok{sum}\NormalTok{(}\KeywordTok{abs}\NormalTok{(y\_range)) }
    
\NormalTok{    y\_scale =}\StringTok{ }\NormalTok{(}\FloatTok{7.5}\OperatorTok{/}\DecValTok{100}\NormalTok{)}\OperatorTok{*}\NormalTok{y\_sum }\CommentTok{\# starting position of the vertical bar (determined \% of the total y scale)}
    
\NormalTok{    bar\_height =}\StringTok{ }\NormalTok{y\_scale }\OperatorTok{+}\StringTok{ }\NormalTok{((}\DecValTok{5}\OperatorTok{/}\DecValTok{100}\NormalTok{)}\OperatorTok{*}\NormalTok{y\_sum) }\CommentTok{\# final position of the vertical bar (determined \% of the total y scale in addition to y\_scale)}
    
    
    
\NormalTok{    ycoord\_top =}\StringTok{ }\KeywordTok{max}\NormalTok{(ycoords) }\CommentTok{\# the bar should take the heighest of the two groups as a reference}
    
\NormalTok{    coord\_bar =}\StringTok{ }\KeywordTok{data.frame}\NormalTok{(}\DataTypeTok{x =} \KeywordTok{c}\NormalTok{(xcoords[}\DecValTok{1}\NormalTok{], xcoords[}\DecValTok{1}\NormalTok{], xcoords[}\DecValTok{2}\NormalTok{], xcoords[}\DecValTok{2}\NormalTok{]), }\DataTypeTok{y =} \KeywordTok{c}\NormalTok{(ycoord\_top }\OperatorTok{+}\StringTok{ }\NormalTok{y\_scale, ycoord\_top }\OperatorTok{+}\StringTok{ }\NormalTok{bar\_height, ycoord\_top }\OperatorTok{+}\StringTok{ }\NormalTok{bar\_height, ycoord\_top }\OperatorTok{+}\StringTok{ }\NormalTok{y\_scale)) }\CommentTok{\# final coordinates of the bar}
    
    
    
\NormalTok{    star\_x =}\StringTok{ }\KeywordTok{mean}\NormalTok{(xcoords) }\CommentTok{\# x coordinate of the text above the bar (in the middle of the two groups)}
    
\NormalTok{    star\_y =}\StringTok{ }\NormalTok{ycoord\_top }\OperatorTok{+}\StringTok{ }\NormalTok{bar\_height }\OperatorTok{+}\StringTok{ }\NormalTok{((}\FloatTok{2.75}\OperatorTok{/}\DecValTok{100}\NormalTok{)}\OperatorTok{*}\NormalTok{y\_sum) }\CommentTok{\# y coordinate of the text above the bar (above the bar by a determined factor)}
    
\NormalTok{    coord\_star =}\StringTok{ }\KeywordTok{c}\NormalTok{(star\_x, star\_y) }\CommentTok{\# x,y coordinates of the text above the bar}
    
    
    
\NormalTok{    plot =}\StringTok{ }\NormalTok{plot }\OperatorTok{+}\StringTok{ }\KeywordTok{geom\_path}\NormalTok{(}\DataTypeTok{data =}\NormalTok{ coord\_bar, }\KeywordTok{aes}\NormalTok{(}\DataTypeTok{x=}\NormalTok{x, }\DataTypeTok{y=}\NormalTok{y), }\DataTypeTok{size =}\NormalTok{ size\_bar, }\DataTypeTok{color =}\NormalTok{ color\_bar, }\DataTypeTok{linetype =}\NormalTok{ line\_type) }\OperatorTok{+}\StringTok{ }\KeywordTok{annotate}\NormalTok{(}\StringTok{"text"}\NormalTok{, }\DataTypeTok{x =}\NormalTok{ star\_x, }\DataTypeTok{y =}\NormalTok{ star\_y, }\DataTypeTok{label =}\NormalTok{ text, }\DataTypeTok{size =}\NormalTok{ size\_text, }\DataTypeTok{color =}\NormalTok{ color\_text, }\DataTypeTok{fontface =}\NormalTok{ font\_face, }\DataTypeTok{family =}\NormalTok{ font\_style) }\CommentTok{\# create the new ggplot}
    
    \KeywordTok{print}\NormalTok{(plot)}
    
    
    
\NormalTok{  \} }\ControlFlowTok{else} \ControlFlowTok{if}\NormalTok{ (}\KeywordTok{class}\NormalTok{(}\KeywordTok{as.list.environment}\NormalTok{(plot}\OperatorTok{$}\NormalTok{layers[[}\DecValTok{1}\NormalTok{]])}\OperatorTok{$}\NormalTok{geom)[}\DecValTok{1}\NormalTok{] }\OperatorTok{==}\StringTok{ "GeomBar"}\NormalTok{) \{ }\CommentTok{\# if the ggplot is a dotplot}
    
\NormalTok{    coords =}\StringTok{ }\KeywordTok{ggplot\_build}\NormalTok{(plot)}\OperatorTok{$}\NormalTok{data[[}\DecValTok{1}\NormalTok{]]}
    
\NormalTok{    xcoords =}\StringTok{ }\KeywordTok{c}\NormalTok{()  }
    
\NormalTok{    ycoords =}\StringTok{ }\KeywordTok{c}\NormalTok{()}
    
    \ControlFlowTok{for}\NormalTok{ (i }\ControlFlowTok{in}\NormalTok{ groups)\{ }\CommentTok{\# get the x and y coordinates of the two groups                                      }
      
\NormalTok{      xcoord\_temp =}\StringTok{ }\KeywordTok{mean}\NormalTok{(}\KeywordTok{c}\NormalTok{(coords[i,]}\OperatorTok{$}\NormalTok{xmin, coords[i,]}\OperatorTok{$}\NormalTok{xmax))}
      
\NormalTok{      xcoords =}\StringTok{ }\KeywordTok{append}\NormalTok{(xcoords, xcoord\_temp)}
      
\NormalTok{      ycoord\_temp =}\StringTok{ }\NormalTok{coords[i,}\DecValTok{7}\NormalTok{] }\CommentTok{\# The position of ymax in ggplot\_build(plot)$data[[1]] changed from column 6 to 7}
      
\NormalTok{      ycoords =}\StringTok{ }\KeywordTok{append}\NormalTok{(ycoords, ycoord\_temp)}
      
\NormalTok{    \}}
    
    
    
\NormalTok{    y\_range =}\StringTok{ }\KeywordTok{ggplot\_build}\NormalTok{(plot)}\OperatorTok{$}\NormalTok{layout}\OperatorTok{$}\NormalTok{panel\_scales\_y[[}\DecValTok{1}\NormalTok{]]}\OperatorTok{$}\NormalTok{limits }\CommentTok{\# get the total height of the y scale}
    
\NormalTok{    y\_sum =}\StringTok{ }\KeywordTok{sum}\NormalTok{(}\KeywordTok{abs}\NormalTok{(y\_range))}
    
\NormalTok{    y\_scale =}\StringTok{ }\NormalTok{(}\FloatTok{7.5}\OperatorTok{/}\DecValTok{100}\NormalTok{)}\OperatorTok{*}\NormalTok{y\_sum  }\CommentTok{\# starting position of the vertical bar (determined \% of the total y scale)}
    
\NormalTok{    bar\_height =}\StringTok{ }\NormalTok{y\_scale }\OperatorTok{+}\StringTok{ }\NormalTok{((}\DecValTok{5}\OperatorTok{/}\DecValTok{100}\NormalTok{)}\OperatorTok{*}\NormalTok{y\_sum) }\CommentTok{\# final position of the vertical bar (determined \% of the total y scale in addition to y\_scale)}
    
    
    
\NormalTok{    ycoord\_top =}\StringTok{ }\KeywordTok{max}\NormalTok{(ycoords) }\CommentTok{\# the bar should take the heighest of the two groups as a reference}
    
\NormalTok{    coord\_bar =}\StringTok{ }\KeywordTok{data.frame}\NormalTok{(}\DataTypeTok{x =} \KeywordTok{c}\NormalTok{(xcoords[}\DecValTok{1}\NormalTok{], xcoords[}\DecValTok{1}\NormalTok{], xcoords[}\DecValTok{2}\NormalTok{], xcoords[}\DecValTok{2}\NormalTok{]), }\DataTypeTok{y =} \KeywordTok{c}\NormalTok{(ycoord\_top }\OperatorTok{+}\StringTok{ }\NormalTok{y\_scale, ycoord\_top }\OperatorTok{+}\StringTok{ }\NormalTok{bar\_height, ycoord\_top }\OperatorTok{+}\StringTok{ }\NormalTok{bar\_height, ycoord\_top }\OperatorTok{+}\StringTok{ }\NormalTok{y\_scale)) }\CommentTok{\#  final coordinates of the bar}
    
    
    
\NormalTok{    star\_x =}\StringTok{ }\KeywordTok{mean}\NormalTok{(xcoords) }\CommentTok{\# x coordinate of the text above the bar (in the middle of the two groups)}
    
\NormalTok{    star\_y =}\StringTok{ }\NormalTok{ycoord\_top }\OperatorTok{+}\StringTok{ }\NormalTok{bar\_height }\OperatorTok{+}\StringTok{ }\NormalTok{(text\_height}\OperatorTok{*}\NormalTok{y\_sum) }\CommentTok{\# y coordinate of the text above the bar (above the bar by a determined factor)}
    
\NormalTok{    coord\_star =}\StringTok{ }\KeywordTok{c}\NormalTok{(star\_x, star\_y) }\CommentTok{\# x,y coordinates of the text above the bar}
    
    
    
\NormalTok{    plot =}\StringTok{ }\NormalTok{plot }\OperatorTok{+}\StringTok{ }\KeywordTok{geom\_path}\NormalTok{(}\DataTypeTok{data =}\NormalTok{ coord\_bar, }\KeywordTok{aes}\NormalTok{(}\DataTypeTok{x=}\NormalTok{x, }\DataTypeTok{y=}\NormalTok{y), }\DataTypeTok{size =}\NormalTok{ size\_bar, }\DataTypeTok{color =}\NormalTok{ color\_bar, }\DataTypeTok{linetype =}\NormalTok{ line\_type) }\OperatorTok{+}\StringTok{ }\KeywordTok{annotate}\NormalTok{(}\StringTok{"text"}\NormalTok{, }\DataTypeTok{x =}\NormalTok{ star\_x, }\DataTypeTok{y =}\NormalTok{ star\_y, }\DataTypeTok{label =}\NormalTok{ text, }\DataTypeTok{size =}\NormalTok{ size\_text, }\DataTypeTok{color =}\NormalTok{ color\_text, }\DataTypeTok{fontface =}\NormalTok{ font\_face, }\DataTypeTok{family =}\NormalTok{ font\_style) }\CommentTok{\# create the new ggplot}
    
    \KeywordTok{print}\NormalTok{(plot)}
    
\NormalTok{  \}}
  
\NormalTok{\}}
\end{Highlighting}
\end{Shaded}

\begin{Shaded}
\begin{Highlighting}[]
\NormalTok{gg\textless{}{-}}\StringTok{ }\KeywordTok{ggplot}\NormalTok{(c, }\KeywordTok{aes}\NormalTok{(}\DataTypeTok{x =}\NormalTok{ c..aa....ap.., }\DataTypeTok{y =} \KeywordTok{as.numeric}\NormalTok{(m\_duree\_appel)))}\OperatorTok{+}
\StringTok{    }\KeywordTok{geom\_bar}\NormalTok{(}\DataTypeTok{stat =} \StringTok{"identity"}\NormalTok{)}\OperatorTok{+}
\StringTok{    }\KeywordTok{geom\_errorbar}\NormalTok{(}\DataTypeTok{ymin =}\NormalTok{ m\_duree\_appel}\OperatorTok{{-}}\NormalTok{sd\_duree\_appel, }\DataTypeTok{ymax =}\NormalTok{ m\_duree\_appel}\OperatorTok{+}\NormalTok{sd\_duree\_appel)}\OperatorTok{+}\StringTok{ }
\StringTok{    }\KeywordTok{ylim}\NormalTok{(}\OperatorTok{{-}}\DecValTok{500}\NormalTok{,}\DecValTok{5000}\NormalTok{)}\OperatorTok{+}
\StringTok{    }\KeywordTok{labs}\NormalTok{(}\DataTypeTok{title=}\StringTok{"Duree appel"}\NormalTok{)}
\KeywordTok{significativity\_bar}\NormalTok{(gg, }\DataTypeTok{groups =} \KeywordTok{c}\NormalTok{(}\DecValTok{1}\NormalTok{,}\DecValTok{2}\NormalTok{))}
\end{Highlighting}
\end{Shaded}

\includegraphics{Calcul_téléphone_files/figure-latex/unnamed-chunk-19-1.pdf}

\hypertarget{taux-de-ruxe9ponses}{%
\subsubsection{Taux de réponses}\label{taux-de-ruxe9ponses}}

Cette partie c'est juste pour voir si je répond autant aux messages
qu'on m'en envoie.

\begin{Shaded}
\begin{Highlighting}[]
\NormalTok{Ratio\textless{}{-}df}\OperatorTok{$}\NormalTok{Messages\_recus}\OperatorTok{/}\NormalTok{df}\OperatorTok{$}\NormalTok{Messages\_envoyes}
\CommentTok{\#Remplacement des NaN et inf (division par 0) en 0.}
\NormalTok{Ratio[}\KeywordTok{is.na}\NormalTok{(Ratio)]\textless{}{-}}\DecValTok{0}
\NormalTok{Ratio[}\KeywordTok{is.infinite}\NormalTok{(Ratio)]\textless{}{-}}\DecValTok{0}
\KeywordTok{barplot}\NormalTok{(Ratio)}
\end{Highlighting}
\end{Shaded}

\includegraphics{Calcul_téléphone_files/figure-latex/unnamed-chunk-20-1.pdf}

\begin{Shaded}
\begin{Highlighting}[]
\KeywordTok{mean}\NormalTok{(Ratio)}
\end{Highlighting}
\end{Shaded}

\begin{verbatim}
## [1] 1.067513
\end{verbatim}

En moyenne c'est assez équilibré : je réponds autant de fois qu'on
m'envoie un message.

\hypertarget{conclusion}{%
\subsection{Conclusion}\label{conclusion}}

\textbf{J'ai passé pas mal de temps à faire ça mais ça m'a permis de
bien prendre en main l'outil.\\
Je conçois que mon étude est assez sale et que les manières de plotter
ne sont vraiment pas optimisées mais ce n'était pas vraiment le but de
l'exercice.}

\textbf{Après avoir compilé, je n'ai pas pû le faire en pdf (des erreurs
de polices qui ne passent pas avec LaTeX on dirait \ldots).\\
Aussi, j'ai remarqué qu'il fallait laissé un retour chariot après la
visualisation du plot sinon le texte se met à côté dans le rendu.}

\end{document}
