Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Text slightly shifted in PPT output & width and height arguments ignored #31

Open
tomwenseleers opened this issue Oct 31, 2019 · 0 comments

Comments

@tomwenseleers
Copy link

tomwenseleers commented Oct 31, 2019

I am having trouble with text being slightly shifted vertically in the PPT output compared to what I see onscreen (e.g. the X axis labels touch the X axis tickmarks in the PPT when they don't touch onscreen). Also, the width & height argument appears to be ignored, as my graph is always stretched across the slide, which I don't want here (sorry if that's a silly issue).
Reproducible example:

library(ggplot2)
library(devtools)
devtools::install_github("davidgohel/rvg")
devtools::install_github("davidgohel/officer")
devtools::install_github("davidgohel/gdtools")
library(rvg)
library(gdtools)

plot_data <- data.frame (a = runif (1:20), b = seq (1:20))

x11 (width =  3, height = 3)

z <- ggplot(data = plot_data, mapping = aes (x = a, y = b)) +
  geom_point() +
  labs(x = "my x-label", y = "my y-label") +
  theme(panel.background = element_blank(),
        panel.border = element_rect (fill = NA, size = 0.5),
        axis.ticks = element_line (color = "black", lineend = "round", size=0.5),
        axis.ticks.length = unit (2, "mm"),
        axis.text = element_text (color = "black"),
        plot.margin = unit(rep (0, 4), "cm"),
        text = element_text (size=18,  
                             family="sans", 
                             color = "black")
  )
z

library(officer)
doc <- read_pptx()
doc <- add_slide(doc, "Title and Content", "Office Theme")
doc <- ph_with(doc, dml(ggobj = z, width = 3, height = 3), # I get the same output with extra argument fonts = list(sans = "TT Arial")), 
               location = ph_location_type(type = "body"))
fileout <- "test.pptx"
print(doc, target = fileout)

onscreen_result
test.pptx
PPT_result


sessionInfo()
# R version 3.5.3 (2019-03-11)
# Platform: x86_64-w64-mingw32/x64 (64-bit)
# Running under: Windows 10 x64 (build 18362)
# 
# Matrix products: default
# 
# locale:
#   [1] LC_COLLATE=English_United States.1252  LC_CTYPE=English_United States.1252    LC_MONETARY=English_United States.1252
# [4] LC_NUMERIC=C                           LC_TIME=English_United States.1252    
# 
# attached base packages:
#   [1] stats     graphics  grDevices utils     datasets  methods   base     
# 
# other attached packages:
#   [1] officer_0.3.6.015    gdtools_0.2.1        rvg_0.2.2.001        usethis_1.5.1        devtools_2.0.2       ggplot2_3.2.1       
# [7] RevoUtils_11.0.3     RevoUtilsMath_11.0.0
# 
# loaded via a namespace (and not attached):
#   [1] zip_2.0.4         Rcpp_1.0.2        pillar_1.4.2      compiler_3.5.3    base64enc_0.1-3   prettyunits_1.0.2 remotes_2.0.4    
# [8] tools_3.5.3       uuid_0.1-2        testthat_2.2.1    digest_0.6.20     pkgbuild_1.0.5    pkgload_1.0.2     memoise_1.1.0    
# [15] tibble_2.1.3      gtable_0.3.0      pkgconfig_2.0.2   rlang_0.4.0       cli_1.1.0         rstudioapi_0.10   curl_3.3         
# [22] xml2_1.2.2        withr_2.1.2       dplyr_0.8.3       systemfonts_0.1.1 fs_1.3.1          desc_1.2.0        rprojroot_1.3-2  
# [29] grid_3.5.3        tidyselect_0.2.5  glue_1.3.1        R6_2.4.0          processx_3.4.1    sessioninfo_1.1.1 purrr_0.3.2      
# [36] callr_3.3.1       magrittr_1.5      htmltools_0.3.6   scales_1.0.0      backports_1.1.4   ps_1.3.0          assertthat_0.2.1 
# [43] colorspace_1.4-1  labeling_0.3      lazyeval_0.2.2    munsell_0.5.0     crayon_1.3.4 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant