Home > Mobile >  Named R-chunk can't be referd to
Named R-chunk can't be referd to

Time:01-19

The following MWE should correctly display the number of the figure by referring to it with \@ref(fig:chunk-label) yet the reference is not found by the function. Is there any option that I have to add to the chunk header to achieve a correct reference?

MWE :

    ---
title: "Untitled"
author: "dsf"
date: "18 1 2022"
output:
  bookdown::pdf_document2:
    keep_tex: yes
    fig_caption: true
    number_sections: true
toc: true
lot: true
lof: true
graphics: true
---

```{r decision-tree, fig.cap="Decision Tree Example for the strava irmi dataset", echo= FALSE, message = FALSE}
library(rpart)
library(rattle)
library(tidyverse)
attach(mtcars)
train <- mtcars
train <- train %>% 
  mutate(across( .cols = everything(),  ~scale(.x)))
# Create a decision tree model
tree <- rpart(mpg~., data=train, cp=.05)

# Visualize the decision tree with rpart.plot
fancyRpartPlot(tree,yesno=2,split.col="black",nn.col="black", 
               caption="Decision Tree Example for the irmi dataset",palette="Set3",branch.col="black")
```
 Figure \@ref(fig:decision-tree) shows an example of an decision tree for the irmi dataset. 

EDIT : Thanks to stefan. I followed enter image description here

  •  Tags:  
  • Related