There we go. This is a proper Markdown document. Here I can type what I want. TO begin to code, we need to denote the secttion that R consders code.
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 running the “play” button on the code chunk. The results are printed inline the r markdown file.
fit <- lm(len ~ dose, data = Toothdata)
b <- fit$coefficients
plot(len ~ dose, data = Toothdata,
main = "Tooth Guineapig Analysis",
ylab = "Length of tooth",
xlab= "Drug dose")
abline(lm(len ~ dose, data = Toothdata))
Figure 1. The tooth growth of Guniea Pigs
The slope regression is 9.7635714
The y intercept is 7.4225
We can put sections in subsection in pour R markdown file similar to numbers or bullet óints ina word document. This is done with the # symbol that we previously used to denot thext in our R script.
Make sure that you put space after #, otherwise it will not work.
We can also add bullet point-type marks in our markdown file.
Its important to note here that in R Markdown indentation matters.
We can out quotes in Markdown document. 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 this files. This is specially useful in HTML files, since they are in a web browser and will redirect the reader to the material you are intersted in showing them. RMarkdown
We can put formulas using two dolar signs $
\[p^2 + 2pq + q^1 = 1\] You can get more complex
\[\Theta = \begin{pmatrix}\alpha & \beta & \alpha\\ \gamma & \delta & \alpha \end{pmatrix}\]
cat("Hello World")
## Hello World
Options on how knit (the one that compiles and interprets code)
Eval (T or F): whether or not to evaluate code output. code will still show Echo (T or F): whether or not you show the code. output will still show
Cache: If enable, same code will not be evaluated next time that knitter is run. Great for code with LONG run times.
fig.width or fig.height: the (graphical device) size of the R plots in inches. The figures are are first written into the knitter then to files that are separately. Good for publication purposes.
out.width or out.height: The ouput size of the R plots in the R DOCUMENT.
fig.cap: the words for the figure caption.
Add table of contents to our HTML Documents. alter YAML code (At the top of document —YAML—). EXAMPLE : title: “HTML” author: “Francisco Romo” date: “2023-12-12” output: html_document: toc: true toc_float: true
This gives us a nice floating table of contents in the document toc = table of documents.
You can also add tabs in our report. To do this you need to specify “{.tabset}” after the line.
You can also add themes to your HTML output. This can be nice aesthetically. To do this you change your theme in the YAML to one of the following:
cerulean journal flatly redeable spacelab united cosmo lumen paper sandstone simplex yeti null
Change color by specifying highlight:
default tango payments kate monochrome espresso zenburn haddock textmate
Allow reader to taggle between diplsaying the code and hiding the code. This is done with code_folding: hide
Thats the end