Subfigures or Subcaptions with knitr that span more than one page?

好久不见. 提交于 2020-05-17 08:46:39

问题


Very similar to this post. However I have more plots than that fit on one page causing the remaining plots to be cut off after pressing Knit. Does any one know how to solve this by plotting the other plots on the next page?

title: 'title'
author: "--"
date: "`r Sys.Date()`"
output: pdf_document
header-includes:
  - \usepackage{subfig}
  - \usepackage{float}

## To make the example more reproducible ##

```{r echo=FALSE, message=FALSE}
knitr::opts_chunk$set(fig.width=6, fig.height=9, fig.show="hold", 
hightligh=TRUE, warnings=TRUE, error=FALSE, cache=FALSE, echo=FALSE, 
dpi=100)
```

```{r test, fig.cap='A collection of figs', fig.subcap= "-", out.width="49%", fig.asp=1, fig.ncol = 2, fig.show = 
"asis", fig.align="center"}

       for (ii in 1:10) {
       plot(1:3, 1:3, main=ii)
       }

```

## this part is only to resemble the answer by *Michael Harper* in the post mentioned before and should be uncommented to replicate (google maps API needed) ## 

# ```{r}
# locations <- c("Southampton, UK", "London, UK", "Bristol, UK", 
# "Birmingham, UK", "Liverpool, UK", "Southampton, UK", "London, UK", 
# "Bristol, UK", "Birmingham, UK", "Liverpool, UK") 
# ggmap::register_google(key = "....")
# ```

# ```{r fig-sub-2, fig.cap='A collection of maps', fig.subcap= locations, 
# out.width='.49\\linewidth', fig.asp=1, fig.ncol = 2}
# library(ggmap)
# lapply(locations, function(x) 
# ggmap(get_map(x))
# )
# ```

The answer from Michael Harper in the same post got me quite far but not to the point that the number of plots exceed the number of plots that fit on one page.

output form the code above showing only 6 out of 10 plots

来源:https://stackoverflow.com/questions/61526548/subfigures-or-subcaptions-with-knitr-that-span-more-than-one-page

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!