SlideShare a Scribd company logo
1 of 20
Download to read offline
Department of!
Psychology!
University of Mary Hardin-Baylor!
Integrating R, knitr,
and LaTeX via
RStudio!
!
Aaron R. Baggett!
February15, 2013!
Introduction!
•  R is a free, open-source statistical and data visualization
software application
•  Open source = large community of developers
•  Increasing in popularity
(Muenchen, 2012)
Aaron R. Baggett | 02/15/2013! 2!
R!
Introduction!
•  Programming language
•  Can interface with many other programs
•  Object oriented language
a <- 15
b <- 15
a + b
[1] 30	
Aaron R. Baggett | 02/15/2013! 3!
R!
> Response <- c("Not too happy", "Pretty happy", "Very happy")	
> lt20k <- c(17.2, 60.5, 22.2)	
> lt49k <- c(13, 56.8, 30.2)	
> lt89k <- c(7.7, 50.3, 41.9)	
> gt90k <- c(5.3, 51.8, 42.9)	
> 	
> (happy <- data.frame(Response, lt20k, lt49k, lt89k, gt90k))	
Response lt20k lt49k lt89k gt90k	
1 Not too happy 17.2 13.0 7.7 5.3	
2 Pretty happy 60.5 56.8 50.3 51.8	
3 Very happy 22.2 30.2 41.9 42.9	
	
> happy$Response <- NULL	
> happy	
lt20k lt49k lt89k gt90k	
1 17.2 13.0 7.7 5.3	
2 60.5 56.8 50.3 51.8	
3 22.2 30.2 41.9 42.9	
> 	
> (test <- chisq.test(happy))	
	
	Pearson's Chi-squared test	
	
data: happy	
X-squared = 17.73, df = 6, p-value = 0.00694	
	
> test$expected	
lt20k lt49k lt89k gt90k	
[1,] 10.79 10.81 10.79 10.81	
[2,] 54.82 54.88 54.82 54.88	
[3,] 34.28 34.32 34.28 34.32
Introduction!
•  Flexible and versatile
•  4,336 user contributed packages
o  Statistics and data analysis
o  Psychometrics
o  Graphics
o  Economics and finance
	
Aaron R. Baggett | 02/15/2013! 5!
R!
Introduction!
•  Free graphical user interface (GUI) for R
o  http://www.rstudio.com/
o  https://twitter.com/rstudioapp
•  Still requires use of syntax
o  e.g., reg.fit <- lm(y ~ x1 + x2 + x3, data = df)	
•  Not limited by point and click interface
Aaron R. Baggett | 02/15/2013! 6!
RStudio!
Introduction!
•  Consolidated work environment
o  Four window panes
1.  R Console
2.  Script
3.  Workspace
4.  Utility tabs
a.  Files
b.  Plots
c.  Packages
d.  R Help
Aaron R. Baggett | 02/15/2013! 7!
Advantages of RStudio!
Introduction!
•  Templates for document preparation
o  knitr: http://yihui.name/knitr/
o  Sweave: http://goo.gl/gMkqo
o  R Markdown: http://goo.gl/YHBB1
•  LaTeX integration
o  knitr works best for me
Aaron R. Baggett | 02/15/2013! 9!
Advantages of RStudio!
Document Preparation!
•  Pronounced “Lah-Tek”
•  Document preparation system
•  Sections, cross-references, bibliographies
•  Equation/math typesetting
•  Stability
•  Like R, large, active community
Aaron R. Baggett | 02/15/2013! 10!
LaTeX http://www.latex-project.org/
LaTeX!
documentclass[11pt, oneside]{article}	
usepackage{geometry}	
geometry{letterpaper}	
usepackage[parfill]{parskip}	
usepackage{graphicx}	
	
title{Brief Article}	
author{The Author}	
date{today}	
	
begin{document}	
maketitle	
%section{}	
%subsection{}	
	
end{document} 	
	
Aaron R. Baggett | 02/15/2013! 11!
Standard Preamble!
Brief Article
The Author
February 15, 2013
1
Document Preparation!
•  Comprehensive package for generating “Elegant,
flexible and fast, dynamic report generation with R.”
•  Easily handles embedding R code directly in LaTeX
documents
•  Tutorial video from knitr developers:
http://www.screenr.com/qcv8
Aaron R. Baggett | 02/15/2013! 13!
knitr!
knitr!
•  All inline R code begins with: <<>>=	
•  And ends with: @	
Aaron R. Baggett | 02/15/2013! 15!
knitr Code!
<<tidy = TRUE>>=	
library(ggplot2)	
names(diamonds) #Returns variable names	
head(diamonds) #Returns first six rows of dataset	
with(diamonds, summary(carat)) #Summarize 'carat' variable	
with(diamonds, cor(carat, price)) #Correlate 'carat' and 'price’. 	
@	
<<fig.width = 6, fig.height = 6, tidy = FALSE>>=	
qplot(carat, data = diamonds, fill = color, geom = ‘histogram’,	
	binwidth = 0.4, xlim = c(0,3),	
	main = ‘Stacked Histogram of Diamond Carat Weight by Color’,	
	xlab = ‘Carat Weight’, ylab = ‘Count’)	
@
knitr!
Aaron R. Baggett | 02/15/2013! 16!
knitr Code!
<<box, fig.width=5.5, fig.height=5.5, fig.align='center', tidy=FALSE>>=	
plot(Sex, Extrov, main = 	
	"Box-Whisker Plot of Variancen(Extroversion by Sex)”,	
	col = "dodgerblue3", ylab = "Extroversion")	
@	
newpage	
setlengthparindent{0pt}textbf{large{5). Test to see if there is a
mean difference in Extroversion between males and females (make sure
you test the assumption of homogeneity of variance and set up your t-
test appropriately)}}	
vspace*{-.55in}
knitr!
Aaron R. Baggett | 02/15/2013! 18!
knitr efficiency!
Conclusion!
•  Efficient document markup
•  Dynamic and attractive reports
•  Stability
•  Open source
•  Free
Aaron R. Baggett | 02/15/2013! 19!
Benefits!
Aaron Baggett!
abaggett@umhb.edu
Aaron R. Baggett | 02/15/2013! 20!
Questions?!

More Related Content

Similar to Integrating R, knitr, and LaTeX via RStudio

R Programming Overview
R Programming Overview R Programming Overview
R Programming Overview dlamb3244
 
Introduction to R and R Studio
Introduction to R and R StudioIntroduction to R and R Studio
Introduction to R and R StudioRupak Roy
 
Reproducible Research in R and R Studio
Reproducible Research in R and R StudioReproducible Research in R and R Studio
Reproducible Research in R and R StudioSusan Johnston
 
Business Analytics with R
Business Analytics with RBusiness Analytics with R
Business Analytics with REdureka!
 
BUSINESS ANALYTICS WITH R SOFTWARE DIAST
BUSINESS ANALYTICS WITH R SOFTWARE DIASTBUSINESS ANALYTICS WITH R SOFTWARE DIAST
BUSINESS ANALYTICS WITH R SOFTWARE DIASTHaritikaChhatwal1
 
Data Analysis and Visualization: R Workflow
Data Analysis and Visualization: R WorkflowData Analysis and Visualization: R Workflow
Data Analysis and Visualization: R WorkflowOlga Scrivner
 
An introduction to R is a document useful
An introduction to R is a document usefulAn introduction to R is a document useful
An introduction to R is a document usefulssuser3c3f88
 
Business Analytics with R
Business Analytics with RBusiness Analytics with R
Business Analytics with REdureka!
 
Data Science - Part II - Working with R & R studio
Data Science - Part II -  Working with R & R studioData Science - Part II -  Working with R & R studio
Data Science - Part II - Working with R & R studioDerek Kane
 
R as supporting tool for analytics and simulation
R as supporting tool for analytics and simulationR as supporting tool for analytics and simulation
R as supporting tool for analytics and simulationAlvaro Gil
 
DSM software tools
DSM software toolsDSM software tools
DSM software toolsFAO
 
4. Digital Soil Mapping: Software and Tools
4. Digital Soil Mapping: Software and Tools4. Digital Soil Mapping: Software and Tools
4. Digital Soil Mapping: Software and ToolsFAO
 
Overview data analyis and visualisation tools 2020
Overview data analyis and visualisation tools 2020Overview data analyis and visualisation tools 2020
Overview data analyis and visualisation tools 2020Marié Roux
 
aRangodb, un package per l'utilizzo di ArangoDB con R
aRangodb, un package per l'utilizzo di ArangoDB con RaRangodb, un package per l'utilizzo di ArangoDB con R
aRangodb, un package per l'utilizzo di ArangoDB con RGraphRM
 
4. Digital Soil Mapping software tools
4. Digital Soil Mapping software tools4. Digital Soil Mapping software tools
4. Digital Soil Mapping software toolsExternalEvents
 
Big Data Step-by-Step: Using R & Hadoop (with RHadoop's rmr package)
Big Data Step-by-Step: Using R & Hadoop (with RHadoop's rmr package)Big Data Step-by-Step: Using R & Hadoop (with RHadoop's rmr package)
Big Data Step-by-Step: Using R & Hadoop (with RHadoop's rmr package)Jeffrey Breen
 

Similar to Integrating R, knitr, and LaTeX via RStudio (20)

R Programming Overview
R Programming Overview R Programming Overview
R Programming Overview
 
Introduction to R and R Studio
Introduction to R and R StudioIntroduction to R and R Studio
Introduction to R and R Studio
 
Reproducible Research in R and R Studio
Reproducible Research in R and R StudioReproducible Research in R and R Studio
Reproducible Research in R and R Studio
 
Business Analytics with R
Business Analytics with RBusiness Analytics with R
Business Analytics with R
 
BUSINESS ANALYTICS WITH R SOFTWARE DIAST
BUSINESS ANALYTICS WITH R SOFTWARE DIASTBUSINESS ANALYTICS WITH R SOFTWARE DIAST
BUSINESS ANALYTICS WITH R SOFTWARE DIAST
 
Data Analysis and Visualization: R Workflow
Data Analysis and Visualization: R WorkflowData Analysis and Visualization: R Workflow
Data Analysis and Visualization: R Workflow
 
An introduction to R is a document useful
An introduction to R is a document usefulAn introduction to R is a document useful
An introduction to R is a document useful
 
R programming
R programmingR programming
R programming
 
Business Analytics with R
Business Analytics with RBusiness Analytics with R
Business Analytics with R
 
Data Science - Part II - Working with R & R studio
Data Science - Part II -  Working with R & R studioData Science - Part II -  Working with R & R studio
Data Science - Part II - Working with R & R studio
 
R programming
R programmingR programming
R programming
 
R as supporting tool for analytics and simulation
R as supporting tool for analytics and simulationR as supporting tool for analytics and simulation
R as supporting tool for analytics and simulation
 
DSM software tools
DSM software toolsDSM software tools
DSM software tools
 
4. Digital Soil Mapping: Software and Tools
4. Digital Soil Mapping: Software and Tools4. Digital Soil Mapping: Software and Tools
4. Digital Soil Mapping: Software and Tools
 
Overview data analyis and visualisation tools 2020
Overview data analyis and visualisation tools 2020Overview data analyis and visualisation tools 2020
Overview data analyis and visualisation tools 2020
 
Crash course in R and BioConductor
Crash course in R and BioConductorCrash course in R and BioConductor
Crash course in R and BioConductor
 
aRangodb, un package per l'utilizzo di ArangoDB con R
aRangodb, un package per l'utilizzo di ArangoDB con RaRangodb, un package per l'utilizzo di ArangoDB con R
aRangodb, un package per l'utilizzo di ArangoDB con R
 
R crash course
R crash courseR crash course
R crash course
 
4. Digital Soil Mapping software tools
4. Digital Soil Mapping software tools4. Digital Soil Mapping software tools
4. Digital Soil Mapping software tools
 
Big Data Step-by-Step: Using R & Hadoop (with RHadoop's rmr package)
Big Data Step-by-Step: Using R & Hadoop (with RHadoop's rmr package)Big Data Step-by-Step: Using R & Hadoop (with RHadoop's rmr package)
Big Data Step-by-Step: Using R & Hadoop (with RHadoop's rmr package)
 

Recently uploaded

Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 

Recently uploaded (20)

Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 

Integrating R, knitr, and LaTeX via RStudio

  • 1. Department of! Psychology! University of Mary Hardin-Baylor! Integrating R, knitr, and LaTeX via RStudio! ! Aaron R. Baggett! February15, 2013!
  • 2. Introduction! •  R is a free, open-source statistical and data visualization software application •  Open source = large community of developers •  Increasing in popularity (Muenchen, 2012) Aaron R. Baggett | 02/15/2013! 2! R!
  • 3. Introduction! •  Programming language •  Can interface with many other programs •  Object oriented language a <- 15 b <- 15 a + b [1] 30 Aaron R. Baggett | 02/15/2013! 3! R!
  • 4. > Response <- c("Not too happy", "Pretty happy", "Very happy") > lt20k <- c(17.2, 60.5, 22.2) > lt49k <- c(13, 56.8, 30.2) > lt89k <- c(7.7, 50.3, 41.9) > gt90k <- c(5.3, 51.8, 42.9) > > (happy <- data.frame(Response, lt20k, lt49k, lt89k, gt90k)) Response lt20k lt49k lt89k gt90k 1 Not too happy 17.2 13.0 7.7 5.3 2 Pretty happy 60.5 56.8 50.3 51.8 3 Very happy 22.2 30.2 41.9 42.9 > happy$Response <- NULL > happy lt20k lt49k lt89k gt90k 1 17.2 13.0 7.7 5.3 2 60.5 56.8 50.3 51.8 3 22.2 30.2 41.9 42.9 > > (test <- chisq.test(happy)) Pearson's Chi-squared test data: happy X-squared = 17.73, df = 6, p-value = 0.00694 > test$expected lt20k lt49k lt89k gt90k [1,] 10.79 10.81 10.79 10.81 [2,] 54.82 54.88 54.82 54.88 [3,] 34.28 34.32 34.28 34.32
  • 5. Introduction! •  Flexible and versatile •  4,336 user contributed packages o  Statistics and data analysis o  Psychometrics o  Graphics o  Economics and finance Aaron R. Baggett | 02/15/2013! 5! R!
  • 6. Introduction! •  Free graphical user interface (GUI) for R o  http://www.rstudio.com/ o  https://twitter.com/rstudioapp •  Still requires use of syntax o  e.g., reg.fit <- lm(y ~ x1 + x2 + x3, data = df) •  Not limited by point and click interface Aaron R. Baggett | 02/15/2013! 6! RStudio!
  • 7. Introduction! •  Consolidated work environment o  Four window panes 1.  R Console 2.  Script 3.  Workspace 4.  Utility tabs a.  Files b.  Plots c.  Packages d.  R Help Aaron R. Baggett | 02/15/2013! 7! Advantages of RStudio!
  • 8.
  • 9. Introduction! •  Templates for document preparation o  knitr: http://yihui.name/knitr/ o  Sweave: http://goo.gl/gMkqo o  R Markdown: http://goo.gl/YHBB1 •  LaTeX integration o  knitr works best for me Aaron R. Baggett | 02/15/2013! 9! Advantages of RStudio!
  • 10. Document Preparation! •  Pronounced “Lah-Tek” •  Document preparation system •  Sections, cross-references, bibliographies •  Equation/math typesetting •  Stability •  Like R, large, active community Aaron R. Baggett | 02/15/2013! 10! LaTeX http://www.latex-project.org/
  • 11. LaTeX! documentclass[11pt, oneside]{article} usepackage{geometry} geometry{letterpaper} usepackage[parfill]{parskip} usepackage{graphicx} title{Brief Article} author{The Author} date{today} begin{document} maketitle %section{} %subsection{} end{document} Aaron R. Baggett | 02/15/2013! 11! Standard Preamble!
  • 13. Document Preparation! •  Comprehensive package for generating “Elegant, flexible and fast, dynamic report generation with R.” •  Easily handles embedding R code directly in LaTeX documents •  Tutorial video from knitr developers: http://www.screenr.com/qcv8 Aaron R. Baggett | 02/15/2013! 13! knitr!
  • 14.
  • 15. knitr! •  All inline R code begins with: <<>>= •  And ends with: @ Aaron R. Baggett | 02/15/2013! 15! knitr Code! <<tidy = TRUE>>= library(ggplot2) names(diamonds) #Returns variable names head(diamonds) #Returns first six rows of dataset with(diamonds, summary(carat)) #Summarize 'carat' variable with(diamonds, cor(carat, price)) #Correlate 'carat' and 'price’. @ <<fig.width = 6, fig.height = 6, tidy = FALSE>>= qplot(carat, data = diamonds, fill = color, geom = ‘histogram’, binwidth = 0.4, xlim = c(0,3), main = ‘Stacked Histogram of Diamond Carat Weight by Color’, xlab = ‘Carat Weight’, ylab = ‘Count’) @
  • 16. knitr! Aaron R. Baggett | 02/15/2013! 16! knitr Code! <<box, fig.width=5.5, fig.height=5.5, fig.align='center', tidy=FALSE>>= plot(Sex, Extrov, main = "Box-Whisker Plot of Variancen(Extroversion by Sex)”, col = "dodgerblue3", ylab = "Extroversion") @ newpage setlengthparindent{0pt}textbf{large{5). Test to see if there is a mean difference in Extroversion between males and females (make sure you test the assumption of homogeneity of variance and set up your t- test appropriately)}} vspace*{-.55in}
  • 17.
  • 18. knitr! Aaron R. Baggett | 02/15/2013! 18! knitr efficiency!
  • 19. Conclusion! •  Efficient document markup •  Dynamic and attractive reports •  Stability •  Open source •  Free Aaron R. Baggett | 02/15/2013! 19! Benefits!
  • 20. Aaron Baggett! abaggett@umhb.edu Aaron R. Baggett | 02/15/2013! 20! Questions?!