1

这是一个难以调试的问题,因为该问题似乎是由底层模板的怪癖引起的。

我对这个问题的总结是,ggplot2图表在使用某些模板和rvg::dml. 在使用默认模板导出到PPTX时使用.officer rvg::dml

我的问题是我需要在 PPTX 模板中进行哪些更改?

发生这种情况的示例模板在这里:sample_report_template.pptx

一个代表如下:

library(tidyverse)
library(rvg)
library(officer)


plot <- ggplot(mtcars, aes(x = disp, y = mpg)) +
  geom_point()

plot_rvg <- dml(ggobj = plot)

ppt_template <- read_pptx("new_template.pptx") %>%
  add_slide(layout = "standard", master = "default") %>%
  ph_with(plot, location = ph_location(left = 1.09, top = 3.03, height = 3.7, width = 9.4)) %>%
  add_slide(layout = "standard", master = "default") %>%
  ph_with(plot_rvg, location = ph_location(left = 1.09, top = 3.03, height = 3.7, width = 9.4))

print(ppt_template, "sample_report_template.pptx")


ppt_default <- read_pptx() %>%
  add_slide(layout = "Title and Content", master = "Office Theme") %>%
  ph_with(plot_rvg, location = ph_location(left = 1.09, top = 3.03, height = 3.7, width = 9.4))

print(ppt_default, "sample_report_default.pptx")


会话信息。

R version 4.0.3 (2020-10-10)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19043)

Matrix products: default

locale:
[1] LC_COLLATE=English_Australia.1252 
[2] LC_CTYPE=English_Australia.1252   
[3] LC_MONETARY=English_Australia.1252
[4] LC_NUMERIC=C                      
[5] LC_TIME=English_Australia.1252    

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

other attached packages:
 [1] gdtools_0.2.3   officer_0.4.0   rvg_0.2.5      
 [4] forcats_0.5.0   stringr_1.4.0   dplyr_1.0.7    
 [7] purrr_0.3.4     readr_2.0.2     tidyr_1.1.4    
[10] tibble_3.1.5    ggplot2_3.3.3   tidyverse_1.3.0
[13] clipr_0.7.1    

loaded via a namespace (and not attached):
 [1] tidyselect_1.1.1  haven_2.3.1      
 [3] colorspace_2.0-2  vctrs_0.3.8      
 [5] generics_0.1.0    utf8_1.2.2       
 [7] rlang_0.4.11      pillar_1.6.4     
 [9] glue_1.4.2        withr_2.4.2      
[11] DBI_1.1.1         dbplyr_2.0.0     
[13] modelr_0.1.8      readxl_1.3.1     
[15] uuid_0.1-4        lifecycle_1.0.1  
[17] munsell_0.5.0     gtable_0.3.0     
[19] cellranger_1.1.0  rvest_1.0.0      
[21] zip_2.1.1         labeling_0.4.2   
[23] tzdb_0.1.2        fansi_0.5.0      
[25] broom_0.7.6       Rcpp_1.0.7       
[27] scales_1.1.1      backports_1.2.1  
[29] jsonlite_1.7.2    farver_2.1.0     
[31] fs_1.5.0          systemfonts_0.3.2
[33] digest_0.6.27     hms_1.1.1        
[35] stringi_1.7.5     grid_4.0.3       
[37] cli_3.0.1         tools_4.0.3      
[39] magrittr_2.0.1    crayon_1.4.1     
[41] pkgconfig_2.0.3   ellipsis_0.3.2   
[43] xml2_1.3.2        reprex_0.3.0     
[45] lubridate_1.8.0   assertthat_0.2.1 
[47] httr_1.4.2        rstudioapi_0.13  
[49] R6_2.5.1          compiler_4.0.3 
4

0 回答 0