The R Markdown document below is designed to output to a Microsoft Word file using a custom template. However, I’m having trouble getting cross-references to figures to work (clickable hyperlink) in the Word document. Does anyone know why?
---
title: "Minimal working example"
author: "Author's name"
date: "`r Sys.Date()`"
output:
bookdown::word_document2:
toc: false
number_sections: false
global_numbering: true
reference_docx: "template.docx"
---
```{r setup, include=FALSE}
# Let's setup a few things.
rm(list=ls())
library(knitr)
library(officedown)
library(officer)
library(ggplot2)
library(tidyverse)
library(broom)
library(flextable)
library(table1)
library(kableExtra)
library(boot)
# set chunks defaults
knitr::opts_chunk$set(
echo = FALSE,
message = FALSE,
warning = FALSE
)
# set flextable defaults
set_flextable_defaults(
font.family = "Arial Narrow",
font.size = 10,
theme_fun = "theme_booktabs",
big.mark="",
table.layout="autofit",
text.align = "center")
```
# Results
Results are presented in Figure \@ref(fig:scatterplot).
```{r scatterplot, fig.cap="Scatter plot", fig.height=4, fig.width=6, out.width="100%"}
## create scatter plot with random data points
set.seed(123)
data <- data.frame(x = rnorm(100), y = rnorm(100))
ggplot(data, aes(x = x, y = y)) +
geom_point() +
theme_minimal()
```