Open SchmidtPaul opened 2 years ago
Hello @SchmidtPaul,
Sorry for the very late answer. Hopefully this hasn't blocked you from generating your reports....
Here are my thoughts on your questions:
showtext
is not available from PPT (and hence it takes some default font)? When you look select the text in your PPT, does it mention the expected font style?export::graph2doc()
? By default vector.graphic = TRUE
meaning that vector graphics are used to draw the image and show yield crisp images in your docx. If you want to avoid copy pasting from one file to another, there is also the argument append = TRUE
that will put your figure and the end of the target document. height
and width
arguments in graph2pdf
, graph2ppt
and graph2png
(or even in ggsave
). Hi, thanks for the answer!
First of all, I realized that the (3.) was actually more of a {showtext} issue and was addressed in yixuan/showtext#51. Here is a reprex that works fine for all p1
but has considerable dimension changes for p2
:
library(export)
library(ggplot2)
p <- ggplot(data = PlantGrowth,
aes(y = weight, x = group)) +
geom_point() +
labs(subtitle = "Here is also a subtitle",
caption = "And here is a caption")
p1 <- p + ggtitle("Without showtext::showtext_auto()")
ggsave("p1.pdf", p1)
#> Saving 7 x 5 in image
ggsave("p1.png", p1)
#> Saving 7 x 5 in image
graph2doc(p1, "p1.docx", vector.graphic = TRUE)
#> Exported graph as p1.docx
graph2ppt(p1, "p1.pptx", vector.graphic = TRUE)
#> Exported graph as p1.pptx
showtext::showtext_auto()
p2 <- p + ggtitle("With showtext::showtext_auto()")
ggsave("p2.pdf", p2)
#> Saving 7 x 5 in image
ggsave("p2.png", p2)
#> Saving 7 x 5 in image
graph2doc(p2, "p2.docx", vector.graphic = TRUE)
#> Exported graph as p2.docx
graph2ppt(p2, "p2.pptx", vector.graphic = TRUE)
#> Exported graph as p2.pptx
Created on 2022-07-29 by the reprex package (v2.0.1)
For comparison, here are screenshots of all exported p2
:
Again, the font size/dimension thing can be ignored for now since all p1
do look identical. Yet, as you can see the problem remains for the pptx
and I wouldn't assume that PowerPoint does not have this font, as I simply left it with the default (=Arial?). However, I will take your advice and switch to export::graph2doc(vector.graphic = TRUE, append = TRUE)
now.
Hmm indeed this is not expected. When I run your example p1
and p2
lead to the same results for all 4 formats on my side. I must say I don't have MicrosofOffice, but use LibreOffice instead, and am using an Ubuntu OS. Maybe the issue lies within PPT (cf also issue #49 ) ?
However, I cannot explain why the PDF resolution is different... Does it lead to the same with graph2pdf()
? It is relying on cairo()
whereas ggsave()
relies on grDevices::pdf
, although I don't know if the two are related...
I have the same problems, but now they happen even when I don't use "showtext". I get all the cut-out sections of the font filled with black.
Can you give a reproducible example perhaps?
It's the same as the original post in this thread: https://github.com/tomwenseleers/export/issues/45#issue-1108264533.
I realize now that if I started a new R session that had never run or called showtext
, there wouldn't be a font issue. So I guess I was wrong about that part.
But I was having the exact same issues mentioned here, the same as the second reprex too. I managed to fix this issue by using extrafont
instead, but otherwise it was the same for me.
R version 4.3.0 (2023-04-21 ucrt)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19044)
Hi, thanks for the package - been using it for a while now. I recently started using {showtext} to make use of extra fonts in my ggplots. However, I noticed that after running the required
showtext::showtext_auto()
, the exported.pptx
have issues with their text - see the screenshot below.Created on 2022-01-19 by the reprex package (v2.0.1)
This is a Screenshot of![image](https://user-images.githubusercontent.com/31928213/150163082-7a150a24-9630-440e-8f89-ad0e195157b0.png)
Rplot.pptx
:Ultimately, I have these questions:
graph2ppt()
?pptx
in the first place is to get the figures in mydocx
files to be as crisp-looking as possible. I achieve this via copying the graph from thepptx
file and pasting it into word as an enhanced metafile. Does this sound reasonable to you or do you have a better suggestion?pdf
,png
andpptx
. The first two I could do viaggsave()
, but I actually only do so for pdf and subsequently runpdftools::pdf_render_page(pdf_path, page = 1, dpi = 300) %>% png::writePNG(bitmap, png_path)
(see my custom export function). This seems to do the trick of always having the same font sizes and scales for both of these two exported files. Does this sound reasonable to you? Should I try to take a similar approach here with e.g.pdf2pptx::pdf2pptx()
?