Using a figure layout with computational images with different dimensions for the subfigures #7022
-
DescriptionCurrently it's possible to use a code chunk to generate a figure layout with the images created by the chunk, like so: See @fig-example-same-size-1 and @fig-example-same-size-2
```{r}
#| echo: false
#| label: fig-example-same-size
#| fig-cap: "Charts"
#| fig-subcap:
#| - "Cars"
#| - "Pressure"
#| layout-ncol: 2
plot(cars)
plot(pressure)
``` ![]()
It's possible to control the widths of those subplots too with the See @fig-example-different-sizes-1 and @fig-example-different-sizes-2
```{r}
#| echo: false
#| label: fig-example-different-sizes
#| fig-cap: "Charts"
#| fig-subcap:
#| - "Cars"
#| - "Pressure"
#| layout: "[[ 25, 75 ]]"
plot(cars)
plot(pressure)
``` ![]()
However, the dimensions are all squished because both images generated by the chunk use the same width and height. It would be neat to be able to feed a list of dimensions to As an alternative, it's possible to put the different figures in separate chunks and use a See @fig-example-multiple-chunks-1 and @fig-example-multiple-chunks-2.
::: {#fig-example-multiple-chunks layout="[[ 25, 75 ]]"}
```{r fig1, echo=FALSE, fig.width=2, fig.height=5}
#| fig-subcap: "Cars"
plot(cars)
```
```{r fig2, echo=FALSE, fig.width=6, fig.height=5}
#| fig-subcap: "Pressure"
plot(pressure)
```
Charts
::: This looks great! ![]()
But it no longer treats the plots as subfigures. The cross referencing is broken ("See ?@fig-example-multiple-chunks-1" appears in the text), and the captions don't have the "(a)" and "(b)" prefixes. Is there a way to get differently-sized computational images into a custom figure layout like this? Either with a vector of dimensions (like |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 19 replies
-
This should work Note that you should not mix "inline R option" and "yaml option" in the same code cell or expect unintended behaviour. |
Beta Was this translation helpful? Give feedback.
-
@cscheid Ha yes, force of habit. But also I've been keeping only fig.width and fig.height up in the chunk options because it seems to be the only way RStudio can recognize the correct dimensions (via rstudio/rstudio#4521), so my normal approach has been to put all chunk options as YAML except for dimensions. But that's a whole separate issue :) ![]() |
Beta Was this translation helpful? Give feedback.
Btw, this also works (surprisingly to me!)