This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.
When you click the Knit button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:
summary(cars)
## speed dist
## Min. : 4.0 Min. : 2.00
## 1st Qu.:12.0 1st Qu.: 26.00
## Median :15.0 Median : 36.00
## Mean :15.4 Mean : 42.98
## 3rd Qu.:19.0 3rd Qu.: 56.00
## Max. :25.0 Max. :120.00
You can also embed plots, for example:
This is a tutorial on how to use R markdwon for reproducible research
Here we can type long passages or descriptions of our data withotu the need fo “hashing” out or comments with the # symbol. in our first example, we will be using the ToothGrowth dataset. In this experiment, Guinea Pigs were given different amounts of vitamin v to see the effects on the animal’s tooth growth.
To run R code i nmarkdown file, we need to denotate teh section taht is considered R code. We call these “code chunks.”
belwo is the 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 running the “play” button on the code chunk, the results are printed inline of the r markdown file.
fit <- lm(len ~ dose, data = ToothGrowth)
b <- fit$coefficients
plot(len ~ dose, data = toothdata)
abline(lm(len ~ dose, data = toothdata))
The slope of the regression line is ‘r b[2]’.
we can also put sections and subsections in our r markdown file, similar to numbers or bullet points in a word doccument. This is doen with the “#” that we previously ised to denote text in an R script
make sure that you put a space after hashtag, otherwise it will not work
we can also add bullet point marks in our r markdown file
Its important to note here that in R markdown indentation matters
we can put really nice quotes into the markdown document. we do this by using the “>” symbol.
“Genes are like the story, and DNA is the lanaguage taht the story is writte in.”
— Sam Kean
Hyperlinks can also be incorporated into these files. This is especially useful in HTML files, since they are in a web browser and will redirect the reader to the material that you are interested in showing them. Here we will use the link to the R markdown homepage for this example. Rmarkdown
We can also put formatted formulas into markdown using two dollar signs
Hardy-Weinberg formula
\[p^2 + 2pq + q^2 = 1\] And you can get really complex as well!
\[\Theta = \begin{pmatrix}\alpha & \beta\\ \gamma & \delta \end{pmatrix}\]
## [1] "Hello World"
## [1] "Hello World"
there are also options for your R markdown file knitr interprets the code chunk. There are teh following options.
Eval (T or F): whether or not the evaluate the code chunk
Echo (T or F): whether or not to show code for the chunck, but results will stil print.
Cache: If enable, the same code chunck will not be evaluated the next time taht the knitr is run. Great for code that has long runtimes.
fig.width or fig.height: the (graphical device) size of the R polts in inches. the figures are first written to the knitr document then to files that are saved separately.
out.width or out.height: the output soze of the R plots in the R document
fig.cap: the words for the figure caption
we can also add a table of contents to our HTML Document. We do this by altering the YAML code (the erid code chunk at the VERY TOP of the document.) we can add this:
title: “HTML” author: “Emma Daniel” date: “3/30/2022” output: html_document: toc: true toc_float: true
this will gie up a very nice floating table of contents on the right side of the document.
you can also add tabs in our report. To do this you need to specify each section you want to becoe a table by placing {.tabset} after the line. Every subsequent header will be a new tab.
you can also add themes to your HTML document that change the highlightig color and hyperlink color of you html output. This can be nice astherticaly. to do this, you chagne your thieme in the YAML to one of the following:
cerulean journal flatly readbale spacelab united cosmo lumen paper sandstone simplex yeti null
You can also change the color by specifying highlight:
default tango payments kate monochrome espresso zenburn haddock textmate
you can also use the code_folding option to allow the reader to toggle between displaying and hiding the code. This done with:
code_folding: hide
There are a ton of options and ways for you to customize R code using the HTML format. This is also a great way to display a “portfolio” of your rwork if you are tyring to market yourself to intersted parties.