首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >命名的R块不能被引用

命名的R块不能被引用
EN

Stack Overflow用户
提问于 2022-01-18 18:20:57
回答 1查看 37关注 0票数 1

下面的MWE应该通过引用\@ref(fig:chunk-label)正确地显示图形的数量,但是函数没有找到引用。是否有任何选项,我必须添加到块头,以实现正确的引用?

MWE:

代码语言:javascript
复制
    ---
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}

图书馆(Rpart)

图书馆(拨浪鼓)

图书馆(Tidyverse)

附加(汽车)

火车&mtcar

列车<-列车%>%

变异( .cols = everything(),~scale(.x))

创建决策树模型

树<- rpart(mpg~.,data=train,cp=.05)

用rpart.plot可视化决策树

fancyRpartPlot(树,yesno=2,split.col=“黑”,nn.col=“黑”,

代码语言:javascript
复制
           caption="Decision Tree Example for the irmi dataset",palette="Set3",branch.col="black")
代码语言:javascript
复制
 Figure \@ref(fig:decision-tree) shows an example of an decision tree for the irmi dataset. 

编辑:感谢斯特凡。我密切关注knitr/rmarkdown/Latex: How to cross-reference figures and tables?并更新了MWE。可悲的是,解决方案并没有解决问题!

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-01-18 19:21:38

这个问题相当微妙。要使您的引用工作,您必须在代码块和下面的文本之后添加一个中断行:

代码语言:javascript
复制
---
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}

图书馆(Rpart)

图书馆(拨浪鼓)

图书馆(Tidyverse)

附加(汽车)

火车&mtcar

列车<-列车%>%

变异( .cols = everything(),~scale(.x))

创建决策树模型

树<- rpart(mpg~.,data=train,cp=.05)

用rpart.plot可视化决策树

fancyRpartPlot(树,yesno=2,split.col=“黑”,nn.col=“黑”,

代码语言:javascript
复制
           caption="Decision Tree Example for the irmi dataset",palette="Set3",branch.col="black")
代码语言:javascript
复制
Figure \@ref(fig:decision-tree) shows an example of an decision tree for the irmi dataset. 

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/70760568

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档