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. A useful guide to help you get started can be found here.
Rmarkdown is a great way to do reproducible research and generate reports.
File -> New File -> R Markdown...
Knit HTML
button up the top of the source window. You click that button to turn the markdown into HTML (or PDF or Word).r
, the (optional) chunk name and any arugments:
{r}` or `
{r chunk_name, tidy=TRUE}
. The chunk also ends with three back ticks
`
. Examples can be seen in the template that opens along as a new file in RStudio.You can embed static plots in an rmarkdown document without doing anything special. Important chunk options are fig.width
and fig.height
to set the figure width and height for example `
{r, fig.width=4, fig.height=6}
.
If you're sticking with HTML (as opposed to PDF or Word), you might like to take advantage of the interactive visualisations that leverage web technologies such as JavaScript. In this workshop we highlight pairsD3
and d3heatmap
. To include these in a rmarkdown document, the chunk need to have the option results='asis'
and it's safest to also set cache=FALSE
(sometimes this is required). For example, the below chunk begins with `
{r, results='asis', cache=FALSE}
data("artificialeg", package = "mplot")
d3heatmap::d3heatmap(cor(artificialeg))
data("diabetes", package = "mplot")
pairsD3::pairsD3(diabetes[, c("y", "tch", "hdl", "ldl", "tc")], group = diabetes$sex,
width = 600)