I'm trying to get my figure captions to work but i have some problems. Either my captions won't work properly or my header will show under the figure.
I have tried will \newpage, \pagebreak, \ at all possible positions, fig.pos, fig.height and fig.width but nothing seems to work. Can't get both the caption to show and the header over the figure.
This is my code:
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
I'm not able to reproduce your problem, #Oscar. I did have to adjust your code slightly to get it to work:
---
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()
```
My 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
Related
When I try to render an rmarkdown file with a ggplot image, all the chunks work that do not contain a ggplot image and it fails without an error when it tries to run said chunk.
The output I get in my terminal is
Killed
It runs fine on my local machine with the latest version of R and all the packages updated.
Below is the environment I am using in docker to try to run the same thing (when it fails).
R version 3.4.1 (2017-06-30)
Platform: x86_64-redhat-linux-gnu (64-bit)
Running under: Amazon Linux AMI 2017.09
Matrix products: default
BLAS/LAPACK: /usr/lib64/R/lib/libRblas.so
locale:
[1] C
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] bindrcpp_0.2.2 blogdown_0.10 rmarkdown_1.11 here_0.1
[5] PRROC_1.3.1 DT_0.5 forcats_0.3.0
stringr_1.3.1
[9] dplyr_0.7.8 purrr_0.2.5 readr_1.3.1
tidyr_0.8.2
[13] tibble_2.0.1 ggplot2_3.1.0 tidyverse_1.2.1
data.table_1.12.0
loaded via a namespace (and not attached):
[1] Rcpp_1.0.0 lubridate_1.7.4 lattice_0.20-35
assertthat_0.2.0
[5] rprojroot_1.3-2 digest_0.6.18 mime_0.6 R6_2.3.0
[9] cellranger_1.1.0 plyr_1.8.4 backports_1.1.3 evaluate_0.12
[13] httr_1.4.0 pillar_1.3.1 rlang_0.3.1
lazyeval_0.2.1
[17] readxl_1.2.0 rstudioapi_0.9.0 Matrix_1.2-10
reticulate_1.10
[21] htmlwidgets_1.3 munsell_0.5.0 shiny_1.2.0 broom_0.5.1
[25] compiler_3.4.1 httpuv_1.4.5.1 modelr_0.1.2 xfun_0.4
[29] pkgconfig_2.0.2 htmltools_0.3.6 tidyselect_0.2.5 crayon_1.3.4
[33] withr_2.1.2 later_0.7.5 grid_3.4.1 nlme_3.1-131
[37] jsonlite_1.6 xtable_1.8-3 gtable_0.2.0 magrittr_1.5
[41] scales_1.0.0 cli_1.0.1 stringi_1.2.4
promises_1.0.1
[45] xml2_1.2.0 generics_0.0.2 tools_3.4.1 glue_1.3.0
[49] hms_0.4.2 crosstalk_1.0.0 yaml_2.2.0
colorspace_1.4-0
[53] rvest_0.3.2 knitr_1.21 bindr_0.1.1 haven_2.0.0
I didn't find any results on my internet calls. How to fix this error is caused?
library(ggplot2)
ggplot(data = mtcars, aes(x=disp , y=wt)) +
geom_point(stat = "identity")
result;
Error: Can't find stat called "identity"
My sessionInfo()
R version 3.5.1 (2018-07-02)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 18.04.1 LTS
Matrix products: default
BLAS: /usr/lib/x86_64-linux-gnu/blas/libblas.so.3.7.1
LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.7.1
locale:
[1] LC_CTYPE=tr_TR.UTF-8 LC_NUMERIC=C
[3] LC_TIME=tr_TR.UTF-8 LC_COLLATE=tr_TR.UTF-8
[5] LC_MONETARY=tr_TR.UTF-8 LC_MESSAGES=tr_TR.UTF-8
[7] LC_PAPER=tr_TR.UTF-8 LC_NAME=C
[9] LC_ADDRESS=C LC_TELEPHONE=C
[11] LC_MEASUREMENT=tr_TR.UTF-8 LC_IDENTIFICATION=C
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] ggplot2_3.1.0 shiny_1.2.0
loaded via a namespace (and not attached):
[1] Rcpp_1.0.0 pillar_1.3.0 compiler_3.5.1
[4] cellranger_1.1.0 RColorBrewer_1.1-2 later_0.7.5
[7] plyr_1.8.4 bindr_0.1.1 forcats_0.3.0
[10] tools_3.5.1 digest_0.6.18 viridisLite_0.3.0
[13] jsonlite_1.5 tibble_1.4.2 gtable_0.2.0
[16] pkgconfig_2.0.2 rlang_0.3.0.1 ggplotgui_1.0.0
[19] rstudioapi_0.8 yaml_2.2.0 haven_1.1.2
[22] bindrcpp_0.2.2 withr_2.1.2 stringr_1.3.1
[25] httr_1.3.1 dplyr_0.7.8 htmlwidgets_1.3
[28] hms_0.4.2 grid_3.5.1 tidyselect_0.2.5
[31] data.table_1.11.8 glue_1.3.0 R6_2.3.0
[34] plotly_4.8.0 readxl_1.1.0 readr_1.1.1
[37] tidyr_0.8.2 purrr_0.2.5 magrittr_1.5
[40] scales_1.0.0 promises_1.0.1 htmltools_0.3.6
[43] assertthat_0.2.0 xtable_1.8-3 mime_0.6
[46] colorspace_1.3-2 httpuv_1.4.5 stringi_1.2.4
[49] lazyeval_0.2.1 munsell_0.5.0 crayon_1.3.4
choroplethrZip is returning a "cannot add bindings" error even when I use example code like the following:
library(choroplethrZip)
data(df_pop_zip)
zip_choropleth(df_pop_zip,
state_zoom = "new york",
title = "2012 New York State ZCTA Population Estimates",
legend = "Population")
Error in c$subtitle = subtitle :
cannot add bindings to a locked environment
sessionInfo()
R version 3.5.1 (2018-07-02)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 7 x64 (build 7601) Service Pack 1
Matrix products: default
locale:
[1] LC_COLLATE=English_United States.1252 LC_CTYPE=English_United States.1252 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] choroplethrZip_1.5.0
loaded via a namespace (and not attached):
[1] httr_1.3.1 maps_3.3.0 splines_3.5.1 Formula_1.2-3 assertthat_0.2.0 sp_1.3-1 latticeExtra_0.6-28
[8] yaml_2.1.19 pillar_1.3.0 backports_1.1.2 lattice_0.20-35 glue_1.3.0 uuid_0.1-2 digest_0.6.15
[15] RColorBrewer_1.1-2 checkmate_1.8.5 colorspace_1.3-2 htmltools_0.3.6 Matrix_1.2-14 plyr_1.8.4 XML_3.98-1.12
[22] pkgconfig_2.0.1 WDI_2.5 purrr_0.2.5 scales_0.5.0 jpeg_0.1-8 tigris_0.7 ggmap_2.6.1
[29] htmlTable_1.12 tibble_1.4.2 ggplot2_3.0.0 nnet_7.3-12 lazyeval_0.2.1 proto_1.0.0 survival_2.42-6
[36] RJSONIO_1.3-0 magrittr_1.5 crayon_1.3.4 maptools_0.9-2 acs_2.1.3 foreign_0.8-71 class_7.3-14
[43] tools_3.5.1 data.table_1.11.4 geosphere_1.5-7 RgoogleMaps_1.4.2 stringr_1.3.1 munsell_0.5.0 cluster_2.0.7-1
[50] bindrcpp_0.2.2 compiler_3.5.1 e1071_1.6-8 rlang_0.2.1 classInt_0.2-3 units_0.6-0 grid_3.5.1
[57] rstudioapi_0.7 rjson_0.2.20 rappdirs_0.3.1 htmlwidgets_1.2 base64enc_0.1-3 gtable_0.2.0 DBI_1.0.0
[64] reshape2_1.4.3 R6_2.2.2 gridExtra_2.3 knitr_1.20 dplyr_0.7.6 rgdal_1.3-3 bindr_0.1.1
[71] choroplethr_3.6.2 Hmisc_4.1-1 stringi_1.1.7 Rcpp_0.12.18 mapproj_1.2.6 sf_0.6-3 rpart_4.1-13
[78] acepack_1.4.1 png_0.1-7 spData_0.2.9.0 tidyselect_0.2.4
The new ggplot version (3.0.0) necessitates an edit to the choroplethrZip package's zip_choropleth.R, as package author Ari Lamstein described for the choroplehtr package at https://arilamstein.com/blog/2018/06/27/choroplethr-v3-6-2-is-now-on-cran/:
Add a comma after the last function (render_helper) in zip_choropleth.R and then insert this code:
theme_clean = function()
{
ggplot2::theme_void()
},
theme_inset = function()
{
ggplot2::theme_void() %+replace%
ggplot2::theme(legend.position = "none")
}
You will need a local version of the package, which you can download from https://github.com/arilamstein/choroplethrZip. Edit zip_choropleth.R and then locally install the code with the devtools package a la:
devtools::install_local('C:/Users/RickPack/Downloads/choroplethrZip-master')
Has anyone experienced having their plot labels cropped in knitted PDF's in Linux? This does not happen in my Windows machine.
Here is a minimal r-markdown example to replicate this problem.
---
output:
pdf_document:
keep_tex: true
---
---
{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
---
---
{r pressure, echo=FALSE}
plot(pressure)
---
Here is the output.
I have submitted this as a bug report here.
sessionInfo()
R version 3.4.4 (2018-03-15)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: elementary OS 0.4.1 Loki
Matrix products: default
BLAS: /usr/lib/libblas/libblas.so.3.6.0
LAPACK: /usr/lib/lapack/liblapack.so.3.6.0
locale:
[1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C LC_TIME=en_US.UTF-8
[4] LC_COLLATE=en_US.UTF-8 LC_MONETARY=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8
[7] LC_PAPER=en_US.UTF-8 LC_NAME=C LC_ADDRESS=C
[10] LC_TELEPHONE=C LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C
attached base packages:
[1] stats grDevices utils datasets graphics methods base
loaded via a namespace (and not attached):
[1] tseries_0.10-44 httr_1.3.1 tufte_0.3
[4] tidyr_0.8.0 jsonlite_1.5 uroot_2.0-9
[7] modelr_0.1.1 assertthat_0.2.0 TTR_0.23-3
[10] selectr_0.4-1 cellranger_1.1.0 yaml_2.1.18
[13] progress_1.2.0 pillar_1.2.2 backports_1.1.2
[16] lattice_0.20-35 glue_1.2.0 quadprog_1.5-5
[19] digest_0.6.15 rvest_0.3.2 colorspace_1.3-2
[22] htmltools_0.3.6 plyr_1.8.4 psych_1.8.3.3
[25] timeDate_3043.102 pkgconfig_2.0.1 broom_0.4.4
[28] haven_1.1.1 purrr_0.2.4 scales_0.5.0.9000
[31] git2r_0.21.0 tibble_1.4.2 ggplot2_2.2.1.9000
[34] withr_2.1.2 urca_1.3-0 nnet_7.3-12
[37] ansistrings_1.0.0.9000 lazyeval_0.2.1 cli_1.0.0.9002
[40] quantmod_0.4-13 mnormt_1.5-5 magrittr_1.5
[43] crayon_1.3.4 readxl_1.1.0 memoise_1.1.0
[46] evaluate_0.10.1 nlme_3.1-131.1 forcats_0.3.0
[49] xts_0.10-2 xml2_1.2.0 foreign_0.8-69
[52] rsconnect_0.8.8 tools_3.4.4 prettyunits_1.0.2
[55] hms_0.4.2 stringr_1.3.0 munsell_0.4.3
[58] bindrcpp_0.2.2 compiler_3.4.4 rlang_0.2.0.9001
[61] grid_3.4.4 rstudioapi_0.7 labeling_0.3
[64] rmarkdown_1.9 gtable_0.2.0 fracdiff_1.4-2
[67] curl_3.2 reshape2_1.4.3 R6_2.2.2
[70] zoo_1.8-1 lubridate_1.7.4 knitr_1.20
[73] dplyr_0.7.4 utf8_1.1.3 bindr_0.1.1
[76] rprojroot_1.3-2 readr_1.1.1 stringi_1.1.7
[79] parallel_3.4.4 Rcpp_0.12.16 lmtest_0.9-36
I have problem with the function ggparagraph() from ggpubr package. Its content is not drawing. If I use the function:
example(ggparagraph)
The plot is drawing without any problem, but the "ggparagraph area" (below plot) is empty. The same problem is if I use custom scripts, where the ggparagraph is applied.
R does not print any error message. Where can be the problem?
My session info is:
sessionInfo()
R version 3.4.1 (2017-06-30)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 15063)
Matrix products: default
locale:
1 LC_COLLATE=Slovak_Slovakia.1250 LC_CTYPE=Slovak_Slovakia.1250
[3] LC_MONETARY=Slovak_Slovakia.1250 LC_NUMERIC=C
[5] LC_TIME=Slovak_Slovakia.1250
attached base packages:
1 stats graphics grDevices utils datasets methods base
other attached packages:
1 ggpubr_0.1.4 magrittr_1.5 gridExtra_2.2.1 dplyr_0.7.2
[5] purrr_0.2.3 readr_1.1.1 tidyr_0.6.3 tibble_1.3.3
[9] ggplot2_2.2.1 tidyverse_1.1.1
loaded via a namespace (and not attached):
1 Rcpp_0.12.12 cellranger_1.1.0 compiler_3.4.1 plyr_1.8.4
[5] bindr_0.1 forcats_0.2.0 tools_3.4.1 jsonlite_1.5
[9] lubridate_1.6.0 nlme_3.1-131 gtable_0.2.0 lattice_0.20-35
[13] pkgconfig_2.0.1 rlang_0.1.2 psych_1.7.5 parallel_3.4.1
[17] haven_1.1.0 bindrcpp_0.2 xml2_1.1.1 stringr_1.2.0
[21] httr_1.2.1 hms_0.3 cowplot_0.8.0 grid_3.4.1
[25] glue_1.1.1 R6_2.2.2 readxl_1.0.0 foreign_0.8-69
[29] reshape2_1.4.2 modelr_0.1.1 scales_0.4.1 rvest_0.3.2
[33] assertthat_0.2.0 mnormt_1.5-5 colorspace_1.3-2 labeling_0.3
[37] stringi_1.1.5 lazyeval_0.2.0 munsell_0.4.3 broom_0.4.2
Finally, I don't find where is the problem, but if I install this package from github (instead of CRAN), all paragraphs are rendered correctly.