Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve tables and figures captions workflow #21

Open
kguidonimartins opened this issue Jun 22, 2019 · 0 comments
Open

Improve tables and figures captions workflow #21

kguidonimartins opened this issue Jun 22, 2019 · 0 comments
Assignees

Comments

@kguidonimartins
Copy link
Owner

kguidonimartins commented Jun 22, 2019

Setup {captioner}

tab_cap <- captioner(prefix="Table")

tab_ref <- function(label){
  stringr::str_extract(label, "[^:]*")
}

fig_cap <- captioner(prefix ="Figure")

fig_ref <- function(label){
  stringr::str_extract(label, "[^:]*")
}

Generate figs at high resolution:

tiff(filename="images/plot1.tiff", res=200, height=200/72*500, width=200/72*500)
plot(1)
dev.off()

tiff(filename="images/plot2.tiff", res=200, height=200/72*500, width=200/72*500)
plot(2)
dev.off()

Captions definition must be in order:

\```{r figs_caps, include=FALSE}

fig_cap_plot1 <- 
  fig_cap(
    name = "`r fig_ref(fig_cap_plot1)`plot1", 
    caption = "My plot 1."
    )

fig_cap_plot2 <- 
  fig_cap(
    name = "plot2", 
    caption = "My plot 2."
    )
\```

Call figs reference in the text:

Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua `r fig_ref(fig_cap_plot1)`. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat `r fig_ref(fig_cap_plot2)`.

I prefer to call figs as follows:

\```{r, echo=FALSE, eval=TRUE, results='asis', fig.height=10, fig.width=10, fig.cap=fig_cap_plot1}
grid::grid.raster(readTIFF(source = "images/plot1.tiff"))
\```

Then break the page wit the {minimalTemplate} trick and call another fig:

##### page break

\```{r, echo=FALSE, eval=TRUE, results='asis', fig.height=10, fig.width=10, fig.cap=fig_cap_plot2}
grid::grid.raster(readTIFF(source = "images/plot2.tiff"))
\```
@kguidonimartins kguidonimartins self-assigned this Apr 4, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant