\documentclass[10pt,a4paper]{article} % Packages \usepackage{fancyhdr} % For header and footer \usepackage{multicol} % Allows multicols in tables \usepackage{tabularx} % Intelligent column widths \usepackage{tabulary} % Used in header and footer \usepackage{hhline} % Border under tables \usepackage{graphicx} % For images \usepackage{xcolor} % For hex colours %\usepackage[utf8x]{inputenc} % For unicode character support \usepackage[T1]{fontenc} % Without this we get weird character replacements \usepackage{colortbl} % For coloured tables \usepackage{setspace} % For line height \usepackage{lastpage} % Needed for total page number \usepackage{seqsplit} % Splits long words. %\usepackage{opensans} % Can't make this work so far. Shame. Would be lovely. \usepackage[normalem]{ulem} % For underlining links % Most of the following are not required for the majority % of cheat sheets but are needed for some symbol support. \usepackage{amsmath} % Symbols \usepackage{MnSymbol} % Symbols \usepackage{wasysym} % Symbols %\usepackage[english,german,french,spanish,italian]{babel} % Languages % Document Info \author{Jeffrey M. Pisklak (non\_human\_entity)} \pdfinfo{ /Title (r-cheat-sheet.pdf) /Creator (Cheatography) /Author (Jeffrey M. Pisklak (non\_human\_entity)) /Subject (R Cheat Sheet) } % Lengths and widths \addtolength{\textwidth}{6cm} \addtolength{\textheight}{-1cm} \addtolength{\hoffset}{-3cm} \addtolength{\voffset}{-2cm} \setlength{\tabcolsep}{0.2cm} % Space between columns \setlength{\headsep}{-12pt} % Reduce space between header and content \setlength{\headheight}{85pt} % If less, LaTeX automatically increases it \renewcommand{\footrulewidth}{0pt} % Remove footer line \renewcommand{\headrulewidth}{0pt} % Remove header line \renewcommand{\seqinsert}{\ifmmode\allowbreak\else\-\fi} % Hyphens in seqsplit % This two commands together give roughly % the right line height in the tables \renewcommand{\arraystretch}{1.3} \onehalfspacing % Commands \newcommand{\SetRowColor}[1]{\noalign{\gdef\RowColorName{#1}}\rowcolor{\RowColorName}} % Shortcut for row colour \newcommand{\mymulticolumn}[3]{\multicolumn{#1}{>{\columncolor{\RowColorName}}#2}{#3}} % For coloured multi-cols \newcolumntype{x}[1]{>{\raggedright}p{#1}} % New column types for ragged-right paragraph columns \newcommand{\tn}{\tabularnewline} % Required as custom column type in use % Font and Colours \definecolor{HeadBackground}{HTML}{333333} \definecolor{FootBackground}{HTML}{666666} \definecolor{TextColor}{HTML}{333333} \definecolor{DarkBackground}{HTML}{0F573F} \definecolor{LightBackground}{HTML}{F7F9F9} \renewcommand{\familydefault}{\sfdefault} \color{TextColor} % Header and Footer \pagestyle{fancy} \fancyhead{} % Set header to blank \fancyfoot{} % Set footer to blank \fancyhead[L]{ \noindent \begin{multicols}{3} \begin{tabulary}{5.8cm}{C} \SetRowColor{DarkBackground} \vspace{-7pt} {\parbox{\dimexpr\textwidth-2\fboxsep\relax}{\noindent \hspace*{-6pt}\includegraphics[width=5.8cm]{/web/www.cheatography.com/public/images/cheatography_logo.pdf}} } \end{tabulary} \columnbreak \begin{tabulary}{11cm}{L} \vspace{-2pt}\large{\bf{\textcolor{DarkBackground}{\textrm{R Cheat Sheet}}}} \\ \normalsize{by \textcolor{DarkBackground}{Jeffrey M. Pisklak (non\_human\_entity)} via \textcolor{DarkBackground}{\uline{cheatography.com/127433/cs/24819/}}} \end{tabulary} \end{multicols}} \fancyfoot[L]{ \footnotesize \noindent \begin{multicols}{3} \begin{tabulary}{5.8cm}{LL} \SetRowColor{FootBackground} \mymulticolumn{2}{p{5.377cm}}{\bf\textcolor{white}{Cheatographer}} \\ \vspace{-2pt}Jeffrey M. Pisklak (non\_human\_entity) \\ \uline{cheatography.com/non-human-entity} \\ \end{tabulary} \vfill \columnbreak \begin{tabulary}{5.8cm}{L} \SetRowColor{FootBackground} \mymulticolumn{1}{p{5.377cm}}{\bf\textcolor{white}{Cheat Sheet}} \\ \vspace{-2pt}Published 28th December, 2023.\\ Updated 28th December, 2023.\\ Page {\thepage} of \pageref{LastPage}. \end{tabulary} \vfill \columnbreak \begin{tabulary}{5.8cm}{L} \SetRowColor{FootBackground} \mymulticolumn{1}{p{5.377cm}}{\bf\textcolor{white}{Sponsor}} \\ \SetRowColor{white} \vspace{-5pt} %\includegraphics[width=48px,height=48px]{dave.jpeg} Measure your website readability!\\ www.readability-score.com \end{tabulary} \end{multicols}} \begin{document} \raggedright \raggedcolumns % Set font size to small. Switch to any value % from this page to resize cheat sheet text: % www.emerson.emory.edu/services/latex/latex_169.html \footnotesize % Small font. \begin{tabularx}{17.67cm}{x{4.6629 cm} x{12.6071 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{17.67cm}}{\bf\textcolor{white}{Operators}} \tn % Row 0 \SetRowColor{LightBackground} `=` \{\{nl\}\} `\textless{}-` & Assigns a value to an object \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} ` \textgreater{} ` & greater than \tn % Row Count 3 (+ 1) % Row 2 \SetRowColor{LightBackground} `\textless{}` & less than \tn % Row Count 4 (+ 1) % Row 3 \SetRowColor{white} `\textgreater{}=` & greater than or equal to \tn % Row Count 5 (+ 1) % Row 4 \SetRowColor{LightBackground} `\textless{}=` & less than or equal to \tn % Row Count 6 (+ 1) % Row 5 \SetRowColor{white} `==` & exactly equal to \tn % Row Count 7 (+ 1) % Row 6 \SetRowColor{LightBackground} `!=` & not equal to \tn % Row Count 8 (+ 1) % Row 7 \SetRowColor{white} `!x` & not x \tn % Row Count 9 (+ 1) % Row 8 \SetRowColor{LightBackground} `x | y` & x OR y \tn % Row Count 10 (+ 1) % Row 9 \SetRowColor{white} `x \& y` & x AND y \tn % Row Count 11 (+ 1) % Row 10 \SetRowColor{LightBackground} `\%\textgreater{}\%` & Sends something (e.g., dataframe or function output) to a tidyverse function. i.e., it is an elegant way to nest tidyverse functions. \tn % Row Count 16 (+ 5) % Row 11 \SetRowColor{white} & Example:`\{\{nl\}\}library(tidyverse)\{\{nl\}\}msleep \%\textgreater{}\%\{\{nl\}\} ~filter(conservation == 'domesticated') \%\textgreater{}\%\{\{nl\}\} ~ ~summarise(m = mean(brainwt, na.rm = TRUE),\{\{nl\}\} ~ ~ ~ ~ ~ ~ ~s = sd(brainwt, na.rm = TRUE),\{\{nl\}\} ~ ~ ~ ~ ~ ~ ~med = median(brainwt, na.rm = TRUE)\{\{nl\}\}~~~~~~~~~~~~~~)` \{\{nl\}\} \{\{nl\}\} Note that `summarise()` is nested within `filter()`, which is using info from the `msleep` dataframe. \tn % Row Count 35 (+ 19) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{17.67cm}}{\bf\textcolor{white}{Basic R Functions}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{17.67cm}}{{\bf{Access a function's help file}}} \tn \mymulticolumn{1}{x{17.67cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}`?{[}function name{]}`} \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{17.67cm}}{{\bf{Load a csv file}}} \tn \mymulticolumn{1}{x{17.67cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}`read.csv( "filename.csv", header = TRUE )`} \tn % Row Count 5 (+ 3) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{17.67cm}}{{\bf{Install a library}}} \tn \mymulticolumn{1}{x{17.67cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}\seqsplit{`install.packages("library} name")`} \tn % Row Count 7 (+ 2) % Row 3 \SetRowColor{white} \mymulticolumn{1}{x{17.67cm}}{{\bf{Load an installed library}}} \tn \mymulticolumn{1}{x{17.67cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}`library(library name)`} \tn % Row Count 9 (+ 2) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{1}{x{17.67cm}}{{\bf{Resize images in Google Collab}}} \tn \mymulticolumn{1}{x{17.67cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}`options(repr.plot.width = x, repr.plot.height = y)`} \tn % Row Count 12 (+ 3) % Row 5 \SetRowColor{white} \mymulticolumn{1}{x{17.67cm}}{{\bf{Return the amount of values in x}}} \tn \mymulticolumn{1}{x{17.67cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}`length(x)`} \tn % Row Count 14 (+ 2) % Row 6 \SetRowColor{LightBackground} \mymulticolumn{1}{x{17.67cm}}{Return the number of rows in a dataframe} \tn \mymulticolumn{1}{x{17.67cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}`nrow(dataframe)`} \tn % Row Count 16 (+ 2) % Row 7 \SetRowColor{white} \mymulticolumn{1}{x{17.67cm}}{{\bf{Return the absolute value(s) in x}}} \tn \mymulticolumn{1}{x{17.67cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}`abs(x)`} \tn % Row Count 18 (+ 2) % Row 8 \SetRowColor{LightBackground} \mymulticolumn{1}{x{17.67cm}}{{\bf{Return the sum of all the values in x}}} \tn \mymulticolumn{1}{x{17.67cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}`sum(x)`} \tn % Row Count 20 (+ 2) % Row 9 \SetRowColor{white} \mymulticolumn{1}{x{17.67cm}}{{\bf{Return the square-root of the value(s) in x}}} \tn \mymulticolumn{1}{x{17.67cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}`sqrt(x)`} \tn % Row Count 22 (+ 2) % Row 10 \SetRowColor{LightBackground} \mymulticolumn{1}{x{17.67cm}}{{\bf{Return the mean of the values in x with optional arguments for trimming and removing NAs}}} \tn \mymulticolumn{1}{x{17.67cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}`mean(x, tr = 0, na.rm = FALSE)`} \tn % Row Count 25 (+ 3) % Row 11 \SetRowColor{white} \mymulticolumn{1}{x{17.67cm}}{{\bf{Return the median of the values in x with optional arguments removing NAs}}} \tn \mymulticolumn{1}{x{17.67cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}`median(x, na.rm = FALSE)`} \tn % Row Count 28 (+ 3) % Row 12 \SetRowColor{LightBackground} \mymulticolumn{1}{x{17.67cm}}{{\bf{Return the sample standard deviation of values in x with optional argument for removing NAs}}} \tn \mymulticolumn{1}{x{17.67cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}`sd(x, na.rm = FALSE)`} \tn % Row Count 31 (+ 3) \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{17.67cm}}{\bf\textcolor{white}{Basic R Functions (cont)}} \tn % Row 13 \SetRowColor{white} \mymulticolumn{1}{x{17.67cm}}{{\bf{Return the sample variance of values in x with optional argument for removing NAs}}} \tn \mymulticolumn{1}{x{17.67cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}`var(x, na.rm = FALSE)`} \tn % Row Count 3 (+ 3) % Row 14 \SetRowColor{LightBackground} \mymulticolumn{1}{x{17.67cm}}{{\bf{Return the quartiles for x with optional argument for removing NAs}}} \tn \mymulticolumn{1}{x{17.67cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}`quantile(x, na.rm = FALSE)`} \tn % Row Count 6 (+ 3) % Row 15 \SetRowColor{white} \mymulticolumn{1}{x{17.67cm}}{{\bf{Sort the values of x into ascending order}}} \tn \mymulticolumn{1}{x{17.67cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}`sort(x)`} \tn % Row Count 8 (+ 2) % Row 16 \SetRowColor{LightBackground} \mymulticolumn{1}{x{17.67cm}}{{\bf{Compute the median absolute deviation of x with optional argument to remove NAs}}} \tn \mymulticolumn{1}{x{17.67cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}`mad(x, na.rm = FALSE)`} \tn % Row Count 11 (+ 3) % Row 17 \SetRowColor{white} \mymulticolumn{1}{x{17.67cm}}{{\bf{Find NA values in x (returns TRUE/FALSE)}}} \tn \mymulticolumn{1}{x{17.67cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}`is.na(x)`} \tn % Row Count 13 (+ 2) % Row 18 \SetRowColor{LightBackground} \mymulticolumn{1}{x{17.67cm}}{Paste things together into a single string} \tn \mymulticolumn{1}{x{17.67cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}`paste(x, y, z, sep = "")`} \tn % Row Count 15 (+ 2) % Row 19 \SetRowColor{white} \mymulticolumn{1}{x{17.67cm}}{Create a table of counts} \tn \mymulticolumn{1}{x{17.67cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}Examples: \{\{nl\}\}`table(x)` \{\{nl\}\} `table(x, y)`} \tn % Row Count 17 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{17.67cm}}{\bf\textcolor{white}{Data Frames}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{17.67cm}}{{\bf{Create a new data frame}}} \tn \mymulticolumn{1}{x{17.67cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}`Column\_1 \textless{}- c("A", "B", "C")`\{\{nl\}\}`Column\_2 \textless{}- c(21, 22, NA)`\{\{nl\}\}`new\_df \textless{}- data.frame(Column\_1, Column\_2)`} \tn % Row Count 4 (+ 4) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{17.67cm}}{{\bf{Add a column}}} \tn \mymulticolumn{1}{x{17.67cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}`new\_df\$Column\_3 \textless{}- c(51, 52, 53)`} \tn % Row Count 6 (+ 2) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{17.67cm}}{{\bf{Select a specific value}} (e.g., 52 = row 2, column 3)} \tn \mymulticolumn{1}{x{17.67cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}`new\_df{[}2, 3{]}`} \tn % Row Count 9 (+ 3) % Row 3 \SetRowColor{white} \mymulticolumn{1}{x{17.67cm}}{{\bf{Select a series of values}} (e.g., all of row 2)} \tn \mymulticolumn{1}{x{17.67cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}`new\_df{[}2, c(1,2,3){]}` \{\{nl\}\} or \{\{nl\}\} `new\_df{[}2, {]}`} \tn % Row Count 12 (+ 3) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{1}{x{17.67cm}}{{\bf{Select an entire column}} (e.g., column 2)} \tn \mymulticolumn{1}{x{17.67cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}`new\_df\$Column\_2` \{\{nl\}\} or \{\{nl\}\}`new\_df{[} , 2{]}`} \tn % Row Count 15 (+ 3) % Row 5 \SetRowColor{white} \mymulticolumn{1}{x{17.67cm}}{{\bf{Isolate values that are not NAs}}} \tn \mymulticolumn{1}{x{17.67cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}`new\_df\$Column\_2{[}!is.na(new\_df\$Column\_2){]}`} \tn % Row Count 17 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{17.67cm}}{\bf\textcolor{white}{Filter Function}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{17.67cm}}{{\bf{Used to select specific observations from a dataframe according to a rule you specify.}}} \tn \mymulticolumn{1}{x{17.67cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}`filter(dataframe, subset rule)`} \tn % Row Count 3 (+ 3) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{17.67cm}}{Example 1:} \tn \mymulticolumn{1}{x{17.67cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}`filter(heightData, Father \textless{} 60.1 | Father \textgreater{} 75.3)`} \tn % Row Count 6 (+ 3) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{17.67cm}}{Example 2:} \tn \mymulticolumn{1}{x{17.67cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}`heightData \%\textgreater{}\% filter(Father \textless{} 60.1 | Father \textgreater{} 75.3)`} \tn % Row Count 9 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{17.67cm}}{\bf\textcolor{white}{Subset Function}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{17.67cm}}{{\bf{Used to select specific observations from a dataframe according to a rule you specify.}}} \tn \mymulticolumn{1}{x{17.67cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}`subset(dataframe, subset rule, select = ("columns to keep"))`} \tn % Row Count 4 (+ 4) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{17.67cm}}{Example:} \tn \mymulticolumn{1}{x{17.67cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}`outliers \textless{}- subset(heightData, Father \textless{} 60.1 | Father \textgreater{} 75.3, select = c("Father"))`} \tn % Row Count 7 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{17.67cm}}{\bf\textcolor{white}{Library Functions}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{17.67cm}}{{\bf{library(tidyverse)}} or {\bf{library(dplyr)}}} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{17.67cm}}{Aggregate data sets into a new dataframe. \{\{nl\}\} For example . . .} \tn \mymulticolumn{1}{x{17.67cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}`msleep \%\textgreater{}\%\{\{nl\}\}~~group\_by(vore, conservation) \%\textgreater{}\% ~~ \{\{nl\}\}~~summarise(m = mean(brainwt, na.rm = TRUE),\{\{nl\}\}~~~~~~~~~~~~s = sd(brainwt, na.rm = TRUE)\{\{nl\}\}~~~~~~~~~~~~)`} \tn % Row Count 10 (+ 9) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{17.67cm}}{{\bf{library(rcompanion)}}} \tn % Row Count 11 (+ 1) % Row 3 \SetRowColor{white} \mymulticolumn{1}{x{17.67cm}}{Calculates lambda for Tukey's ladder of powers} \tn \mymulticolumn{1}{x{17.67cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}`transformTukey(x, plotit = FALSE, returnLambda = TRUE)`} \tn % Row Count 14 (+ 3) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{1}{x{17.67cm}}{{\bf{library(WRS2)}}} \tn % Row Count 15 (+ 1) % Row 5 \SetRowColor{white} \mymulticolumn{1}{x{17.67cm}}{Winsorized {\emph{variance}} of x} \tn \mymulticolumn{1}{x{17.67cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}`winvar(x, tr = .2)`} \tn % Row Count 17 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{17.67cm}}{\bf\textcolor{white}{Distribution Functions}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{17.67cm}}{{\bf{Return the the corres​ponding {\emph{quantile}} for a given probab​ility}}} \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{17.67cm}}{Normal Distribution} \tn \mymulticolumn{1}{x{17.67cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}\seqsplit{`qnorm​(pr​oba​bility}, mean, sd)`} \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{17.67cm}}{T Distribution} \tn \mymulticolumn{1}{x{17.67cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}`qt(pr​oba​bility, df, lower.tail)`} \tn % Row Count 6 (+ 2) % Row 3 \SetRowColor{white} \mymulticolumn{1}{x{17.67cm}}{F Distribution} \tn \mymulticolumn{1}{x{17.67cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}`qf(probability, df1, df2, lower.tail)`} \tn % Row Count 8 (+ 2) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{1}{x{17.67cm}}{Chi-Square Distribution} \tn \mymulticolumn{1}{x{17.67cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}`qchisq(probability, df, lower.tail)`} \tn % Row Count 10 (+ 2) % Row 5 \SetRowColor{white} \mymulticolumn{1}{x{17.67cm}}{{\bf{Return the the corres​ponding {\emph{probab​ility}} for a given quantile.}}} \tn % Row Count 12 (+ 2) % Row 6 \SetRowColor{LightBackground} \mymulticolumn{1}{x{17.67cm}}{Normal Distribution} \tn \mymulticolumn{1}{x{17.67cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}`pnorm​(quantile, mean, sd)`} \tn % Row Count 14 (+ 2) % Row 7 \SetRowColor{white} \mymulticolumn{1}{x{17.67cm}}{T Distribution} \tn \mymulticolumn{1}{x{17.67cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}`pt(quantile, df, lower.tail)`} \tn % Row Count 16 (+ 2) % Row 8 \SetRowColor{LightBackground} \mymulticolumn{1}{x{17.67cm}}{F Distribution} \tn \mymulticolumn{1}{x{17.67cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}`pf(quantile, df1, df2, lower.tail)`} \tn % Row Count 18 (+ 2) % Row 9 \SetRowColor{white} \mymulticolumn{1}{x{17.67cm}}{Chi-Square Distribution} \tn \mymulticolumn{1}{x{17.67cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}`pchisq(quantile, df, lower.tail)`} \tn % Row Count 20 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{17.67cm}}{Note: \newline - z-scores and t-scores (e.g. critical T and test statistics) are types of quantiles.\{\{nl\}\} \newline - The calculations are all performed from left to right by default unless you specify lower.tail = FALSE).} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{17.67cm}}{\bf\textcolor{white}{Plotting: library(ggplot2)}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{17.67cm}}{{\bf{Histogram}}} \tn \mymulticolumn{1}{x{17.67cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}`ggplot(dataFrame, aes(x = Dep\_Var)) +`\{\{nl\}\} `~~~~~ ~geom\_histogram(colour = "black",` \{\{nl\}\} `~~~~~~~~~~~ ~ ~ ~~~~~ fill = "white")`\{\{nl\}\}} \tn % Row Count 7 (+ 7) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{17.67cm}}{{\bf{Density Plot}}} \tn \mymulticolumn{1}{x{17.67cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}`ggplot(dataFrame, aes(x = Dep\_Var)) +`\{\{nl\}\} `~~~~~ ~geom\_density(colour = "black",` \{\{nl\}\} `~~~~~~~~~~~~~~~ ~ ~ fill = "pink",` \{\{nl\}\} `~~~~~~~~~~~~~~~~~~~ adjust = 1)`\{\{nl\}\}} \tn % Row Count 17 (+ 10) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{17.67cm}}{{\bf{Boxplot - for one sample}}} \tn \mymulticolumn{1}{x{17.67cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}`ggplot(dataFrame, aes(y = Dep\_Var,)) +`\{\{nl\}\} `~~~~~ ~geom\_boxplot()`} \tn % Row Count 21 (+ 4) % Row 3 \SetRowColor{white} \mymulticolumn{1}{x{17.67cm}}{{\bf{Boxplot - for two or more samples}}} \tn \mymulticolumn{1}{x{17.67cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}`ggplot(dataFrame, aes(x = Indep\_Var, y = Dep\_Var)) +`\{\{nl\}\} `~~~~~ ~geom\_boxplot()`} \tn % Row Count 25 (+ 4) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{1}{x{17.67cm}}{{\bf{Barplot with errorbars}}} \tn \mymulticolumn{1}{x{17.67cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}`ggplot(plotData, aes(x = Indep\_Var, y = Dep\_Var,`\{\{nl\}\} `~~~~~~~~~~~~~~~ ~ ~ ~fill = Indep\_Var)) +`\{\{nl\}\} `~~ geom\_bar(stat = "identity", colour = "black") +`\{\{nl\}\} `~~ geom\_errorbar(aes(ymin = bottom\_values,`\{\{nl\}\} \seqsplit{`~~~~~~~~~~~~~~~~~~~~~ymax} = top\_values),`\{\{nl\}\} `~~~~~~~~~~~~~~~~~ width = .25)`\{\{nl\}\}} \tn % Row Count 39 (+ 14) \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{17.67cm}}{\bf\textcolor{white}{Plotting: library(ggplot2) (cont)}} \tn % Row 5 \SetRowColor{white} \mymulticolumn{1}{x{17.67cm}}{{\bf{Q-Q Plot For two independent samples}} \{\{nl\}\} \textasciicircum{}Remove + facet\_wrap() for a single sample\textasciicircum{}} \tn \mymulticolumn{1}{x{17.67cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}`ggplot(dataFrame, aes(sample = Dep\_Var)) +`\{\{nl\}\} `~~~~~~~ stat\_qq() +`\{\{nl\}\} `~~~~~~~ stat\_qq\_line() +`\{\{nl\}\} `~~~~~~~ facet\_wrap(\textasciitilde{} Indep\_Var)`} \tn % Row Count 8 (+ 8) % Row 6 \SetRowColor{LightBackground} \mymulticolumn{1}{x{17.67cm}}{{\bf{Line Plot of Means with Two Predictors}}} \tn \mymulticolumn{1}{x{17.67cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}`ggplot(plotData, aes(x = PredictorA, y = Means, group = PredictorB, colour = PredictorB)) + \{\{nl\}\} ~ ~ geom\_line(position = position\_dodge(width = 0.4)) + \{\{nl\}\} ~ ~ geom\_point(position = position\_dodge(width = 0.4)) `} \tn % Row Count 15 (+ 7) % Row 7 \SetRowColor{white} \mymulticolumn{1}{x{17.67cm}}{{\bf{Scatterplot with Regression Line}}} \tn \mymulticolumn{1}{x{17.67cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}`ggplot(dataframe, aes(x = predictor, y = response)) + \{\{nl\}\} ~ ~ geom\_point() + \{\{nl\}\} ~ ~ geom\_abline(intercept = b0, slope = b1) `} \tn % Row Count 20 (+ 5) \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{17.67cm}}{Note: \newline \textasciicircum{}Indep\_Var = Independent Variable\textasciicircum{} \newline \textasciicircum{}Dep\_Var = Dependent Variable\textasciicircum{} \newline \textasciicircum{}plotData = Dataframe of aggregated values\textasciicircum{}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{p{1.727 cm} x{15.543 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{17.67cm}}{\bf\textcolor{white}{R Style Guide (from the Tidyverse)}} \tn % Row 0 \SetRowColor{LightBackground} & \seqsplit{https://style.tidyverse.org/} \tn % Row Count 1 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \end{document}