我正在尝试使图形标题正常工作,但是我有一些问题。我的字幕无法正常工作,或者标题将显示在图形下方。
我尝试过将\ newpage,\ pagebreak,\放在所有可能的位置,Fig.pos,Fig.height和Fig.Width,但似乎没有任何作用。无法同时显示标题和图形上方的标题。
这是我的代码:
output: pdf_document
fig_caption: yes
graphics: yes
keep_tex: yes
---
### Header(Will get under the plot in the pdf)
```{r plot, fig.cap="Hello World!"}
ggplot(data, aes(x=x, y=y)) + geom+point()
```
Text text text text text text text
sessionInfo()
R version 3.4.2 (2017-09-28)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: macOS 10.14
Matrix products: default
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] ggfortify_0.4.6 ggplot2_2.2.1 dplyr_0.7.4 knitr_1.17 pxweb_0.9.1
loaded via a namespace (and not attached):
[1] Rcpp_0.12.13 bindr_0.1 compiler_3.4.2 highr_0.6 plyr_1.8.4 tools_3.4.2
[7] digest_0.6.18 gtable_0.2.0 jsonlite_1.5 evaluate_0.10.1 tibble_1.3.4 checkmate_1.8.5
[13] viridisLite_0.2.0 pkgconfig_2.0.1 rlang_0.1.4 rstudioapi_0.7 curl_3.1 yaml_2.1.14
[19] bindrcpp_0.2 gridExtra_2.3 httr_1.3.1 stringr_1.2.0 xml2_1.2.0 hms_0.4.2
[25] grid_3.4.2 rprojroot_1.3-2 webshot_0.5.1 glue_1.2.0 data.table_1.10.4-3 R6_2.2.2
[31] rmarkdown_1.8 RJSONIO_1.3-0 purrr_0.2.4 tidyr_0.7.2 readr_1.1.1 magrittr_1.5
[37] backports_1.1.1 scales_0.5.0 htmltools_0.3.6 assertthat_0.2.0 rvest_0.3.2 colorspace_1.3-2
[43] stringi_1.1.6 lazyeval_0.2.1 munsell_0.4.3
答案 0 :(得分:0)
我无法重现您的问题,@ Oscar。我确实需要稍微调整您的代码才能使其正常工作:
---
output: pdf_document
fig_caption: yes
graphics: yes
keep_tex: yes
---
### Header(Will get under the plot in the pdf)
```{r plot, fig.cap="Hello World!"}
library(ggplot2)
ggplot(mtcars, aes(x=mpg, y=cyl)) + geom_point()
```
我的sessionInfo:
R version 3.5.1 (2018-07-02)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows >= 8 x64 (build 9200)
Matrix products: default
locale:
[1] LC_COLLATE=English_United States.1252 LC_CTYPE=English_United States.1252
[3] LC_MONETARY=English_United States.1252 LC_NUMERIC=C
[5] LC_TIME=English_United States.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] scales_1.0.0 ggpubr_0.2 magrittr_1.5 lubridate_1.7.4 forcats_0.4.0 purrr_0.3.0
[7] readr_1.3.1 tibble_2.0.1 tidyverse_1.2.1 broom_0.5.1 xlsx_0.6.1 gridExtra_2.3
[13] stringr_1.4.0 ggplot2_3.1.0 tidyr_0.8.2 dplyr_0.8.0.1 plyr_1.8.4 knitr_1.21
loaded via a namespace (and not attached):
[1] tidyselect_0.2.5 xfun_0.4 rJava_0.9-10 haven_2.1.0 lattice_0.20-38
[6] colorspace_1.4-0 generics_0.0.2 htmltools_0.3.6 yaml_2.2.0 rlang_0.3.1
[11] pillar_1.3.1 glue_1.3.0 withr_2.1.2 RColorBrewer_1.1-2 modelr_0.1.4
[16] readxl_1.3.0 cellranger_1.1.0 munsell_0.5.0 gtable_0.2.0 rvest_0.3.2
[21] evaluate_0.13 labeling_0.3 xlsxjars_0.6.1 highr_0.7 Rcpp_1.0.0
[26] backports_1.1.3 jsonlite_1.6 hms_0.4.2 digest_0.6.18 stringi_1.3.1
[31] grid_3.5.1 cli_1.0.1 tools_3.5.1 lazyeval_0.2.1 crayon_1.3.4
[36] pkgconfig_2.0.2 xml2_1.2.0 assertthat_0.2.0 rmarkdown_1.11 httr_1.4.0
[41] rstudioapi_0.9.0 R6_2.4.0 nlme_3.1-137 compiler_3.5.1