This is a practice on how to use R markdown for reproducible research.
We are going to use ToothGrowth dataset.
Below is a code chunk:
Toothdata <- ToothGrowth
head(Toothdata)
## len supp dose
## 1 4.2 VC 0.5
## 2 11.5 VC 0.5
## 3 7.3 VC 0.5
## 4 5.8 VC 0.5
## 5 6.4 VC 0.5
## 6 10.0 VC 0.5
As you can see, from the running the ‘play’ button on the code.
fit <- lm(len ~ dose, data = Toothdata)
b <- fit$coefficients
plot(len ~ dose, data = Toothdata)
abline(lm(lm(len ~ dose, data = Toothdata)))
Figure 1: The tooth growth
This slop of the regression line is 9.7635714.
We can also put sections and subsections in out r markdown file, similar to numbers or buller points in a word document.
Make sure to put space after #, otherwise it will not work.
We can also add bullet points in the file.
We can really put nice quotes into the markdown doc by using ‘>’ symbol.
“Genes are like the story, and DNA is the language that the story is written in.”
— Sam Kean
Hyperlinks can also be incorporated into these files. This is especially useful in HTML, since they are in a web browser and will redirect the reader to the material that you are interested in showing them.
We can also put nice formatted formulas into markdown
Hard-Weinberg Formula
\[p^2 + 2pq + q^2 = 1\]
It can be really complex like
\[\Theta = \begin{pmatrix}\alpha & \beta\\ \gamma & \delta \end{pmatrix}\]
print("Hello world")
## [1] "Neko says meaww..."
Let’s talk about knitr, it interpretes the code chunk. There are the following options.
Eval (T or F): whether or not to evaluate the r code chunk.
Echo (T or F): whether or not to show the code for the chunk, but results will still print.
Cache: If enable, the same code chunk will not be evaluated the next time that the knitr is running.
fig.width or fig.height: The graphical device that represent the size of the plots in inches. The figure are first written to the knitr doc then to files that are saved separately.
out.width or out.height: The output size of the R plots in the R doc.
fig.cap: The words for the figure caption.
We can also add a table of contents to our HTML doc.
You can also add TABS in our report. To do this you need to specify each section that you want to give a tab by placing “{.tabset}” after the line.
We can always use different themes to change the HTML doc. Themes like: cerulean journal flatly readable spacelab united cosmo lumen paper sandstone simplex yeti null
We can also change color by specifying highlights: default tango payments kate monochrome espresso zenburn haddock textmate
Choose any one of them either theme or highlights.
You can also use the code_folding option like this: code_folding: hide
There are a TON of options in R markdown