如何在Rmarkdown文档(书本)中交叉引用Cowplot子图标签?

时间:2019-08-15 12:44:18

标签: r ggplot2 knitr cross-reference cowplot

我有一个针织R块,其中多个ggplot2使用Cowplot排列到一个图形并使用Cowplot标签进行标记。

我想在图中引用图中的各个图形,即1A,1B,1C

我尝试了fig.subcap knitr选项,但随后得到了附加标签:(a),(b),(c)。 我不想使用(a),(b),(c),而只使用我的Cowplot标签,因为很容易更改Cowplot标签(位置,命名等),并且用Cowplot安排子图(我个人的ggplot2s)很容易。

我尝试了fig.subcap,但随后在无法更改的位置上得到了不必要的标签(a),(b),(c) 块选项

```{r figure, fig.cap= 'myFigure', fig.subcap=c('A', 'B', 'C')}
    ```

我按预期获得每个单独子图下的(a)A,(b)B,(c)C。 我希望在每个子图的侧面都绘制考图标签A,B,C。

我试图创建空的子标题标签

---
title: "t"
author: "a"
date: "d"
site: bookdown::bookdown_site
documentclass: paper
link-citations: yes

output:
 bookdown::pdf_book:
   extra_dependencies: subfig
---

```{r}
library(ggplot2)
library(cowplot)
g1 = ggplot()+geom_line(aes(x = c(1, 2), y = c(1, 2)))
g2 = ggplot()+geom_line(aes(x = c(1, 2), y = c(1, 2)))
g3 = ggplot()+geom_line(aes(x = c(1, 2), y = c(1, 2)))
cp = plot_grid(g1, g2, g3,  nrow = 3, align = "hv", labels = c('A', 'B', 'C'))
    ``` 

```{r fi, fig.cap= 'myFigure', fig.subcap=c('', '', '')}
cp
    ```

and then cross-reference in the text with
\@ref(fig:fi1), \@ref(fig:fi2), \@ref(fig:fi2)

但是这不起作用,因为它注意到我只包含一个Cowplot(cp)。

我还试图在Cowplot之外添加空图:

---
title: "t"
author: "a"
date: "d"
site: bookdown::bookdown_site
documentclass: paper
link-citations: yes

output:
 bookdown::pdf_book:
   extra_dependencies: subfig
---

```{r}
library(ggplot2)
library(cowplot)
g1 = ggplot()+geom_line(aes(x = c(1, 2), y = c(1, 2)))
g2 = ggplot()+geom_line(aes(x = c(1, 2), y = c(1, 2)))
g3 = ggplot()+geom_line(aes(x = c(1, 2), y = c(1, 2)))
cp = plot_grid(g1, g2, g3,  nrow = 3, align = "hv", labels = c('A', 'B', 'C'))
    ``` 

```{r f, fig.cap= 'myFigure', fig.subcap=c('', '', '')}
cp
plot.new()
plot.new()
    ```

Then I can use the empty plots as substitutes 
for the subfigures in the cowplot and cross-reference 
them with \@ref(fig:f1), \@ref(fig:f2), 
\@ref(fig:f2). 

但是没有给出Cowplot(cp)的对齐方式,但仍然从子图中得到一个不必要的(a)。

0 个答案:

没有答案
相关问题