text:
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{\label{sec:platform-macos}Macintosh OS X}
\index{platform-specific information!Macintosh OS X}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

This section provides information specific to the Macintosh OS X port of
Condor.
The Macintosh port of Condor is more accurately a port of Condor to
Darwin, the BSD core of OS X. Condor uses the Carbon library only to
detect keyboard activity, and it does not use Cocoa at all.
Condor on the Macintosh is a relatively new port, and it
is not yet well-integrated
into the Macintosh environment.

Condor on the Macintosh has a few shortcomings:
\begin{itemize}
\item Users connected to the Macintosh via \Prog{ssh} are not
noticed for console activity.
\item The memory size of threaded programs is reported incorrectly.
\item No Macintosh-based installer is provided.
\item The example start up scripts do not follow Macintosh conventions.
\item Kerberos is not supported.
\end{itemize}

ext: tex


text:
\section{Usage}
\label{sec:interface}

The entire code can be compiled via CMake.

Please make sure you have ImageMagick installed, and its bin folder under your path.
We rely on its convert command extensively for image format conversion and basic image processing.
Please also install python for running the scripts.

\filename{test.py} is an example Python script for ordinary texture synthesis without constraints.

\filename{urc_test.py} is an example Python script for running the binary test data with various options explained in the comments.

It is best to cmake everything under a \foldername{build} folder in parallel with \foldername{src}, and invoke the script from there.


text:
\documentclass[table]{beamer}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\usepackage{amsmath}
\usepackage{xcolor}
\usepackage{mathtools}
\newcommand\x{\times}
\newcommand\y{\cellcolor{green!10}}
\usepackage{hyperref}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\DeclareUrlCommand\ULurl{%
  \renewcommand\UrlFont{\ttfamily\color{blue}}%
  \renewcommand\UrlLeft{\uline\bgroup}%
  \renewcommand\UrlRight{\egroup}}

\newif\iflattersubsect
\setcounter{tocdepth}{4}
\setcounter{secnumdepth}{4}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\AtBeginSection[] {
    \begin{frame}<beamer>
    \frametitle{Overview} %
    \tableofcontents[currentsection]
    \end{frame}
    \lattersubsectfalse
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\usepackage{graphicx}
% \graphicspath{{../figures/}}
\usetheme{default}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\newcommand\scalemath[2]{\scalebox{#1}{\mbox{\ensuremath{\displaystyle #2}}}}

\addtobeamertemplate{navigation symbols}{}{%
    \usebeamerfont{footline}%
    \usebeamercolor[fg]{footline}%
    \hspace{1em}%
    \insertframenumber/\inserttotalframenumber
}

% \beamertemplatenavigationsymbolsempty
% \setbeamertemplate{navigation symbols}{}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\title{\centering The Ring}
% \subtitle{}
\author{Gandalf the Grey}
% \institute[]
% {
%   \inst{1}%
% \\
%   \and
%   \inst{2}%
% \\
% }
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\date{date}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \subject{}

\AtBeginSubsection[]
{
  \begin{frame}<beamer>{Outline}
    \tableofcontents[currentsection,currentsubsection]
  \end{frame}
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{document}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}
  \titlepage
\end{frame}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}{Outline}
  \tableofcontents
\end{frame}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{}

\begin{frame}{}
\end{frame}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\end{document}

max_stars_repo_name: krishnanj/tex-templates

max_issues_repo_name: krishnanj/tex-templates

max_forks_repo_name: krishnanj/tex-templates


text:
% Original slides by: Karthik Ram, karthik.ram@gmail.com
% Modified by: Naupaka Zimmerman, naupaka@gmail.com
% Licence, CC-BY 4.0

\documentclass{beamer}\usepackage[]{graphicx}\usepackage[]{color}
%% maxwidth is the original width if it is less than linewidth
%% otherwise use linewidth (to make sure the graphics do not exceed the margin)
\makeatletter
\def\maxwidth{ %
  \ifdim\Gin@nat@width>\linewidth
    \linewidth
  \else
    \Gin@nat@width
  \fi
}
\makeatother

\definecolor{fgcolor}{rgb}{0.345, 0.345, 0.345}
\newcommand{\hlnum}[1]{\textcolor[rgb]{0.686,0.059,0.569}{#1}}%
\newcommand{\hlstr}[1]{\textcolor[rgb]{0.192,0.494,0.8}{#1}}%
\newcommand{\hlcom}[1]{\textcolor[rgb]{0.678,0.584,0.686}{\textit{#1}}}%
\newcommand{\hlopt}[1]{\textcolor[rgb]{0,0,0}{#1}}%
\newcommand{\hlstd}[1]{\textcolor[rgb]{0.345,0.345,0.345}{#1}}%
\newcommand{\hlkwa}[1]{\textcolor[rgb]{0.161,0.373,0.58}{\textbf{#1}}}%
\newcommand{\hlkwb}[1]{\textcolor[rgb]{0.69,0.353,0.396}{#1}}%
\newcommand{\hlkwc}[1]{\textcolor[rgb]{0.333,0.667,0.333}{#1}}%
\newcommand{\hlkwd}[1]{\textcolor[rgb]{0.737,0.353,0.396}{\textbf{#1}}}%

\usepackage{framed}
\makeatletter
\newenvironment{kframe}{%
 \def\at@end@of@kframe{}%
 \ifinner\ifhmode%
  \def\at@end@of@kframe{\end{minipage}}%
  \begin{minipage}{\columnwidth}%
 \fi\fi%
 \def\FrameCommand##1{\hskip\@totalleftmargin \hskip-\fboxsep
 \colorbox{shadecolor}{##1}\hskip-\fboxsep
     % There is no \\@totalrightmargin, so:
     \hskip-\linewidth \hskip-\@totalleftmargin \hskip\columnwidth}%
 \MakeFramed {\advance\hsize-\width
   \@totalleftmargin\z@ \linewidth\hsize
   \@setminipage}}%
 {\par\unskip\endMakeFramed%
 \at@end@of@kframe}
\makeatother

\definecolor{shadecolor}{rgb}{.97, .97, .97}
\definecolor{messagecolor}{rgb}{0, 0, 0}
\definecolor{warningcolor}{rgb}{1, 0, 1}
\definecolor{errorcolor}{rgb}{1, 0, 0}
\newenvironment{knitrout}{}{} % an empty environment to be redefined in TeX

\usepackage{alltt}
\let\Tiny=\tiny
\hfuzz=\maxdimen
\tolerance=10000
\hbadness=10000
\usepackage{listings}
% \usepackage{inconsolata}
\usepackage[T1]{fontenc}
\setbeamertemplate{frametitle}[default][center]
\usepackage{url}
\usepackage{color}
\setcounter{secnumdepth}{-1}
\usetheme{default}
\defbeamertemplate*{title page}{customized}[1][]
{
  \begin{center}
  \usebeamerfont{title}\inserttitle\par
  \usebeamerfont{subtitle}\usebeamercolor[fg]{subtitle}\insertsubtitle\par
  \bigskip
  \bigskip
  \bigskip
  \usebeamerfont{author}\insertauthor\par
  \usebeamerfont{date}\insertdate\par
  \end{center}
}
\addtobeamertemplate{frametitle}{\vspace*{0.5cm}}{}

% --------------------------------------------------------------
% --------------------------------------------------------------
% --------------------------------------------------------------

% Setting up some knitr options

% --------------------------------------------------------------
% --------------------------------------------------------------
% --------------------------------------------------------------
\IfFileExists{upquote.sty}{\usepackage{upquote}}{}
\begin{document}
\SweaveOpts{concordance=TRUE}
% \SweaveOpts{concordance=TRUE} % deprecated

\title{Data Visualization Using R \& ggplot2}
\author{Naupaka Zimmerman (@naupakaz) \linebreak Andrew Tredennick (@ATredennick) \linebreak \linebreak Hat tip to Karthik Ram (@\_inundata) for original slides \linebreak}
\date{August 6, 2016}
\maketitle

% --------------------------------------------------------------

\begin{frame}[fragile]
\frametitle{Some housekeeping}
Install some packages
\begin{knitrout}\footnotesize
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{alltt}
\hlkwd{install.packages}\hlstd{(}\hlstr{"ggplot2"}\hlstd{,} \hlkwc{dependencies} \hlstd{=} \hlnum{TRUE}\hlstd{)}
\hlkwd{install.packages}\hlstd{(}\hlstr{"ggthemes"}\hlstd{)}
\hlkwd{install.packages}\hlstd{(}\hlstr{"tidyr"}\hlstd{)}
\hlkwd{install.packages}\hlstd{(}\hlstr{"dplyr"}\hlstd{)}
\end{alltt}
\end{kframe}
\end{knitrout}
\end{frame}

\begin{frame}[fragile]
\frametitle{1 minute}
\begin{knitrout}\footnotesize
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}

{\centering \includegraphics[width=.75\linewidth]{figure/gapminder-1}

}

\end{knitrout}
\end{frame}

\begin{frame}[fragile]
\frametitle{}
\begin{knitrout}\footnotesize
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{alltt}
\hlkwd{ggplot}\hlstd{(gapminder,} \hlkwd{aes}\hlstd{(}\hlkwc{x} \hlstd{= gdpPercap,} \hlkwc{y} \hlstd{= lifeExp))} \hlopt{+}
  \hlkwd{geom_point}\hlstd{(}\hlkwc{shape} \hlstd{=} \hlnum{1}\hlstd{,} \hlkwd{aes}\hlstd{(}\hlkwc{color} \hlstd{= continent))} \hlopt{+}
  \hlkwd{stat_smooth}\hlstd{(}\hlkwc{method} \hlstd{=} \hlstr{"lm"}\hlstd{,} \hlkwc{size} \hlstd{=} \hlnum{1}\hlstd{,} \hlkwc{color} \hlstd{=} \hlstr{"black"}\hlstd{)} \hlopt{+}
  \hlkwd{scale_x_log10}\hlstd{()} \hlopt{+}
  \hlkwd{xlab}\hlstd{(}\hlstr{"Per Capita GDP"}\hlstd{)} \hlopt{+}
  \hlkwd{ylab}\hlstd{(}\hlstr{"Life Expectancy (yrs)"}\hlstd{)} \hlopt{+}
  \hlkwd{facet_wrap}\hlstd{(}\hlopt{~}\hlstd{continent,} \hlkwc{scales} \hlstd{=} \hlstr{"free"}\hlstd{)} \hlopt{+}
  \hlkwd{theme_bw}\hlstd{()} \hlopt{+}
  \hlkwd{guides}\hlstd{(}\hlkwc{color}\hlstd{=}\hlnum{FALSE}\hlstd{)}
\end{alltt}
\end{kframe}
\end{knitrout}
\end{frame}

\begin{frame}[fragile]
\frametitle{30 minutes}

\begin{center}
\includegraphics[scale=0.5]{images/base_continents_plot.png}
\end{center}
\end{frame}

\begin{frame}[fragile]
\frametitle{}
\begin{knitrout}\footnotesize
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{alltt}
conts <- \hlkwd{unique}(gapminder[,\hlstr{"continent"}])
cols <- scales::\hlkwd{hue_pal}()(\hlkwd{length}(conts))
\hlkwd{par}(mfrow = \hlkwd{c}(2,3))
counter<-1
\hlkwd{for} (i in conts) \{
  \hlkwd{plot}(gapminder[\hlkwd{which}(gapminder$continent == i),
  			   \hlstr{"gdpPercap"}],
       gapminder[\hlkwd{which}(gapminder$continent == i),
       		  \hlstr{"lifeExp"}],
  	   col = cols[counter],
       xlab = \hlstr{"Per Capita GDP"},
		 ylab = \hlstr{"Life \hlkwd{Expectancy} (yrs)"},
       main = i, las = 1, log = \hlstr{"x"})
  fit <- \hlkwd{lm}(gapminder[\hlkwd{which}(gapminder$continent == i),
  					\hlstr{"lifeExp"}] ~
\end{alltt}
\end{kframe}
\end{knitrout}
\end{frame}

\begin{frame}[fragile]
\frametitle{but wait there's more}
\begin{knitrout}\footnotesize
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{alltt}
      \hlkwd{log}(gapminder[\hlkwd{which}(gapminder$continent == i),
      			  \hlstr{"gdpPercap"}]))
  pred <- \hlkwd{predict}(fit, interval = \hlstr{"confidence"})
  \hlkwd{lines}(\hlkwd{sort}(gapminder[\hlkwd{which}(gapminder$continent == i),
  					 \hlstr{"gdpPercap"}]),
        \hlkwd{sort}(pred[,1]))
  \hlkwd{lines}(\hlkwd{sort}(gapminder[\hlkwd{which}(gapminder$continent == i),
  					 \hlstr{"gdpPercap"}]),
        \hlkwd{sort}(pred[,2]), lty = 2)
  \hlkwd{lines}(\hlkwd{sort}(gapminder[\hlkwd{which}(gapminder$continent == i),
  					 \hlstr{"gdpPercap"}]),
        \hlkwd{sort}(pred[,3]), lty = 2)
  counter <- counter + 1
\}
\end{alltt}
\end{kframe}
\end{knitrout}
\end{frame}

% --------------------------------------------------------------
% --------------------------------------------------------------

\section*{Why \texttt{ggplot2}?}
\frame{\sectionpage}

% --------------------------------------------------------------
% --------------------------------------------------------------

\begin{frame}[fragile]
\frametitle{Why \texttt{ggplot2}?}
\begin{itemize}
\item More elegant \& compact code than with base graphics\\
\item More aesthetically pleasing defaults than lattice\\
\item Very powerful for exploratory data analysis\\
\end{itemize}
\end{frame}

% --------------------------------------------------------------

\begin{frame}[fragile]
\frametitle{Why \texttt{ggplot2}?}
\begin{itemize}
\item `gg' is for `grammar of graphics' (term by Lee Wilkinson)\\
\item A set of terms that defines the basic components of a plot\\
\item Used to produce figures using coherant, consistant syntax\\
\end{itemize}
\end{frame}

% --------------------------------------------------------------

\begin{frame}[fragile]
\frametitle{Why \texttt{ggplot2}?}
\begin{itemize}
\item Supports a continuum of expertise:
\item Easy to get started, plenty of power for complex figures
\end{itemize}
\end{frame}

% --------------------------------------------------------------
% --------------------------------------------------------------

\section*{The Grammar}
\frame{\sectionpage}

% --------------------------------------------------------------
% --------------------------------------------------------------

\begin{frame}[fragile]
\frametitle{Some terminology}
\begin{columns}[t]

\begin{column}[T]{3cm}
\begin{itemize}
    \item \textbf{data}
\end{itemize}
\end{column}

\begin{column}[T]{8cm}
\begin{itemize}
    \item Must be a data.frame
    \item Gets pulled into the ggplot() object
\end{itemize}
\end{column}

\end{columns}
\end{frame}

% --------------------------------------------------------------

\begin{frame}[fragile]
\frametitle{The iris dataset}
\begin{knitrout}\footnotesize
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{alltt}
\hlkwd{head}\hlstd{(iris)}
\end{alltt}
\begin{verbatim}
##   Sepal.Length Sepal.Width Petal.Length Petal.Width Species
## 1          5.1         3.5          1.4         0.2  setosa
## 2          4.9         3.0          1.4         0.2  setosa
## 3          4.7         3.2          1.3         0.2  setosa
## 4          4.6         3.1          1.5         0.2  setosa
## 5          5.0         3.6          1.4         0.2  setosa
## 6          5.4         3.9          1.7         0.4  setosa
\end{verbatim}
\end{kframe}
\end{knitrout}
\end{frame}

% --------------------------------------------------------------

\begin{frame}[fragile]
\frametitle{\texttt{tidyr}}
Help your data play nice with \texttt{ggplot}.
\end{frame}

% --------------------------------------------------------------

\begin{frame}[fragile]
\frametitle{\texttt{tidyr}}
\begin{knitrout}\footnotesize
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{alltt}
\hlstd{iris[}\hlnum{1}\hlopt{:}\hlnum{2}\hlstd{, ]}
\end{alltt}
\begin{verbatim}
##   Sepal.Length Sepal.Width Petal.Length Petal.Width Species
## 1          5.1         3.5          1.4         0.2  setosa
## 2          4.9         3.0          1.4         0.2  setosa
\end{verbatim}
\begin{alltt}
\hlkwd{library}\hlstd{(}\hlstr{"tidyr"}\hlstd{)}
\hlstd{df} \hlkwb{<-} \hlkwd{gather}\hlstd{(iris,} \hlkwc{key} \hlstd{= flower_attribute,} \hlkwc{value} \hlstd{= measurement,}
                         \hlopt{-}\hlstd{Species)}
\hlstd{df[}\hlnum{1}\hlopt{:}\hlnum{2}\hlstd{, ]}
\end{alltt}
\begin{verbatim}
##   Species flower_attribute measurement
## 1  setosa     Sepal.Length         5.1
## 2  setosa     Sepal.Length         4.9
\end{verbatim}
\end{kframe}
\end{knitrout}
\end{frame}

% --------------------------------------------------------------
% --------------------------------------------------------------

\section*{Aesthetics}
\frame{\sectionpage}

% --------------------------------------------------------------
% --------------------------------------------------------------

\begin{frame}[fragile]
\frametitle{Some terminology}
\begin{columns}[t]

\begin{column}[T]{3cm}
\begin{itemize}
    \item \textbf{\color{gray}data}
    \item \textbf{aes}thetics
\end{itemize}
\end{column}

\begin{column}[T]{8cm}
\begin{itemize}
    \item \textbf{How your data are represented visually}
        \begin{itemize}
        \item \emph{a.k.a. mapping}
        \end{itemize}
    \item which data on the x
    \item which data on the y
    \item but also: {\color{red}color}, {\LARGE{size}}, shape, transparency
\end{itemize}
\end{column}

\end{columns}
\end{frame}

% --------------------------------------------------------------

\begin{frame}[fragile]
\frametitle{Let's try an example}
\begin{knitrout}\footnotesize
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{alltt}
\hlstd{myplot} \hlkwb{<-} \hlkwd{ggplot}\hlstd{(}\hlkwc{data} \hlstd{= iris,} \hlkwd{aes}\hlstd{(}\hlkwc{x} \hlstd{= Sepal.Length,}
                        \hlkwc{y} \hlstd{= Sepal.Width))}
\hlkwd{summary}\hlstd{(myplot)}
\end{alltt}
\begin{verbatim}
## data: Sepal.Length, Sepal.Width, Petal.Length,
##   Petal.Width, Species [150x5]
## mapping:  x = Sepal.Length, y = Sepal.Width
## faceting: facet_null()
\end{verbatim}
\end{kframe}
\end{knitrout}
\end{frame}

% --------------------------------------------------------------
% --------------------------------------------------------------

\section*{Geoms}
\frame{\sectionpage}

% --------------------------------------------------------------
% --------------------------------------------------------------

\begin{frame}[fragile]
\frametitle{Some terminology}
\begin{columns}[t]

\begin{column}[T]{3cm}
\begin{itemize}
    \item \textbf{\color{gray}data}
    \item \textbf{\color{gray}aesthetics}
    \item \textbf{geom}etry
\end{itemize}
\end{column}

\begin{column}[T]{8cm}
\begin{itemize}
    \item \textbf{The geometric objects in the plot}
    \item points, lines, polygons, etc
    \item shortcut functions: geom\_point(), geom\_bar(), geom\_line()
\end{itemize}
\end{column}

\end{columns}
\end{frame}

% --------------------------------------------------------------

\begin{frame}[fragile]
\frametitle{Basic structure}
\begin{knitrout}\footnotesize
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{alltt}
\hlkwd{ggplot}\hlstd{(}\hlkwc{data} \hlstd{= iris,} \hlkwd{aes}\hlstd{(}\hlkwc{x} \hlstd{= Sepal.Length,} \hlkwc{y} \hlstd{= Sepal.Width))}
    \hlopt{+} \hlkwd{geom_point}\hlstd{()}
\hlstd{myplot} \hlkwb{<-} \hlkwd{ggplot}\hlstd{(}\hlkwc{data} \hlstd{= iris,} \hlkwd{aes}\hlstd{(}\hlkwc{x} \hlstd{= Sepal.Length,}
                                \hlkwc{y} \hlstd{= Sepal.Width))}
\hlstd{myplot} \hlopt{+} \hlkwd{geom_point}\hlstd{()}
\end{alltt}
\end{kframe}
\end{knitrout}
\begin{itemize}
\item Specify the data and variables inside the \texttt{ggplot} function.
\item Anything else that goes in here becomes a global setting.
\item Then add layers: geometric objects, statistical models, and facets.
\end{itemize}
\end{frame}

% --------------------------------------------------------------

\begin{frame}[fragile]
\frametitle{Quick note}
\begin{itemize}
\item Never use \texttt{qplot} - short for quick plot.
\item You`ll end up unlearning and relearning a good bit.
\end{itemize}

\end{frame}

% --------------------------------------------------------------

\begin{frame}[fragile]
\frametitle{Let's try an example}
\begin{knitrout}\footnotesize
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{alltt}
\hlkwd{ggplot}\hlstd{(}\hlkwc{data} \hlstd{= iris,} \hlkwd{aes}\hlstd{(}\hlkwc{x} \hlstd{= Sepal.Length,} \hlkwc{y} \hlstd{= Sepal.Width))} \hlopt{+}
    \hlkwd{geom_point}\hlstd{()}
\end{alltt}
\end{kframe}

{\centering \includegraphics[width=.75\linewidth]{figure/first_plot-1}

}

\end{knitrout}
\end{frame}

% --------------------------------------------------------------

\begin{frame}[fragile]
\frametitle{Changing the aesthetics of a geom: \\Increase the size of points}
\begin{knitrout}\footnotesize
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{alltt}
\hlkwd{ggplot}\hlstd{(}\hlkwc{data} \hlstd{= iris,} \hlkwd{aes}\hlstd{(}\hlkwc{x} \hlstd{= Sepal.Length,} \hlkwc{y} \hlstd{= Sepal.Width))} \hlopt{+}
    \hlkwd{geom_point}\hlstd{(}\hlkwc{size} \hlstd{=} \hlnum{3}\hlstd{)}
\end{alltt}
\end{kframe}

{\centering \includegraphics[width=.75\linewidth]{figure/first_plot_size-1}

}

\end{knitrout}
\end{frame}

% --------------------------------------------------------------

\begin{frame}[fragile]
\frametitle{Changing the aesthetics of a geom: \\Add some color}
\begin{knitrout}\footnotesize
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{alltt}
\hlkwd{ggplot}\hlstd{(iris,} \hlkwd{aes}\hlstd{(Sepal.Length, Sepal.Width,}
                \hlkwc{color} \hlstd{= Species))} \hlopt{+}
    \hlkwd{geom_point}\hlstd{(}\hlkwc{size} \hlstd{=} \hlnum{3}\hlstd{)}
\end{alltt}
\end{kframe}

{\centering \includegraphics[width=.75\linewidth]{figure/first_plot_color-1}

}

\end{knitrout}
\end{frame}

% --------------------------------------------------------------

\begin{frame}[fragile]
\frametitle{Changing the aesthetics of a geom: \\Differentiate points by shape}
\begin{knitrout}\footnotesize
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{alltt}
\hlkwd{ggplot}\hlstd{(iris,} \hlkwd{aes}\hlstd{(Sepal.Length, Sepal.Width,} \hlkwc{color} \hlstd{= Species))} \hlopt{+}
    \hlkwd{geom_point}\hlstd{(}\hlkwd{aes}\hlstd{(}\hlkwc{shape} \hlstd{= Species),} \hlkwc{size} \hlstd{=} \hlnum{3}\hlstd{)}
\hlcom{# Why aes(shape = Species)?}
\end{alltt}
\end{kframe}

{\centering \includegraphics[width=.75\linewidth]{figure/first_plot_shape-1}

}

\end{knitrout}
\end{frame}

% --------------------------------------------------------------

\begin{frame}[fragile]
\frametitle{Exercise 1}
\begin{knitrout}\footnotesize
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{alltt}
\hlcom{# Make a small sample of the diamonds dataset}
\hlstd{d2} \hlkwb{<-} \hlstd{diamonds[}\hlkwd{sample}\hlstd{(}\hlnum{1}\hlopt{:}\hlkwd{dim}\hlstd{(diamonds)[}\hlnum{1}\hlstd{],} \hlnum{1000}\hlstd{), ]}
\end{alltt}
\end{kframe}
\end{knitrout}
Then generate this plot below.

\begin{knitrout}\footnotesize
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}

{\centering \includegraphics[width=.75\linewidth]{figure/ex1-1}

}

\end{knitrout}
\end{frame}

% --------------------------------------------------------------
% --------------------------------------------------------------

\section*{Stats}
\frame{\sectionpage}

% --------------------------------------------------------------
% --------------------------------------------------------------

\begin{frame}[fragile]
\frametitle{Some terminology}
\begin{columns}[t]

\begin{column}[T]{3cm}
\begin{itemize}
    \item \textbf{\color{gray}data}
    \item \textbf{\color{gray}aesthetics}
    \item \textbf{\color{gray}geometry}
    \item \textbf{stat}s
\end{itemize}
\end{column}

\begin{column}[T]{8cm}
\begin{itemize}
    \item \textbf{Statistical transformations and data summary}
    \item All geoms have associated default stats, and vice versa
    \item e.g. binning for a histogram or fitting a linear model
\end{itemize}
\end{column}

\end{columns}
\end{frame}

% --------------------------------------------------------------

\begin{frame}[fragile]
\frametitle{Built-in stat example: Boxplots}
See \texttt{?geom\_boxplot} for list of options
\begin{knitrout}\footnotesize
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{alltt}
\hlkwd{library}\hlstd{(MASS)}
\hlkwd{ggplot}\hlstd{(birthwt,} \hlkwd{aes}\hlstd{(}\hlkwd{factor}\hlstd{(race), bwt))} \hlopt{+} \hlkwd{geom_boxplot}\hlstd{()}
\end{alltt}
\end{kframe}

{\centering \includegraphics[width=.75\linewidth]{figure/boxplots1-1}

}

\end{knitrout}
\end{frame}

% --------------------------------------------------------------

\begin{frame}[fragile]
\frametitle{Built-in stat example: Boxplots}
\begin{knitrout}\footnotesize
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{alltt}
\hlstd{myplot} \hlkwb{<-} \hlkwd{ggplot}\hlstd{(birthwt,} \hlkwd{aes}\hlstd{(}\hlkwd{factor}\hlstd{(race), bwt))} \hlopt{+}
        \hlkwd{geom_boxplot}\hlstd{()}
\hlkwd{summary}\hlstd{(myplot)}
\end{alltt}
\begin{verbatim}
## data: low, age, lwt, race, smoke, ptl, ht, ui, ftv,
##   bwt [189x10]
## mapping:  x = factor(race), y = bwt
## faceting: facet_null()
## -----------------------------------
## geom_boxplot: outlier.colour = NULL, outlier.shape = 19, outlier.size = 1.5, outlier.stroke = 0.5, notch = FALSE, notchwidth = 0.5, varwidth = FALSE, na.rm = FALSE
## stat_boxplot: na.rm = FALSE
## position_dodge
\end{verbatim}
\end{kframe}
\end{knitrout}
\end{frame}

% --------------------------------------------------------------
% --------------------------------------------------------------

\section*{Facets}
\frame{\sectionpage}

% --------------------------------------------------------------
% --------------------------------------------------------------

\begin{frame}[fragile]
\frametitle{Some terminology}
\begin{columns}[t]

\begin{column}[T]{3cm}
\begin{itemize}
    \item \textbf{\color{gray}data}
    \item \textbf{\color{gray}aesthetics}
    \item \textbf{\color{gray}geometry}
    \item \textbf{\color{gray}stats}
    \item \textbf{facet}s
\end{itemize}
\end{column}

\begin{column}[T]{8cm}
\begin{itemize}
    \item \textbf{Subsetting data to make lattice plots}
    \item Really powerful
\end{itemize}
\end{column}

\end{columns}
\end{frame}

% --------------------------------------------------------------

\begin{frame}[fragile]
\frametitle{Faceting: single column, multiple rows}
\begin{knitrout}\footnotesize
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{alltt}
\hlkwd{ggplot}\hlstd{(iris,} \hlkwd{aes}\hlstd{(Sepal.Length, Sepal.Width,} \hlkwc{color} \hlstd{= Species))} \hlopt{+}
    \hlkwd{geom_point}\hlstd{()} \hlopt{+}
    \hlkwd{facet_grid}\hlstd{(Species} \hlopt{~} \hlstd{.)}
\end{alltt}
\end{kframe}

{\centering \includegraphics[width=.75\linewidth]{figure/facetgrid1-1}

}

\end{knitrout}
\end{frame}

% --------------------------------------------------------------

\begin{frame}[fragile]
\frametitle{Faceting: single row, multiple columns}
\begin{knitrout}\footnotesize
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{alltt}
\hlkwd{ggplot}\hlstd{(iris,} \hlkwd{aes}\hlstd{(Sepal.Length, Sepal.Width,} \hlkwc{color} \hlstd{= Species))} \hlopt{+}
    \hlkwd{geom_point}\hlstd{()} \hlopt{+}
    \hlkwd{facet_grid}\hlstd{(.} \hlopt{~} \hlstd{Species)}
\end{alltt}
\end{kframe}

{\centering \includegraphics[width=.75\linewidth]{figure/facet_grid2-1}

}

\end{knitrout}
\end{frame}

% --------------------------------------------------------------

\begin{frame}[fragile]
\frametitle{or just wrap your facets}
\begin{knitrout}\footnotesize
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{alltt}
\hlkwd{ggplot}\hlstd{(iris,} \hlkwd{aes}\hlstd{(Sepal.Length, Sepal.Width,} \hlkwc{color} \hlstd{= Species))} \hlopt{+}
    \hlkwd{geom_point}\hlstd{()} \hlopt{+}
    \hlkwd{facet_wrap}\hlstd{(} \hlopt{~} \hlstd{Species)} \hlcom{# notice lack of .}
\end{alltt}
\end{kframe}

{\centering \includegraphics[width=.75\linewidth]{figure/facet_wrap-1}

}

\end{knitrout}
\end{frame}

% --------------------------------------------------------------
% --------------------------------------------------------------

\section*{Scales}
\frame{\sectionpage}

% --------------------------------------------------------------
% --------------------------------------------------------------

\begin{frame}[fragile]
\frametitle{Some terminology}
\begin{columns}[t]

\begin{column}[T]{3cm}
\begin{itemize}
    \item \textbf{\color{gray}data}
    \item \textbf{\color{gray}aesthetics}
    \item \textbf{\color{gray}geometry}
    \item \textbf{\color{gray}stats}
    \item \textbf{\color{gray}facets}
    \item \textbf{scale}s
\end{itemize}
\end{column}

\begin{column}[T]{8cm}
\begin{itemize}
    \item \textbf{Control the mapping from data to aesthetics}
    \item Often used for adjusting color mapping
\end{itemize}
\end{column}

\end{columns}
\end{frame}

% --------------------------------------------------------------

\begin{frame}[fragile]
\frametitle{Colors}
\begin{knitrout}\footnotesize
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{alltt}
\hlkwd{aes}\hlstd{(}\hlkwc{color} \hlstd{= variable)} \hlcom{# mapping}
\hlstd{color} \hlkwb{=} \hlstr{"black"} \hlcom{# setting}

\hlcom{# Or add it as a scale}
\hlkwd{scale_fill_manual}\hlstd{(}\hlkwc{values} \hlstd{=} \hlkwd{c}\hlstd{(}\hlstr{"color1"}\hlstd{,} \hlstr{"color2"}\hlstd{))}
\end{alltt}
\end{kframe}
\end{knitrout}
\end{frame}

% --------------------------------------------------------------

\begin{frame}[fragile]
\frametitle{The RColorBrewer package}
\begin{knitrout}\footnotesize
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{alltt}
\hlkwd{library}\hlstd{(}\hlstr{"RColorBrewer"}\hlstd{)}
\hlkwd{display.brewer.all}\hlstd{()}
\end{alltt}
\end{kframe}
\end{knitrout}
\begin{center}
\includegraphics[scale=0.25]{images/color_palette.png}
\end{center}
\end{frame}

% --------------------------------------------------------------

\begin{frame}[fragile]
\frametitle{Using a color brewer palette}
\begin{knitrout}\footnotesize
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{alltt}
\hlkwd{library}\hlstd{(}\hlstr{"RColorBrewer"}\hlstd{)}
\hlstd{df} \hlkwb{<-} \hlkwd{gather}\hlstd{(iris,} \hlkwc{key} \hlstd{= flower_attribute,}
                         \hlkwc{value} \hlstd{= measurement,} \hlopt{-}\hlstd{Species)}
\hlstd{df[}\hlnum{1}\hlopt{:}\hlnum{2}\hlstd{,]}
\end{alltt}
\begin{verbatim}
##   Species flower_attribute measurement
## 1  setosa     Sepal.Length         5.1
## 2  setosa     Sepal.Length         4.9
\end{verbatim}
\end{kframe}
\end{knitrout}
\end{frame}

% --------------------------------------------------------------

\begin{frame}[fragile]
\frametitle{Using a color brewer palette}
\begin{knitrout}\footnotesize
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{alltt}
\hlkwd{ggplot}\hlstd{(df,} \hlkwd{aes}\hlstd{(Species, measurement,} \hlkwc{fill} \hlstd{= flower_attribute))} \hlopt{+}
    \hlkwd{geom_bar}\hlstd{(}\hlkwc{stat} \hlstd{=} \hlstr{"identity"}\hlstd{,} \hlkwc{position} \hlstd{=} \hlstr{"dodge"}\hlstd{)} \hlopt{+}
    \hlkwd{scale_fill_brewer}\hlstd{(}\hlkwc{palette} \hlstd{=} \hlstr{"Set1"}\hlstd{)}
\end{alltt}
\end{kframe}

{\centering \includegraphics[width=.75\linewidth]{figure/barcolors-1}

}

\end{knitrout}
\end{frame}

% --------------------------------------------------------------

\begin{frame}[fragile]
\frametitle{Manual color scale}
\begin{knitrout}\footnotesize
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{alltt}
\hlkwd{ggplot}\hlstd{(iris,} \hlkwd{aes}\hlstd{(Sepal.Length, Sepal.Width,} \hlkwc{color} \hlstd{= Species))} \hlopt{+}
    \hlkwd{geom_point}\hlstd{()} \hlopt{+}
    \hlkwd{facet_grid}\hlstd{(Species} \hlopt{~} \hlstd{.)} \hlopt{+}
    \hlkwd{scale_color_manual}\hlstd{(}\hlkwc{values} \hlstd{=} \hlkwd{c}\hlstd{(}\hlstr{"red"}\hlstd{,} \hlstr{"green"}\hlstd{,} \hlstr{"blue"}\hlstd{))}
\end{alltt}
\end{kframe}

{\centering \includegraphics[width=.75\linewidth]{figure/facetgridcolors-1}

}

\end{knitrout}
\end{frame}

% --------------------------------------------------------------

\begin{frame}[fragile]
\frametitle{Refer to a color chart for beautful visualizations}
\begin{center}
\url{http://tools.medialab.sciences-po.fr/iwanthue/}
\newline
\newline
\includegraphics[scale=0.25]{images/color_schemes.png}
\end{center}
\end{frame}

% --------------------------------------------------------------

\begin{frame}[fragile]
\frametitle{Adding a continuous scale to an axis}
\begin{knitrout}\footnotesize
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{alltt}
\hlkwd{library}\hlstd{(MASS)}
\hlkwd{ggplot}\hlstd{(birthwt,} \hlkwd{aes}\hlstd{(}\hlkwd{factor}\hlstd{(race), bwt))} \hlopt{+}
    \hlkwd{geom_boxplot}\hlstd{(}\hlkwc{width} \hlstd{=} \hlnum{.2}\hlstd{)} \hlopt{+}
    \hlkwd{scale_y_continuous}\hlstd{(}\hlkwc{labels} \hlstd{= (}\hlkwd{paste0}\hlstd{(}\hlnum{1}\hlopt{:}\hlnum{4}\hlstd{,} \hlstr{" Kg"}\hlstd{)),}
        \hlkwc{breaks} \hlstd{=} \hlkwd{seq}\hlstd{(}\hlnum{1000}\hlstd{,} \hlnum{4000}\hlstd{,} \hlkwc{by} \hlstd{=} \hlnum{1000}\hlstd{))}
\end{alltt}
\end{kframe}

{\centering \includegraphics[width=.75\linewidth]{figure/boxplots3-1}

}

\end{knitrout}
\end{frame}

% --------------------------------------------------------------

\begin{frame}[fragile]
\frametitle{Commonly used scales}
\begin{knitrout}\footnotesize
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{alltt}
\hlkwd{scale_fill_discrete}\hlstd{();} \hlkwd{scale_colour_discrete}\hlstd{()}
\hlkwd{scale_fill_hue}\hlstd{();} \hlkwd{scale_color_hue}\hlstd{()}
\hlkwd{scale_fill_manual}\hlstd{();}  \hlkwd{scale_color_manual}\hlstd{()}
\hlkwd{scale_fill_brewer}\hlstd{();} \hlkwd{scale_color_brewer}\hlstd{()}
\hlkwd{scale_linetype}\hlstd{();} \hlkwd{scale_shape_manual}\hlstd{()}
\end{alltt}
\end{kframe}
\end{knitrout}
\end{frame}

% --------------------------------------------------------------
% --------------------------------------------------------------

\section*{Coordinates}
\frame{\sectionpage}

% --------------------------------------------------------------
% --------------------------------------------------------------

\begin{frame}[fragile]
\frametitle{Some terminology}
\begin{columns}[t]

\begin{column}[T]{3cm}
\begin{itemize}
    \item \textbf{\color{gray}data}
    \item \textbf{\color{gray}aesthetics}
    \item \textbf{\color{gray}geometry}
    \item \textbf{\color{gray}stats}
    \item \textbf{\color{gray}facets}
    \item \textbf{\color{gray}scales}
    \item \textbf{coord}inates
\end{itemize}
\end{column}

\begin{column}[T]{8cm}
\begin{itemize}
    \item Not going to cover this in detail
    \item e.g. polar coordinate plots
\end{itemize}
\end{column}

\end{columns}
\end{frame}

% --------------------------------------------------------------
% --------------------------------------------------------------

\section*{Putting it all together with more examples}
\frame{\sectionpage}

% --------------------------------------------------------------
% --------------------------------------------------------------

\section*{Histograms}
\frame{\sectionpage}

% --------------------------------------------------------------
% --------------------------------------------------------------

\begin{frame}[fragile]
See \texttt{?geom\_histogram} for list of options
\begin{knitrout}\footnotesize
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{alltt}
\hlstd{h} \hlkwb{<-} \hlkwd{ggplot}\hlstd{(faithful,} \hlkwd{aes}\hlstd{(}\hlkwc{x} \hlstd{= waiting))}
\hlstd{h} \hlopt{+} \hlkwd{geom_histogram}\hlstd{(}\hlkwc{binwidth} \hlstd{=} \hlnum{30}\hlstd{,} \hlkwc{colour} \hlstd{=} \hlstr{"black"}\hlstd{)}
\end{alltt}
\end{kframe}

{\centering \includegraphics[width=.75\linewidth]{figure/histogr-1}

}

\end{knitrout}
\end{frame}

% --------------------------------------------------------------

\begin{frame}[fragile]
\begin{knitrout}\footnotesize
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{alltt}
\hlstd{h} \hlkwb{<-} \hlkwd{ggplot}\hlstd{(faithful,} \hlkwd{aes}\hlstd{(}\hlkwc{x} \hlstd{= waiting))}
\hlstd{h} \hlopt{+} \hlkwd{geom_histogram}\hlstd{(}\hlkwc{binwidth} \hlstd{=} \hlnum{8}\hlstd{,} \hlkwc{fill} \hlstd{=} \hlstr{"steelblue"}\hlstd{,}
\hlkwc{colour} \hlstd{=} \hlstr{"black"}\hlstd{)}
\end{alltt}
\end{kframe}

{\centering \includegraphics[width=.75\linewidth]{figure/histogra-1}

}

\end{knitrout}
\end{frame}

% --------------------------------------------------------------
% --------------------------------------------------------------

\section*{Line plots}
\frame{\sectionpage}

% --------------------------------------------------------------
% --------------------------------------------------------------

\begin{frame}[fragile]
\begin{knitrout}\footnotesize
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{alltt}
\hlstd{climate} \hlkwb{<-} \hlkwd{read.csv}\hlstd{(}\hlstr{"../data/climate.csv"}\hlstd{,} \hlkwc{header} \hlstd{=} \hlnum{TRUE}\hlstd{)}
\hlkwd{ggplot}\hlstd{(climate,} \hlkwd{aes}\hlstd{(Year, Anomaly10y))} \hlopt{+}
    \hlkwd{geom_line}\hlstd{()}
\end{alltt}
\end{kframe}

{\centering \includegraphics[width=.75\linewidth]{figure/linea-1}

}

\end{knitrout}
\begin{flushright}
\begingroup
    \fontsize{6pt}{12pt}\selectfont
    \begin{verbatim}
        climate <- read.csv(text =
        RCurl::getURL('https://raw.github.com/karthikram/ggplot-lecture/master/climate.csv'))
    \end{verbatim}
\endgroup
\end{flushright}
\end{frame}

% --------------------------------------------------------------

\begin{frame}[fragile]
We can also plot confidence regions
\begin{knitrout}\footnotesize
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{alltt}
\hlkwd{ggplot}\hlstd{(climate,} \hlkwd{aes}\hlstd{(Year, Anomaly10y))} \hlopt{+}
    \hlkwd{geom_ribbon}\hlstd{(}\hlkwd{aes}\hlstd{(}\hlkwc{ymin} \hlstd{= Anomaly10y} \hlopt{-} \hlstd{Unc10y,}
        \hlkwc{ymax} \hlstd{= Anomaly10y} \hlopt{+} \hlstd{Unc10y),}
        \hlkwc{fill} \hlstd{=} \hlstr{"blue"}\hlstd{,} \hlkwc{alpha} \hlstd{=} \hlnum{.1}\hlstd{)} \hlopt{+}
    \hlkwd{geom_line}\hlstd{(}\hlkwc{color} \hlstd{=} \hlstr{"steelblue"}\hlstd{)}
\end{alltt}
\end{kframe}

{\centering \includegraphics[width=.75\linewidth]{figure/lineb-1}

}

\end{knitrout}
\end{frame}

% --------------------------------------------------------------

\begin{frame}[fragile]
\frametitle{Exercise 2}
\begin{itemize}
\item Modify the previous plot and change it such that there are three lines instead of one with a confidence band.
\end{itemize}
\begin{knitrout}\footnotesize
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}

{\centering \includegraphics[width=.75\linewidth]{figure/ex2-1}

}

\end{knitrout}
\end{frame}

% --------------------------------------------------------------
% --------------------------------------------------------------

\section*{Bar plots}
\frame{\sectionpage}

% --------------------------------------------------------------
% --------------------------------------------------------------

\begin{frame}[fragile]
\begin{knitrout}\footnotesize
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{alltt}
\hlkwd{ggplot}\hlstd{(iris,} \hlkwd{aes}\hlstd{(Species, Sepal.Length))} \hlopt{+}
        \hlkwd{geom_bar}\hlstd{(}\hlkwc{stat} \hlstd{=} \hlstr{"identity"}\hlstd{)}
\end{alltt}
\end{kframe}

{\centering \includegraphics[width=.75\linewidth]{figure/barone-1}

}

\end{knitrout}

\end{frame}

% --------------------------------------------------------------

\begin{frame}[fragile]
\begin{knitrout}\footnotesize
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{alltt}
\hlkwd{ggplot}\hlstd{(df,} \hlkwd{aes}\hlstd{(Species, measurement,} \hlkwc{fill} \hlstd{= flower_attribute))} \hlopt{+}
    \hlkwd{geom_bar}\hlstd{(}\hlkwc{stat} \hlstd{=} \hlstr{"identity"}\hlstd{)}
\end{alltt}
\end{kframe}

{\centering \includegraphics[width=.75\linewidth]{figure/bartwo-1}

}

\end{knitrout}
\end{frame}

% --------------------------------------------------------------
% http://stackoverflow.com/questions/11604070/issue-with-ggplot2-geom-bar-and-position-dodge-stacked-has-correct-y-values

\begin{frame}[fragile]
\begin{knitrout}\footnotesize
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{alltt}
\hlkwd{ggplot}\hlstd{(df,} \hlkwd{aes}\hlstd{(Species, measurement,} \hlkwc{fill} \hlstd{= flower_attribute))} \hlopt{+}
    \hlkwd{geom_bar}\hlstd{(}\hlkwc{stat} \hlstd{=} \hlstr{"identity"}\hlstd{,} \hlkwc{position} \hlstd{=} \hlstr{"dodge"}\hlstd{)}
\end{alltt}
\end{kframe}

{\centering \includegraphics[width=.75\linewidth]{figure/barthree-1}

}

\end{knitrout}
What's going on with the y axis?
\end{frame}

% --------------------------------------------------------------

\begin{frame}[fragile]
\begin{knitrout}\footnotesize
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{alltt}
\hlkwd{ggplot}\hlstd{(df,} \hlkwd{aes}\hlstd{(Species, measurement,} \hlkwc{fill} \hlstd{= flower_attribute))} \hlopt{+}
    \hlkwd{geom_bar}\hlstd{(}\hlkwc{stat} \hlstd{=} \hlstr{"identity"}\hlstd{,} \hlkwc{position}\hlstd{=}\hlstr{"dodge"}\hlstd{,} \hlkwc{color}\hlstd{=}\hlstr{"black"}\hlstd{)}
\end{alltt}
\end{kframe}

{\centering \includegraphics[width=.75\linewidth]{figure/barthree2-1}

}

\end{knitrout}
\end{frame}

% --------------------------------------------------------------

\begin{frame}[fragile]
\frametitle{Exercise 3}
Using the d2 dataset you created earlier, generate this plot below. Take a quick look at the data first to see if it needs to be binned.
\begin{knitrout}\footnotesize
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}

{\centering \includegraphics[width=\maxwidth]{figure/ex3-1}

}

\end{knitrout}
\end{frame}

% --------------------------------------------------------------

\begin{frame}[fragile]
\frametitle{Exercise 4}
\begin{itemize}
\item Use \texttt{dplyr} to calculate the mean and standard deviation of petal length by species.\\
\begin{knitrout}\footnotesize
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{alltt}
\hlstd{agg} \hlkwb{<-} \hlstd{iris} \hlopt{%>%}
        \hlkwd{group_by}\hlstd{(Species)} \hlopt{%>%}
        \hlkwd{summarise}\hlstd{(}\hlkwc{mean.petal.length} \hlstd{=} \hlkwd{mean}\hlstd{(Petal.Length),}
        \hlkwc{sd.petal.length} \hlstd{=} \hlkwd{sd}\hlstd{(Petal.Length))}
\hlcom{# ?geom_errorbar()}
\end{alltt}
\end{kframe}
\end{knitrout}

\begin{knitrout}\footnotesize
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}

{\centering \includegraphics[width=.75\linewidth]{figure/ex5-1}

}

\end{knitrout}

\end{itemize}
\end{frame}

% --------------------------------------------------------------

\begin{frame}[fragile]
\frametitle{Exercise 5}
\begin{itemize}
\item Using the climate dataset, create a new variable called sign. Make it logical (true/false) based on the sign of Anomaly10y.
\item Plot a bar plot and use \texttt{sign} variable as the fill.\\
\begin{knitrout}\footnotesize
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}

{\centering \includegraphics[width=.75\linewidth]{figure/ex4-1}

}

\end{knitrout}

\end{itemize}
\end{frame}

% --------------------------------------------------------------
% --------------------------------------------------------------

\section*{Density Plots}
\frame{\sectionpage}

% --------------------------------------------------------------
% --------------------------------------------------------------

\begin{frame}[fragile]
\frametitle{Density plots}
\begin{knitrout}\footnotesize
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{alltt}
\hlkwd{ggplot}\hlstd{(faithful,} \hlkwd{aes}\hlstd{(waiting))} \hlopt{+} \hlkwd{geom_density}\hlstd{()}
\end{alltt}
\end{kframe}

{\centering \includegraphics[width=.75\linewidth]{figure/densityone-1}

}

\end{knitrout}
\end{frame}

% --------------------------------------------------------------

\begin{frame}[fragile]
\frametitle{Density plots}
\begin{knitrout}\footnotesize
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{alltt}
\hlkwd{ggplot}\hlstd{(faithful,} \hlkwd{aes}\hlstd{(waiting))} \hlopt{+}
    \hlkwd{geom_density}\hlstd{(}\hlkwc{fill} \hlstd{=} \hlstr{"blue"}\hlstd{,} \hlkwc{alpha} \hlstd{=} \hlnum{0.1}\hlstd{)}
\end{alltt}
\end{kframe}

{\centering \includegraphics[width=.75\linewidth]{figure/densityonefove-1}

}

\end{knitrout}
\end{frame}

% --------------------------------------------------------------

\begin{frame}[fragile]
\begin{knitrout}\footnotesize
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{alltt}
\hlkwd{ggplot}\hlstd{(faithful,} \hlkwd{aes}\hlstd{(waiting))} \hlopt{+}
    \hlkwd{geom_line}\hlstd{(}\hlkwc{stat} \hlstd{=} \hlstr{"density"}\hlstd{)}
\end{alltt}
\end{kframe}

{\centering \includegraphics[width=.75\linewidth]{figure/densitytwo-1}

}

\end{knitrout}
\end{frame}

% --------------------------------------------------------------
% --------------------------------------------------------------

\section*{Adding smoothers}
\frame{\sectionpage}

% --------------------------------------------------------------
% --------------------------------------------------------------

\begin{frame}[fragile]
\begin{knitrout}\footnotesize
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{alltt}
\hlkwd{ggplot}\hlstd{(iris,} \hlkwd{aes}\hlstd{(Sepal.Length, Sepal.Width,} \hlkwc{color} \hlstd{= Species))} \hlopt{+}
    \hlkwd{geom_point}\hlstd{(}\hlkwd{aes}\hlstd{(}\hlkwc{shape} \hlstd{= Species),} \hlkwc{size} \hlstd{=} \hlnum{3}\hlstd{)} \hlopt{+}
    \hlkwd{geom_smooth}\hlstd{(}\hlkwc{method} \hlstd{=} \hlstr{"lm"}\hlstd{)}
\end{alltt}
\end{kframe}

{\centering \includegraphics[width=.75\linewidth]{figure/adding_stats-1}

}

\end{knitrout}
\end{frame}

% --------------------------------------------------------------

\begin{frame}[fragile]
\begin{knitrout}\footnotesize
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{alltt}
\hlkwd{ggplot}\hlstd{(iris,} \hlkwd{aes}\hlstd{(Sepal.Length, Sepal.Width,} \hlkwc{color} \hlstd{= Species))} \hlopt{+}
    \hlkwd{geom_point}\hlstd{(}\hlkwd{aes}\hlstd{(}\hlkwc{shape} \hlstd{= Species),} \hlkwc{size} \hlstd{=} \hlnum{3}\hlstd{)} \hlopt{+}
    \hlkwd{geom_smooth}\hlstd{(}\hlkwc{method} \hlstd{=} \hlstr{"lm"}\hlstd{)} \hlopt{+}
    \hlkwd{facet_grid}\hlstd{(.} \hlopt{~} \hlstd{Species)}
\end{alltt}
\end{kframe}

{\centering \includegraphics[width=.75\linewidth]{figure/adding_stats2-1}

}

\end{knitrout}
\end{frame}

% --------------------------------------------------------------
% --------------------------------------------------------------

\section*{Themes}
\frame{\sectionpage}

% --------------------------------------------------------------
% --------------------------------------------------------------

\begin{frame}[fragile]
\frametitle{Adding themes}
Themes are a great way to define custom plots.
\begin{knitrout}\footnotesize
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{alltt}
\hlopt{+} \hlkwd{theme}\hlstd{()}
\hlcom{# see ?theme() for more options}
\end{alltt}
\end{kframe}
\end{knitrout}
\end{frame}

% --------------------------------------------------------------

\begin{frame}[fragile]
\frametitle{A more basic theme}
\begin{knitrout}\footnotesize
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{alltt}
\hlkwd{ggplot}\hlstd{(iris,} \hlkwd{aes}\hlstd{(Sepal.Length, Sepal.Width,} \hlkwc{color} \hlstd{= Species))} \hlopt{+}
    \hlkwd{geom_point}\hlstd{(}\hlkwc{size} \hlstd{=} \hlnum{1.2}\hlstd{,} \hlkwc{shape} \hlstd{=} \hlnum{16}\hlstd{)} \hlopt{+}
    \hlkwd{facet_wrap}\hlstd{(} \hlopt{~} \hlstd{Species)} \hlopt{+}
    \hlkwd{theme_bw}\hlstd{()}
\end{alltt}
\end{kframe}

{\centering \includegraphics[width=.75\linewidth]{figure/facet_wrapbw_theme-1}

}

\end{knitrout}
\end{frame}

% --------------------------------------------------------------

\begin{frame}[fragile]
\frametitle{A themed plot}
\begin{knitrout}\footnotesize
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{alltt}
\hlkwd{ggplot}\hlstd{(iris,} \hlkwd{aes}\hlstd{(Sepal.Length, Sepal.Width,} \hlkwc{color} \hlstd{= Species))} \hlopt{+}
    \hlkwd{geom_point}\hlstd{(}\hlkwc{size} \hlstd{=} \hlnum{1.2}\hlstd{,} \hlkwc{shape} \hlstd{=} \hlnum{16}\hlstd{)} \hlopt{+}
    \hlkwd{facet_wrap}\hlstd{(} \hlopt{~} \hlstd{Species)} \hlopt{+}
    \hlkwd{theme}\hlstd{(}\hlkwc{legend.key} \hlstd{=} \hlkwd{element_rect}\hlstd{(}\hlkwc{fill} \hlstd{=} \hlnum{NA}\hlstd{),}
        \hlkwc{legend.position} \hlstd{=} \hlstr{"bottom"}\hlstd{,}
        \hlkwc{strip.background} \hlstd{=} \hlkwd{element_rect}\hlstd{(}\hlkwc{fill} \hlstd{=} \hlnum{NA}\hlstd{),}
        \hlkwc{axis.title.y} \hlstd{=} \hlkwd{element_text}\hlstd{(}\hlkwc{angle} \hlstd{=} \hlnum{0}\hlstd{))}
\end{alltt}
\end{kframe}
\end{knitrout}
\end{frame}

% --------------------------------------------------------------

\begin{frame}[fragile]
\frametitle{A themed plot}
\begin{knitrout}\footnotesize
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}
\includegraphics[width=.75\linewidth]{figure/facet_wrap_theme_execc-1}

\end{knitrout}
\end{frame}

% --------------------------------------------------------------

\begin{frame}[fragile]
\frametitle{ggthemes library}
\begin{knitrout}\footnotesize
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{alltt}
\hlkwd{install.packages}\hlstd{(}\hlstr{'ggthemes'}\hlstd{)}
\hlkwd{library}\hlstd{(ggthemes)}
\hlcom{# Then add one of these themes to your plot}
 \hlopt{+} \hlkwd{theme_stata}\hlstd{()}
 \hlopt{+} \hlkwd{theme_excel}\hlstd{()}
 \hlopt{+} \hlkwd{theme_wsj}\hlstd{()}
 \hlopt{+} \hlkwd{theme_solarized}\hlstd{()}
\end{alltt}
\end{kframe}
\end{knitrout}
\end{frame}

% --------------------------------------------------------------

\begin{frame}[fragile]
\frametitle{Fan of Wes Anderson movies?}
\begin{center}
\includegraphics[scale=.12]{images/tenenbaums.png}
\end{center}
\end{frame}

% --------------------------------------------------------------

\begin{frame}[fragile]
\frametitle{Yup, that's a thing}
\begin{center}
\begin{knitrout}\footnotesize
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{alltt}
\hlcom{# install.packages('wesanderson')}
\hlkwd{library}\hlstd{(}\hlstr{"wesanderson"}\hlstd{)}
\hlcom{# display a palette}
\hlkwd{wes_palette}\hlstd{(}\hlstr{"Royal1"}\hlstd{)}
\end{alltt}
\end{kframe}

{\centering \includegraphics[width=.75\linewidth]{figure/facet_wrap_theme_exec_royal-1}

}

\end{knitrout}
\end{center}
\end{frame}

% --------------------------------------------------------------
% --------------------------------------------------------------

\section*{Create functions to automate your plotting}
\frame{\sectionpage}

% --------------------------------------------------------------
% --------------------------------------------------------------

\begin{frame}[fragile]
\frametitle{Write functions for day to day plots}
\begin{knitrout}\footnotesize
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{alltt}
\hlstd{my_custom_plot} \hlkwb{<-} \hlkwa{function}\hlstd{(}\hlkwc{df}\hlstd{,} \hlkwc{title} \hlstd{=} \hlstr{""}\hlstd{,} \hlkwc{...}\hlstd{) \{}
    \hlkwd{ggplot}\hlstd{(df, ...)} \hlopt{+}
    \hlkwd{ggtitle}\hlstd{(title)} \hlopt{+}
    \hlkwd{whatever_geoms}\hlstd{()} \hlopt{+}
    \hlkwd{theme}\hlstd{(...)}
\hlstd{\}}
\end{alltt}
\end{kframe}
\end{knitrout}

Then just call your function to generate a plot.
It's a lot easier to fix one function that do it over and over for many plots
\begin{knitrout}\footnotesize
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{alltt}
\hlstd{plot1} \hlkwb{<-} \hlkwd{my_custom_plot}\hlstd{(dataset1,} \hlkwc{title} \hlstd{=} \hlstr{"Figure 1"}\hlstd{)}
\end{alltt}
\end{kframe}
\end{knitrout}

\end{frame}

% --------------------------------------------------------------
% --------------------------------------------------------------

\section*{Publication quality figures}
\frame{\sectionpage}

% --------------------------------------------------------------
% --------------------------------------------------------------

% How to save your plots

\begin{frame}[fragile]
\begin{itemize}
\item If the plot is on your screen
\begin{knitrout}\footnotesize
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{alltt}
\hlkwd{ggsave}\hlstd{(}\hlstr{'~/path/to/figure/filename.png'}\hlstd{)}
\end{alltt}
\end{kframe}
\end{knitrout}
\item If your plot is assigned to an object
\begin{knitrout}\footnotesize
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{alltt}
\hlkwd{ggsave}\hlstd{(plot1,} \hlkwc{file} \hlstd{=} \hlstr{"~/path/to/figure/filename.png"}\hlstd{)}
\end{alltt}
\end{kframe}
\end{knitrout}

\item Specify a size
\begin{knitrout}\footnotesize
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{alltt}
\hlkwd{ggsave}\hlstd{(}\hlkwc{file} \hlstd{=} \hlstr{"/path/to/figure/filename.png"}\hlstd{,} \hlkwc{width} \hlstd{=} \hlnum{6}\hlstd{,}
\hlkwc{height} \hlstd{=}\hlnum{4}\hlstd{)}
\end{alltt}
\end{kframe}
\end{knitrout}
\item or any format (pdf, png, eps, svg, jpg)
\begin{knitrout}\footnotesize
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{alltt}
\hlkwd{ggsave}\hlstd{(}\hlkwc{file} \hlstd{=} \hlstr{"/path/to/figure/filename.eps"}\hlstd{)}
\hlkwd{ggsave}\hlstd{(}\hlkwc{file} \hlstd{=} \hlstr{"/path/to/figure/filename.jpg"}\hlstd{)}
\hlkwd{ggsave}\hlstd{(}\hlkwc{file} \hlstd{=} \hlstr{"/path/to/figure/filename.pdf"}\hlstd{)}
\end{alltt}
\end{kframe}
\end{knitrout}
\end{itemize}
\end{frame}

% --------------------------------------------------------------

\begin{frame}[fragile]
\frametitle{Further help}
\begin{itemize}
\item You've just scratched the surface with ggplot2.
\item Practice
\item Read the docs (either locally in \texttt{R} or at \url{http://docs.ggplot2.org/current/})
\item Work together
\end{itemize}
\begin{center}
\includegraphics[scale=.15]{images/chang_book.png}
\includegraphics[scale=.15]{images/hadley.png}
\end{center}
\end{frame}

% --------------------------------------------------------------

\begin{frame}[fragile]
\frametitle{ggplot2 Help Pages}
\begin{center}
\includegraphics[scale=.5]{images/ggplot_help.png}
\end{center}
\end{frame}

% --------------------------------------------------------------

\begin{frame}[fragile]
\frametitle{StackOverflow}
\begin{center}
\includegraphics[scale=.35]{images/stackoverflow.png}
\end{center}
\end{frame}

% --------------------------------------------------------------
% end, hope it was useful.
\end{document}


text:
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{lmodern}
\usepackage[a4paper, margin=1in]{geometry}
\usepackage{dirtree}
\usepackage{xcolor}
\usepackage{listings}
\usepackage{tabulary}
\usepackage{pdfpages}
\newcommand\myicon[1]{{\color{#1}\rule{2ex}{2ex}}}
\newcommand{\myfolder}[2]{\myicon{#1}\ {#2}}
\usepackage{minted}
\large
\title{C++ Assignment 1}

\setcounter{secnumdepth}{5}
\setcounter{tocdepth}{5}
\setlength{\parindent}{0em}
\setlength{\parskip}{1em}

\definecolor{codegreen}{rgb}{0,0.6,0}
\definecolor{codegray}{rgb}{0.5,0.5,0.5}
\definecolor{codepurple}{rgb}{0.58,0,0.82}
\definecolor{backcolour}{rgb}{0.95,0.95,0.92}

\lstdefinestyle{mystyle}{
    backgroundcolor=\color{backcolour},
    commentstyle=\color{codegreen},
    keywordstyle=\color{magenta},
    numberstyle=\tiny\color{codegray},
    stringstyle=\color{codepurple},
    basicstyle=\ttfamily\footnotesize,
    breakatwhitespace=false,
    breaklines=true,
    captionpos=b,
    keepspaces=true,
    numbers=left,
    numbersep=5pt,
    showspaces=false,
    showstringspaces=false,
    showtabs=false,
    tabsize=2
}

\lstset{style=mystyle}

\begin{document}
\begin{titlepage}
	\begin{center}
    \line(1,0){300}\\
    [0.65cm]
	\huge{\bfseries ICT374 - Assignment II}\\
	\line(1,0){300}\\
	\textsc{\Large FTP Server and Client}\\
	\textsc{\LARGE \today}\\
	[5.5cm]
	\end{center}
	\begin{flushright}
		\textsc{\Large Kiera Gibson\\33582181}\\
		[0.5cm]
		\textsc{\Large Peter S. Crabbe\\32019269}\\
		[0.5cm]
	\end{flushright}
\end{titlepage}

\tableofcontents
\section{Project Declaration}
\includepdf[pages=-]{ICT374ProjectDeclaration}
\newpage
\section{List of Files}
\dirtree{%
.1 \myfolder{red}{Assignment 2}.
.2 \myfolder{blue}{client}.
.3 \myfolder{green}{client.h}.
.3 \myfolder{green}{client.c}.
.3 \myfolder{green}{main.h}.
.3 \myfolder{green}{main.c}.
.2 \myfolder{blue}{server}.
.3 \myfolder{green}{main.h}.
.3 \myfolder{green}{main.c}.
.2 \myfolder{blue}{shared}.
.3 \myfolder{green}{include}.
.4 \myfolder{orange}{shared.h}.
.4 \myfolder{orange}{token.h}.
.4 \myfolder{orange}{directory\_handling.h}.
.3 \myfolder{green}{src}.
.4 \myfolder{orange}{shared.c}.
.4 \myfolder{orange}{token.c}.
.4 \myfolder{orange}{directory\_handling.c}.
.2 \myfolder{blue}{lib}.
.3 \myfolder{green}{json-c}.
.3 \myfolder{green}{base64}.
.2 \myfolder{blue}{documentation}.
.3 \myfolder{green}{Assignment2.tex}.
}

\section{PreInformation}
Extension from the Unit Coordinator was given and is attached below. \\
\includegraphics[width=\textwidth]{extension}

The group also asked permission to use CMake to generate the Make file. Hong Advised as long as it can make a make file and build using make this was acceptable. The guide on how to use Cmake is in the Building section.\\
\includegraphics[width=\textwidth]{make}

The group also asked that we be able to use JSON for our messaging. This allowed us to simplify our string parsing. Permission was granted. This also meant we needed to use an encoder for binary data as any null terminators would break our JSON stream. Attached is the email approving this.\\
\includegraphics[width=\textwidth]{json}

\section{Information}
Design and implement a simple network protocol that can be used to download files from a remote site and to upload files to a remote site, and a client and a server programs that communicate using that protocol. The protocol is using TCP as its transport layer protocol. The server can have multiple clients request simultaneously. For simplicity we did not consider any authentication process in this project, hence the server will provide its service to any client with the right site address and port number.

\section{Self Diagnosis and Evaluation}
\subsection{Working}
\begin{itemize}
\item The way we have implemented our code makes it portable while also being cross platform on both macOS to Linux. This does make it more complicated and with out extensive checking possibly more error prone.
\item Using a shared library between our client and our server gives us the ability to keep shared code consistent between both the server and client. This avoids any issues of changes to one causing unpredictable behaviour in the other.
\item Using a third party library for serialisation and deserialisation means that our backbone is robust and simpler to parse. This removes any headaches that come with parsing strings in C.
\item All functions that are required are implemented and working. This includes PUT, GET, CD, LCD, DIR, LDIR, PWD, LPWD and QUIT.
\item PUT and GET work with both text and binary data.
\item The server is able to work across the internet and has been tested with multiple clients connecting at the same time with no issues.
\end{itemize}

\subsection{Not Working}
\begin{itemize}
    \item While the program can reap child processes, Due to the socket blocking it wont be able to end our connection while loop until another client attempts to connect. Releasing the block and allowing the program to reap its children. Had we more time this could have been easily been fixed.
    \item Both Put and Get will not work from files from different folders that are not in the current working directory. This is due to the way we handle the transfer of data.
\end{itemize}

\section{Solution Breakdown}
The solution devised is that there is a client and a server program. However, a large chunk of code is required in both. We needed to ensure that the client and the server followed the protocols and any under the hood changes to one side didn't break the other. This was solved by having our own shared library that both programs pull down from. By doing this way, refactoring chunks of code can be achieved with out breaking the functions calling them.\\

The underlying data structure for communication from client and server is JSON. This allows us to use key data pairs. If a key exists the data corresponding to the key must exist. This ensures that parsing data is simple, safe and effective. The reason this is safer is because we are able to stop a function if a key is missing and instead report and error.\\

A short fall in using JSON is that any string must only be null terminated once. This means that binary data is dangerous being stored in a json string. To ensure avoiding this limitation, we encode our data into base64. While this can give us a 40\% overhead on file size at the absolute worst, this ensures that the JSON payload wont break during transmission. We believe that the trade off is worth the reliability that JSON offers.

\section{Protocol}
\subsection{Commands and JSON}
As mentioned prior, JSON is the backbone of the FTP client and server as it allows for serialisation and deserialisation of the data between the two. Another benefit of implementing JSON is that if an error occurs in this process we can also assume that the data sent was not completed.

Each bolded word in a dot point is a key value in the JSON.

\subsubsection{CD}
Changes the current directory on the server.

Client Sends.
\begin{itemize}
\item \textbf{command:} The command to be processed on the server.
\item \textbf{dir:} The directory to be changed into relative to the current directory.
\end{itemize}

Server Response.
\begin{itemize}
\item \textbf{error:} The error number reported by the operation of the function. 0 represents no error.
\end{itemize}

\subsubsection{DIR}
Lists all the the directories and file relative the current working directory on the server.

Client Sends.
\begin{itemize}
\item \textbf{command:} The command to be processed on the server.
\end{itemize}

Server Response.
\begin{itemize}
\item \textbf{directoryError:} An error if the directory fails to open accordingly.
\item \textbf{scandirError:} The error produced if the scan in the directory for files and folders fails. Anything above or equal to 0 is an error.
\item \textbf{arraySize:} The size of the array of directories.
\item \textbf{array:} The array of strings for each file / folder that is in the current working directory of the server.
\item \textbf{currentDirectory:} The current working directory of the server so the client knows the location of the output given.
\end{itemize}

\subsubsection{PWD}
Gives the absolute path to the current working directory of the server.

Client Sends
\begin{itemize}
\item \textbf{command:} The command to be processed on the server.
\end{itemize}

Server Response
\begin{itemize}
\item \textbf{cwd:} The current working directory of the server.
\item \textbf{error:} The error number reported by the operation of the function. 0 represents no error.
\end{itemize}

\subsubsection{PUT}
Takes a file from the client and places it on the server.

Client Sends.
\begin{itemize}
\item \textbf{command:} The command to be processed on the server.
\item \textbf{filename:} The file name to write the data too.
\item \textbf{filedata:} Data of the file that was sent, this is encoded in base64 to ensure that null terminators do not break the json string.
\item \textbf{ensize:} The encoded length of the string.
\item \textbf{desize:} The decoded length of the string.
\end{itemize}

Server Response.
\begin{itemize}
\item \textbf{error:} The error number reported by the operation of the function. 0 represents no error.
\end{itemize}

\subsubsection{GET}
Takes a file from the server and places it on the client.

Client Sends.
\begin{itemize}
\item \textbf{command:} The command to be processed on the server.
\end{itemize}

Server Reponse.
\begin{itemize}
\item \textbf{filename:} The file name to write the data too.
\item \textbf{filedata:} Data of the file that was sent, this is encoded in base64 to ensure that null terminators do not break the json string.
\item \textbf{ensize:} The encoded length of the string.
\item \textbf{desize:} The decoded length of the string.
\item \textbf{error:} The error number reported by the operation of the function. 0 represents no error.
\end{itemize}

\subsection{Send and Receive}
The functions listed above all use the existing TCP protocol implemented by the POSIX standards.
\subsubsection{Send Protocol}
The send protocol that is implemented following these rules. The protocol sends only JSON objects that have been deserialised.
\begin{enumerate}
    \item Attempt to send the size of the data the recipient needs to receive.
    \item Await a response to confirm the recipient is ready. If no value or a false value is received, terminate send.
    \item Recipient sends confirmation that it is ready.
    \item Send payload, deduct how many bytes were sent from the total until the total is equal to zero.
    \item Return 0 if success otherwise return -1.
\end{enumerate}
\subsubsection{Receive Protocol}
The receive protocol that is implemented following these rules. The protocol receives only JSON objects that have been deserialised. Once the final step is complete it is then serialised back into JSON to be parsed.
\begin{enumerate}
    \item Wait for sender to confirm the size of the data.
    \item If size is received acknowledge by sending true, else send false and terminate receive process.
    \item Await sender to begin transfer of data.
    \item Keep looping until the current size is equal to agreed upon size.
    \item If receive error, terminate; else update buffer parameter and return the size to the buffer.
\end{enumerate}
\section{Building}
\subsection{Dependencies}
\subsubsection*{Linux}
The following dependencies are required for Linux.
\begin{itemize}
    \item Cmake 3.14
    \item gcc or clang compiler
\end{itemize}
\begin{lstlisting}
        sudo apt install cmake
\end{lstlisting}
\subsubsection*{macOS}
\begin{itemize}
    \item Cmake 3.14
    \item Brew
    \item gcc or clang compiler
\end{itemize}
\begin{lstlisting}
        brew install cmake
\end{lstlisting}
\subsection{Building}
\begin{center}
\textbf{Please ensure you have the dependencies before you continue.}
\end{center}
To generate the build scripts please run from the root directory....
\begin{lstlisting}
cmake -S . -B build -D CMAKE_BUILD_TYPE=Release
\end{lstlisting}
Change into the build directory
\begin{lstlisting}
cd build/
\end{lstlisting}
Now call make to begin the compilation process like so.
\begin{lstlisting}
make myftp myftpd
\end{lstlisting}
The compiler should have produced 2 unix executables, myftp is the client program and myftpd is the server program. Below is the build output of the make file that was compiled with "-Wall -Wextra" flags showing the program compiles with no warnings or errors. The program was also ran using Valgrind to find and fix any memory leaks.

\begin{lstlisting}
Scanning dependencies of target base64
[  1%] Building C object lib/base64/CMakeFiles/base64.dir/lib/arch/avx2/codec.c.o
[  3%] Building C object lib/base64/CMakeFiles/base64.dir/lib/arch/generic/codec.c.o
[  5%] Building C object lib/base64/CMakeFiles/base64.dir/lib/arch/neon32/codec.c.o
[  7%] Building C object lib/base64/CMakeFiles/base64.dir/lib/arch/neon64/codec.c.o
[  9%] Building C object lib/base64/CMakeFiles/base64.dir/lib/arch/ssse3/codec.c.o
[ 11%] Building C object lib/base64/CMakeFiles/base64.dir/lib/arch/sse41/codec.c.o
[ 13%] Building C object lib/base64/CMakeFiles/base64.dir/lib/arch/sse42/codec.c.o
[ 15%] Building C object lib/base64/CMakeFiles/base64.dir/lib/arch/avx/codec.c.o
[ 17%] Building C object lib/base64/CMakeFiles/base64.dir/lib/lib.c.o
[ 19%] Building C object lib/base64/CMakeFiles/base64.dir/lib/codec_choose.c.o
[ 21%] Building C object lib/base64/CMakeFiles/base64.dir/lib/tables/tables.c.o
[ 23%] Linking C static library libbase64.a
[ 23%] Built target base64
Scanning dependencies of target json-c
[ 25%] Building C object lib/json-c/CMakeFiles/json-c.dir/arraylist.c.o
[ 27%] Building C object lib/json-c/CMakeFiles/json-c.dir/debug.c.o
[ 29%] Building C object lib/json-c/CMakeFiles/json-c.dir/json_c_version.c.o
[ 31%] Building C object lib/json-c/CMakeFiles/json-c.dir/json_object.c.o
[ 33%] Building C object lib/json-c/CMakeFiles/json-c.dir/json_object_iterator.c.o
[ 35%] Building C object lib/json-c/CMakeFiles/json-c.dir/json_pointer.c.o
[ 37%] Building C object lib/json-c/CMakeFiles/json-c.dir/json_tokener.c.o
[ 39%] Building C object lib/json-c/CMakeFiles/json-c.dir/json_util.c.o
[ 41%] Building C object lib/json-c/CMakeFiles/json-c.dir/json_visit.c.o
[ 43%] Building C object lib/json-c/CMakeFiles/json-c.dir/linkhash.c.o
[ 45%] Building C object lib/json-c/CMakeFiles/json-c.dir/printbuf.c.o
[ 47%] Building C object lib/json-c/CMakeFiles/json-c.dir/random_seed.c.o
[ 49%] Building C object lib/json-c/CMakeFiles/json-c.dir/strerror_override.c.o
[ 50%] Linking C shared library libjson-c.dylib
[ 50%] Built target json-c
Scanning dependencies of target myftp-shared
[ 52%] Building C object shared/CMakeFiles/myftp-shared.dir/src/shared.c.o
[ 54%] Building C object shared/CMakeFiles/myftp-shared.dir/src/token.c.o
[ 56%] Building C object shared/CMakeFiles/myftp-shared.dir/src/directory_handling.c.o
[ 58%] Linking C static library libmyftp-shared.a
[ 58%] Built target myftp-shared
Scanning dependencies of target myftp
[ 60%] Building C object CMakeFiles/myftp.dir/client/main.c.o
[ 62%] Building C object CMakeFiles/myftp.dir/client/client.c.o
[ 64%] Linking C executable myftp
[ 64%] Built target myftp
Scanning dependencies of target myftpd
[ 66%] Building C object CMakeFiles/myftpd.dir/server/main.c.o
[ 68%] Linking C executable myftpd
[ 68%] Built target myftpd
Scanning dependencies of target json-c-static
[ 70%] Building C object lib/json-c/CMakeFiles/json-c-static.dir/arraylist.c.o
[ 72%] Building C object lib/json-c/CMakeFiles/json-c-static.dir/debug.c.o
[ 74%] Building C object lib/json-c/CMakeFiles/json-c-static.dir/json_c_version.c.o
[ 76%] Building C object lib/json-c/CMakeFiles/json-c-static.dir/json_object.c.o
[ 78%] Building C object lib/json-c/CMakeFiles/json-c-static.dir/json_object_iterator.c.o
[ 80%] Building C object lib/json-c/CMakeFiles/json-c-static.dir/json_pointer.c.o
[ 82%] Building C object lib/json-c/CMakeFiles/json-c-static.dir/json_tokener.c.o
[ 84%] Building C object lib/json-c/CMakeFiles/json-c-static.dir/json_util.c.o
[ 86%] Building C object lib/json-c/CMakeFiles/json-c-static.dir/json_visit.c.o
[ 88%] Building C object lib/json-c/CMakeFiles/json-c-static.dir/linkhash.c.o
[ 90%] Building C object lib/json-c/CMakeFiles/json-c-static.dir/printbuf.c.o
[ 92%] Building C object lib/json-c/CMakeFiles/json-c-static.dir/random_seed.c.o
[ 94%] Building C object lib/json-c/CMakeFiles/json-c-static.dir/strerror_override.c.o
[ 96%] Linking C static library libjson-c.a
[ 96%] Built target json-c-static
Scanning dependencies of target json_parse
[ 98%] Building C object lib/json-c/apps/CMakeFiles/json_parse.dir/json_parse.c.o
[100%] Linking C executable ../../../json_parse
[100%] Built target json_parse
\end{lstlisting}

\section{Executing}
\subsection{Server}
To run the server just execute myftpd, no additional information is required.
\begin{lstlisting}
    ./myftpd
\end{lstlisting}
\subsection{Client}
Running the client, an IP address will need to be parsed in should you wish to connect to a server that is not local. Failing to provide an IP address on the first argument will result in the IP being bound to 127.0.0.1.

Example of setting an ip...
\begin{lstlisting}
    ./myftp 1.1.1.1
\end{lstlisting}
or
\begin{lstlisting}
    ./myftp arkwolf.com
\end{lstlisting}

\section{Test Evidence}
\subsection{User Testing}
%
%\textbf{Task:} \\
%\textbf{Action:} \\
%\textbf{Result:} \\

\textbf{Task:} Execute Client\\
\textbf{Action:} User input into shell "./myftp"\\
\textbf{Result:} Was able to connect to the local myftpd server when the server was running on my local machine.\\
\includegraphics[width=\textwidth]{testpictures/connect}

\textbf{Task:} Execute Client with DNS\\
\textbf{Action:} User Input into shell "./myftp arkwolf.com"\\
\textbf{Result:} Was able to connect to the remote server myftpd server when the server was running on my remote machine.\\
\includegraphics[width=\textwidth]{testpictures/connect}

\textbf{Task:} Test the pwd command to the server.\\
\textbf{Action:} pwd\\
\textbf{Result:} The server returned its current working directory and performed as expected. Output: /Users/arkwolf/Documents/Coding Schoolwork/ICT374-Assignment2-AKFTP/cmake-build-debug/final/server\\
\includegraphics[width=\textwidth]{testpictures/pwd}

\textbf{Task:} Test the lpwd command to the client.\\
\textbf{Action:} lpwd\\
\textbf{Result:} The client returned its current working directory and performed as expected. Output: /Users/arkwolf/cuments/Coding/Schoolwork/ICT374-Assignment2-AKFTP/cmake-build-debug/final/client\\
\includegraphics[width=\textwidth]{testpictures/lpwd}

\textbf{Task:} Change the directory using the CD command.\\
\textbf{Action:} cd ../\\
\textbf{Result:} No output, indicating a success.\\
\includegraphics[width=\textwidth]{testpictures/cdserver}

\textbf{Task:} Change the directory using the local cd command\\
\textbf{Action:} lcd ../\\
\textbf{Result:} No output, indicating a success.\\
\includegraphics[width=\textwidth]{testpictures/lcd}

\textbf{Task:} Get a list of the directories inside the servers current working directory.\\
\textbf{Action:} dir\\
\textbf{Result:} The server returned a list of its folders and files at its current working directory as expected.\\
\includegraphics[width=\textwidth]{testpictures/dir}

\textbf{Task:} Get a list of the directories inside the clients current working directory.\\\
\textbf{Action:} ldir\\
\textbf{Result:} The client returned a list of its folders and files at its current working directory as expected.\\
\includegraphics[width=\textwidth]{testpictures/ldir}

\textbf{Task:} Upload a text file.\\
\textbf{Action:} put touch.txt\\
\textbf{Result:} The text file from the clients working directory was uploaded to the servers local directory.\\
\includegraphics[width=\textwidth]{testpictures/puttext}

\textbf{Task:} Upload a binary file\\
\textbf{Action:} put myftpd\\
\textbf{Result:} The binary file from the clients working directory was uploaded to the servers local directory.\\
\includegraphics[width=\textwidth]{testpictures/putbinary}

\textbf{Task:} Download a text file\\
\textbf{Action:} get touch.txt\\
\textbf{Result:} The text file from the servers working directory was downloaded to the clients local directory.\\
\includegraphics[width=\textwidth]{testpictures/gettext}

\textbf{Task:} Download a binary file\\
\textbf{Action:} get myftpd\\
\textbf{Result:} The binary file from the servers working directory was downloaded to the clients local directory.\\
\includegraphics[width=\textwidth]{testpictures/getbinary}

\textbf{Task:} Download a file with spaces\\
\textbf{Action:} get "space pic.jpg"\\
\textbf{Result:} The binary file with spaces in the filename from the servers working directory was downloaded to the clients local directory.\\
\includegraphics[width=\textwidth]{testpictures/space_get}

\textbf{Task:} Upload a file with spaces\\
\textbf{Action:} put "space pic.jpg"\\
\textbf{Result:} The binary file with spaces in the filename from the clients working directory was uploaded to the servers local directory.\\
\includegraphics[width=\textwidth]{testpictures/space_put}

\newpage
\section{Source Code Listing}
\subsection{Client}
    \subsubsection{main.c}
	\lstinputlisting[language=C]{../client/main.c}
	\subsubsection{client.c}
	\lstinputlisting[language=C]{../client/client.c}
\subsection{Server}
    \subsubsection{main.c}
	\lstinputlisting[language=C]{../server/main.c}
\subsection{Shared}
    \subsubsection{shared.c}
	\lstinputlisting[language=C]{../shared/src/shared.c}
	\subsubsection{token.c}
	\lstinputlisting[language=C]{../shared/src/token.c}
	\subsubsection{directory\_handling.c}
	\lstinputlisting[language=C]{../shared/src/directory_handling.c}

\section{Third-Party Source Code}
\subsection{json-c}
JSON library used under MIT license.\\
Thank you to all the contributors.\\
https://github.com/json-c/json-c/\\
\subsection{base64}
Base 64 encorder used to encode and decode our data streams.\\
Licensed under BSD-Clause "Simplified" License.\\
Thank you to all the contributors.\\
https://github.com/aklomp/base64\\
\end{document}

max_stars_repo_name: MajorArkwolf/AKFTP

max_issues_repo_name: MajorArkwolf/AKFTP

max_forks_repo_name: MajorArkwolf/AKFTP