Demo of using the R Markdown div notation with
::: used here to create multi-column output and a centred
heading.
Set echo=FALSE to make it tidier.
Markdown used is shown beneath the code before the output.
Discussion on my blog post.
library(ggthemes)
library(kableExtra)
library(ggplot2)
library(dplyr)
data("mtcars")
metric_cars <- mtcars %>%
mutate(
Engine = round(disp / 61.024, 1),
Economy = round(100 * 3.785411784 / (1.609344 * mpg), 1)
) %>%
select(Engine, Economy)
t <- metric_cars %>%
sample_n(10) %>%
kbl(col.names = c('Engine Size (L)', 'Fuel (L/100km)')) %>%
kable_styling() %>%
row_spec(0, font_size=10)
p <- metric_cars %>%
ggplot(aes(x=Engine, y=Economy)) +
geom_point() +
geom_smooth(formula = y ~ x, method = "loess", color = 'orange') +
theme_excel_new() +
theme(axis.title = element_text()) +
ylab('Fuel Consumption (L/100km)\n') +
xlab('\nEngine Size (L)') +
ggtitle('Fuel Consumption by Engine Size')
::: {align="center"
style="font-size:150%;font-weight:bold;"}
Engine Size vs Fuel Consumption
:::
::: columns
::: {.column width="35%"}
```{r}
t
```
:::
::: {.column width="2%"}
:::
::: {.column width="63%"}
```{r, fig.height=5, fig.width=7}
p
```
:::
:::
Engine Size vs Fuel Consumption
t
| Engine Size (L) | Fuel (L/100km) | |
|---|---|---|
| Toyota Corolla | 1.2 | 6.9 |
| Maserati Bora | 4.9 | 15.7 |
| Merc 240D | 2.4 | 9.6 |
| Merc 230 | 2.3 | 10.3 |
| Merc 280 | 2.7 | 12.3 |
| Porsche 914-2 | 2.0 | 9.0 |
| Mazda RX4 Wag | 2.6 | 11.2 |
| Dodge Challenger | 5.2 | 15.2 |
| Hornet 4 Drive | 4.2 | 11.0 |
| Merc 450SL | 4.5 | 13.6 |
p