davidgohel / officer

:cop: officer: office documents from R
https://ardata-fr.github.io/officeverse/
Other
601 stars 107 forks source link

Can't add ggplot2 objects onto a PPT slide #212

Closed phoebewong closed 5 years ago

phoebewong commented 5 years ago

Hi,

I was trying to replicate the example code, but failed to add the ggplot2 plot onto the template ppt.

library(officer)
doc <- read_pptx()
if( require("ggplot2") ){
  doc <- add_slide(doc, layout = "Title and Content",
                   master = "Office Theme")
  gg_plot <- ggplot(data = iris ) +
    geom_point(mapping = aes(Sepal.Length, Petal.Length),
               size = 3) + theme_minimal()
  doc <- ph_with_gg(x = doc, value = gg_plot, type = "body" )
}
print(doc, target = "first_example.pptx") 

Here's the error message I got:

Error in external_img(file, width = width, height = height) : 
  file.exists(src) is not TRUE
In addition: Warning message:
In png(filename = file, width = width, height = height, units = "in",  :
Issues are a great way to keep track of tasks, enhancements, and bugs for your projects (https://guides.github.com/features/issues/). When submitting, you need to provide the following elements:

Here's my sessionInfo():

R version 3.6.0 (2019-04-26)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: macOS High Sierra 10.13.6

Matrix products: default
BLAS:   /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/3.6/Resources/lib/libRlapack.dylib

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] ggplot2_3.1.1 officer_0.3.4

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.1       rstudioapi_0.10  xml2_1.2.0       magrittr_1.5     tidyselect_0.2.5 munsell_0.5.0   
 [7] uuid_0.1-2       colorspace_1.4-1 R6_2.4.0         rlang_0.3.4      plyr_1.8.4       dplyr_0.8.1     
[13] tools_3.6.0      grid_3.6.0       gtable_0.3.0     withr_2.1.2      htmltools_0.3.6  lazyeval_0.2.2  
[19] digest_0.6.19    assertthat_0.2.1 tibble_2.1.2     crayon_1.3.4     zip_2.0.2        purrr_0.3.2     
[25] base64enc_0.1-3  glue_1.3.1       labeling_0.3     compiler_3.6.0   pillar_1.4.1     scales_1.0.0    
[31] pkgconfig_2.0.2 

Let me know if you have any clue of the error!

Thanks, Phoebe

davidgohel commented 5 years ago

Thanks Phoebe

I have no clue. I am not able to reproduce the error and it does not happen on CRAN nor travis. Can you run example of ph_with?

phoebewong commented 5 years ago

Hey David, hmm that's odd. The other examples worked for me, only the ggplot one did not.

Another officer user Megan has let me know that she ran into the same issue and solved by downloading XQuartz (from online) and the Cairo R package, in case anyone else also run into this issue in the future. Thanks for all the great work!

github-actions[bot] commented 2 years ago

This old thread has been automatically locked. If you think you have found something related to this, please open a new issue and link to this old issue if necessary.