knitr::opts_chunk$set( collapse = TRUE, comment = "#>", out.width = "70%", fig.align = "center", fig.width = 6, fig.asp = .618, fig.pos = "H" )
devtools::install_github("ygeunkim/rmdtool")
library(dplyr) library(ggplot2)
We generate simple data set.
set.seed(1) mydf <- tibble(x = rnorm(1000)) (mydf <- mydf %>% mutate(y = 3 * x + rnorm(1000)))
Numbering equations, figures, and tables is a key factor in documentation. Referencing helps these numbers meaningful and useful both when writing and reading.
library(rmdtool)
At the beginning of the document, excecute eqn_numbering() with results = 'asis' if you want to use equation referencing in html document. This writes the script:
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ TeX: { equationNumbers: { autoNumber: "AMS" } } }); </script>
eqn_numbering()
\begin{equation} \label{eq:regression} y_i = \beta_0 + \beta_1 x_i + \epsilon_i \end{equation}
Equation $\eqref{eq:regression}$ also works in html. See the Rmd file for the code.
You will use fig() and tab(). To know how to use these function, you should see the rmd file itself, not the rendered file.
Look at the fig.cap option below.
`r ''````r
To reference above figure, write
writeLines("$`r fig$ref(\"scat\")`$")
mydf %>% ggplot(aes(x, y)) + geom_point()
You can refer the above plot anywhere in the same file by $r fig$ref("scat")$
Similarly, tab() works for the table.
knitr::kable(head(mydf), caption = tab$cap("dftable", "Kable representation for tibble"))
To reference above table, write
writeLines("$`r tab$ref(\"dftable\")`$")
Now you can refer the above table by $r tab$ref("dftable")$
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.