Introduction

See the Introduction pdf for the various examples and the relation of this example to the others.

With the rmarkdown format an author can easily specify how a document should be formatted. When the final document has to be a pdf-file a Latex installation is required. The rmarkdown (rmd) file can contain all Latex commands that the author thinks necessary. This example shows how to create a pdf-file from an rmd-file without any additional Latex commands.
The advantage of not including Latex commands is that e.g. html or MSWord documents can be created without (nearly any) changes: by changing in the yaml-header ‘output: pdf_document’ to ‘output: word_document’ or ‘output: html_document’ instead of a pdf-document a docx- or html-document is created.
The main disadvantage is that internal references to figure and tables are not available. In the next examples we will show how to do this for the pdf case but this introduces a differences between the three document formats.

Libraries used

library(ggplot2)
library(ggthemes)

Load data

We load the iris data set in the workspace.

data(iris)

List the part of the iris data set

We list the first 10 (because we set variable numlist to 10 in a chunck we do not present to the reader) observations in the data set.

kable(iris[1:numlist,],row.names=F,longtable=F)
Sepal.Length Sepal.Width Petal.Length Petal.Width Species
5.1 3.5 1.4 0.2 setosa
4.9 3.0 1.4 0.2 setosa
4.7 3.2 1.3 0.2 setosa
4.6 3.1 1.5 0.2 setosa
5.0 3.6 1.4 0.2 setosa
5.4 3.9 1.7 0.4 setosa
4.6 3.4 1.4 0.3 setosa
5.0 3.4 1.5 0.2 setosa
4.4 2.9 1.4 0.2 setosa
4.9 3.1 1.5 0.1 setosa

Create a plot of the iris data set

Make a ggplot2 plot object p of two variables in the iris data set and use it to create a plot.

p <- ggplot(iris, aes(Sepal.Length, Sepal.Width, colour = Species)) + 
  geom_point() 
p + labs(title = 'default theme')

Session Info

sessionInfo()
## R version 3.2.0 (2015-04-16)
## Platform: x86_64-w64-mingw32/x64 (64-bit)
## Running under: Windows 8 x64 (build 9200)
## 
## locale:
## [1] LC_COLLATE=English_United States.1252  LC_CTYPE=English_United States.1252   
## [3] LC_MONETARY=English_United States.1252 LC_NUMERIC=C                          
## [5] LC_TIME=English_United States.1252    
## 
## attached base packages:
## [1] stats     graphics  grDevices utils     datasets  methods   base     
## 
## other attached packages:
## [1] ggthemes_3.0.1 ggplot2_2.0.0  knitr_1.12.3  
## 
## loaded via a namespace (and not attached):
##  [1] Rcpp_0.12.2      assertthat_0.1   digest_0.6.8     plyr_1.8.3       grid_3.2.0      
##  [6] gtable_0.1.2     formatR_1.2.1    magrittr_1.5     evaluate_0.8     scales_0.3.0    
## [11] highr_0.5.1      stringi_1.0-1    rmarkdown_0.9.2  labeling_0.3     tools_3.2.0     
## [16] stringr_1.0.0    munsell_0.4.2    yaml_2.1.13      colorspace_1.2-6 htmltools_0.2.6