0

I have a knitr R-chunk where multiple ggplot2s that are arranged to one figure using cowplot and labelled using cowplot labels.

I'd like to reference the individual plots in the figure, i.e. 1A, 1B, 1C, in my text

I've tried the fig.subcap knitr option, but then I get additional labels: (a), (b), (c). I do not want to use (a), (b), (c) but only my cowplot labels, as cowplot labels are easily changed (position, naming, etc.) and arranging subfigures (my individual ggplot2s) with cowplot is easy.

I tried fig.subcap but then I get unwanted labels (a), (b), (c) at positions that I cannot change Chunk-options

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

I obtain as expected (a) A, (b) B, (c) C below each individual subplot. I want cowplot labels A, B, C at the side of each individual subplot.

I tried to create empty subcap labels

---
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)

but that does not work as it notices that I only include the one cowplot (cp).

I also tried to include empty plots in addition to the 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). 

But the alignment of the cowplot (cp) is not given and I still get an unwanted (a) from subfigure.

Shudras
  • 117
  • 2
  • 8
  • Can you please [edit] your question to include a [mre] showing what you have tried? – Ralf Stubner Aug 16 '19 at 08:06
  • @ Ralf Stubner, I tired to add empty plots but the alignment of the plot of interest (cp) does not hold anymore and subfigure still places an unwanted (a). – Shudras Aug 16 '19 at 09:37
  • Please try to make a [mre] that can be used with copy and paste. See https://stackoverflow.com/a/57432788/8416610 for an example. The idea is to "show your code" instead of "telling us about it". – Ralf Stubner Aug 16 '19 at 09:54
  • I provided examples. – Shudras Aug 16 '19 at 13:44
  • Thanks. I now see what your problem is. However, I have no idea how to solve it. You are wrking against the system by using `subfig` for references but not for composition of the plots. – Ralf Stubner Aug 16 '19 at 21:58

0 Answers0