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

Fonts get corrupted after exporting ggplot from R to powerpoint #38

Open
Dieuwbieus opened this issue Oct 1, 2020 · 4 comments
Open

Comments

@Dieuwbieus
Copy link

Dieuwbieus commented Oct 1, 2020

When I am exporting my ggplots from R to powerpoint, my fonts get corrupted in powerpoint (fonts are filled). Herewith the code that gives the error in powerpoint and a picture of how the ggplot looks in powerpoint.

Schermafbeelding 2020-10-01 om 16 41 50

Session info

R version 3.6.3 (2020-02-29)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: macOS Sierra 10.12.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] nl_NL.UTF-8/nl_NL.UTF-8/nl_NL.UTF-8/C/nl_NL.UTF-8/nl_NL.UTF-8

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

other attached packages:
 [1] systemfonts_0.1.1 magrittr_1.5      devEMF_3.7        gdtools_0.2.1     packcircles_0.3.3 stringr_1.4.0     rvg_0.2.4        
 [8] officer_0.3.13    showtext_0.8      showtextdb_2.0    sysfonts_0.8      ggchicklet_0.5.0  extrafont_0.17    forcats_0.5.0    
[15] data.table_1.12.8 tidyr_1.0.2       ggplot2_3.3.0     readr_1.3.1       dplyr_0.8.5      

loaded via a namespace (and not attached):
 [1] zip_2.1.1        Rcpp_1.0.4       pillar_1.4.3     compiler_3.6.3   tools_3.6.3      digest_0.6.25    uuid_0.1-4      
 [8] lifecycle_0.2.0  tibble_2.1.3     gtable_0.3.0     pkgconfig_2.0.3  rlang_0.4.5      cli_2.0.2        rstudioapi_0.11 
[15] Rttf2pt1_1.3.8   xml2_1.2.5       withr_2.1.2      vctrs_0.2.4      hms_0.5.3        grid_3.6.3       tidyselect_1.0.0
[22] glue_1.3.2       R6_2.4.1         fansi_0.4.1      farver_2.0.3     purrr_0.3.3      extrafontdb_1.0  scales_1.1.0    
[29] assertthat_0.2.1 colorspace_1.4-1 labeling_0.3     utf8_1.1.4       stringi_1.4.6    munsell_0.5.0    crayon_1.3.4 

Example

library(officer)
library(ggplot2)
library(rvg)

gg <- ggplot(mtcars, aes(x = mpg , y = wt, colour = qsec)) + geom_point() + theme_minimal()

read_pptx() %>%
  add_slide(layout = "Title and Content", master = "Office Theme") %>%
  ph_with(dml(ggobj = gg), location = ph_location_type(type = "body")) %>%
  print(target = "test.pptx")
@davidgohel
Copy link
Owner

Thanks,

Do you have the font installed on your mac? For me the used font is "Helvetica", what is yours?

Could you try to change the font with something you are sure you have on your computer:

https://davidgohel.github.io/rvg/articles/offcran/customizing.html#fonts-1

@Dieuwbieus
Copy link
Author

Thank you for you comment :)

It is still not working. I have the font "Roboto" installed on my mac and used this font in my code. I still get the same output in powerpoint with corrupted texts.

gdtools::font_family_exists("Roboto")
[1] TRUE

New Code as used by the example in your link

library(officer)
library(ggplot2)
library(rvg)

gg <- ggplot(mtcars, aes(x = mpg , y = wt, colour = qsec)) + geom_point() + theme_minimal()

graph_editable <- dml(ggobj = gg, fonts = list(sans = "Roboto"))

doc <- read_pptx()
doc <- add_slide(doc)
doc <- ph_with(x = doc, graph_editable,
location = ph_location_type(type = "body") )
print(doc, target = "rvg.pptx")

@davidgohel
Copy link
Owner

thanks

I don't know what is happening for now... What client are you using? PowerPoint for mac?

@Dieuwbieus
Copy link
Author

Yes PowerPoint for mac version 16.30. Before I had an older version and it also did not work with that version.

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

2 participants