## ----setup, include = FALSE---------------------------------------------------
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
dpi = 300,
dev = "png"
)
library(gridmicrotex)
library(grid)
## ----inline, fig.height = 0.8, fig.width = 6, out.width = "90%"---------------
grid.newpage()
grid.markdown(
r"(The **fitted** $\hat{\beta} = (X^\top X)^{-1} X^\top y$ has ~~no~~ `se` = *0.42*.)",
x = 0.02, hjust = 0, gp = gpar(fontsize = 13)
)
## ----html-css, fig.height = 1.3, fig.width = 6, out.width = "90%", dev = "ragg_png", dev.args = list()----
grid.newpage()
grid.markdown(
r"(Model fit,
serif and
mono.
The **residual** for H0
is within $2\sigma$.)",
x = 0.02, y = 0.9, hjust = 0, vjust = 1, gp = gpar(fontsize = 13)
)
## ----block, fig.height = 4, fig.width = 4.6, out.width = "80%"----------------
md <- r"(
# Model summary
The slope is $\beta_1$ with *p* < 0.001, and this paragraph is long
enough that it wraps inside the column.
## Diagnostics
- residuals look **fine**
- $R^2 = 0.87$
- no influential points
~~~r
fit <- lm(y ~ x, data = d) # refit
if (anyNA(d)) {
stop("missing values")
}
~~~
> Assumptions were checked and hold.
)"
grid.newpage()
grid.draw(markdown_box_grob(
md,
width = unit(4.6, "in"),
padding = unit(10, "pt"),
box_gp = gpar(fill = "grey97", col = "grey40"),
gp = gpar(fontsize = 13),
style = markdown_style(css = "pre { background: #ece2f0 }") # Code background
))
## ----lists-tables, fig.height = 2, fig.width = 4.4, out.width = "80%"---------
md <- r"(
### Checklist
- [x] fit the model
- [ ] write it up
Coefficients:
| term | $\beta$ | *p* |
|:-----|------------:|:---:|
| intercept | 30.1 | *** |
| slope | -5.3 | *** |
)"
grid.newpage()
grid.draw(markdown_box_grob(
md,
width = unit(4.4, "in"),
padding = unit(8, "pt"),
gp = gpar(fontsize = 13)
))
## ----image, fig.height = 1.8, fig.width = 4, out.width = "70%"----------------
# Any .png / .jpeg path works; this one ships with the png package.
img <- system.file("img", "Rlogo.png", package = "png")
md <- sprintf("
A figure with a caption below it.

The caption explains the figure.
", img)
grid.newpage()
grid.draw(markdown_box_grob(
md, width = unit(4, "in"), padding = unit(8, "pt"),
gp = gpar(fontsize = 13)
))
## ----style-css, fig.height = 1.2, fig.width = 5, out.width = "85%"------------
doc <- r"(
# Results
The slope is $\beta_1$ with *p* < 0.001.
> Worth a second look.
)"
grid.newpage()
grid.draw(markdown_box_grob(
doc,
width = unit(4.5, "in"), padding = unit(10, "pt"),
style = "
h1 { color: steelblue; font-size: 1.8rem }
blockquote { color: grey40; border-left: 3px solid steelblue }
",
gp = gpar(fontsize = 13)
))
## ----style-r, eval = FALSE----------------------------------------------------
# markdown_style(
# h1 = md_style(color = "steelblue", font_size = 1.8),
# blockquote = md_style(color = "grey40",
# border_left = "3px solid steelblue")
# )
## ----style-preset, eval = FALSE-----------------------------------------------
# markdown_style("github", h1 = md_style(color = "firebrick"))
# file.show(system.file("css", "github.css", package = "gridmicrotex"))
## ----style-div, fig.height = 1, fig.width = 5, out.width = "85%"--------------
doc <- '
Ordinary text.
| an HTML table is dropped |