-
Notifications
You must be signed in to change notification settings - Fork 11
/
iris_data_set_vm1.rmd
77 lines (64 loc) · 2.96 KB
/
iris_data_set_vm1.rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
---
title: "iris_data_set_vm1 (no dependency on LaTeX)"
author: "Han Oostdijk (www.hanoostdijk.nl)"
date: "February 2016 update June 2017"
graphics: yes
output:
pdf_document :
word_document :
html_document :
linkcolor: blue
---
```{r setup, include=FALSE, cache=FALSE,warning=FALSE,message=FALSE}
library(knitr)
options(replace.assign=TRUE,width=90,xtable.comment = F)
opts_chunk$set(fig.show='hold',tidy=FALSE,
fig.width=8,fig.height=8,fig.scap=NA,highlight = T)
if (identical(knitr:::pandoc_to(), 'latex')) {
knit_hooks$set(plot = hook_plot_tex)
opts_chunk$set(fig.align="center",out.width="3in",out.height="3in")
}
if (identical(knitr:::pandoc_to(), 'html')) knit_hooks$set(plot = hook_plot_html)
```
# 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. We can however create internal links. E.g. this is a link to the [Session Info](#Session-Info-anchor) section.
See *Iris_data_set_vm7* for an example that is able to produce both html and pdf files with references to tables and figures. The Latex commands used for this are hidden in some functions.
# Libraries used
```{r echo=TRUE,warning=FALSE,message=FALSE}
library(ggplot2)
library(ggthemes)
```
```{r echo=FALSE,warning=FALSE,message=FALSE}
# constants/calculations we do not show in the text
numlist = 10 # number of observations in iris data set that is listed
```
# Load data
We load the iris data set in the workspace.
```{r}
data(iris)
```
# List the part of the iris data set
We list the first `r numlist` (because we set variable *numlist* to `r numlist` in a chunck we do not present to the reader) observations in the data set.
```{r results='asis'}
kable(iris[1:numlist,],row.names=F,longtable=F)
```
# 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.
```{r r1a,results='asis'}
p <- ggplot(iris, aes(Sepal.Length, Sepal.Width, colour = Species)) +
geom_point()
p + labs(title = 'default theme')
```
# Session Info {#Session-Info-anchor}
```{r}
sessionInfo()
```