ISO recommendations for plot output format from R to MS Word

classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|

ISO recommendations for plot output format from R to MS Word

Robert Dodier
I need to export plots (constructed with plot and with ggplot) from R
to be imported into a MS Word document.

I am working with MS Word for Mac version 16.16.10 (copyright 2018)
and R versions 3.6.3 and/or 4.0.3.

I have verified that the version of MS Word which I am working with
can import SVG exported from R via svglite.

What I am mostly worried about is that other people with possibly
different versions of MS Word will not be able to view the document
correctly.

Towards the goal of creating an MS Word document which others with
unspecified versions of MS Word can view correctly, in what format
should I export figures from R?

I am working with a fairly large number of figures so there is some
motivation towards a fully automated process.

I have searched various forums and archives, but much of the
information may be out of date, so I am hoping that you can help me
with some up to date information.

Thank you very much for any light you can shed on this problem.

Robert Dodier

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: ISO recommendations for plot output format from R to MS Word

Jinsong Zhao-2
On 2021/2/13 7:05, Robert Dodier wrote:

> I need to export plots (constructed with plot and with ggplot) from R
> to be imported into a MS Word document.
>
> I am working with MS Word for Mac version 16.16.10 (copyright 2018)
> and R versions 3.6.3 and/or 4.0.3.
>
> I have verified that the version of MS Word which I am working with
> can import SVG exported from R via svglite.
>
> What I am mostly worried about is that other people with possibly
> different versions of MS Word will not be able to view the document
> correctly.
>

On Windows, MS Word can not display the SVG imported. In my memory, the
only fully supported vector graphic format is "emf" or "wmf" (both a
same?). Encapsulated PostScript(EPS) seems to be supported with specific
plugin (I am not very sure about it).

However, some figures produced by win.metafile() could display correctly
in Word, but weird when convert to PDF.

> Towards the goal of creating an MS Word document which others with
> unspecified versions of MS Word can view correctly, in what format
> should I export figures from R?
>
> I am working with a fairly large number of figures so there is some
> motivation towards a fully automated process.
>
> I have searched various forums and archives, but much of the
> information may be out of date, so I am hoping that you can help me
> with some up to date information.
>
> Thank you very much for any light you can shed on this problem.
>
> Robert Dodier
>

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: ISO recommendations for plot output format from R to MS Word

Ivan Krylov
In reply to this post by Robert Dodier
On Fri, 12 Feb 2021 15:05:33 -0800
Robert Dodier <[hidden email]> wrote:

> Towards the goal of creating an MS Word document which others with
> unspecified versions of MS Word can view correctly, in what format
> should I export figures from R?

A cross-platform plotting device designed specifically for word
processors is devEMF. In my experience, best compatibility with Word
can be achieved by creating figures with parameters (emfPlus = TRUE,
emfPlusFont = FALSE, emfPlusRaster = TRUE), but I only checked Word
2003 and 2010 (for Windows).

--
Best regards,
Ivan

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: ISO recommendations for plot output format from R to MS Word

Robert Dodier
In reply to this post by Robert Dodier
Hi, a quick follow-up about the question about putting R-generated
figures into MS Word.

I have found by experimenting with some figures and documents that if
I import an SVG figure generated by svglite (didn't try other output
functions), I can view it okay in my installation of MS Word (Word for
Mac 16.16.10), and it looks okay in MS Word for Windows (circa 2016 or
2018) on a laptop I have, and two other people can view it okay (one
on Mac and one on Windows). So that seems safe enough to go ahead.
YMMV.

I am informed that MS Word is actually storing a bitmap image of the
SVG figure, which is displayed by non-SVG-aware versions of Word. So
that seems like a good safeguard.

For the record, I converted the SVG to EPS, PNG, PDF, WMF, and EMF via
Imagemagick. EPS and PNG were tolerable, PDF was too fuzzy, and WMF
and EMF, at least as generated, could not be displayed (I was a little
surprised by that). There are, no doubt, many unanswered questions
here, which unfortunately I cannot take the time to explore right now.

In summary I found that importing SVG generated by svglite into MS
Word for Mac seems to work okay to generate a generally-readable file.
Perhaps this experience is useful in some way to others.

best,

Robert Dodier

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: ISO recommendations for plot output format from R to MS Word

Kevin Thorpe
I did not see the original thread so this may have been discussed.

I would think that it would be more seamless to use Rmarkdown.
Simply put the plotting code into an Rmarkdown file and send it
straight to Word. Is there a reason why this is not a viable option?

--
Kevin E. Thorpe
Head of Biostatistics,  Applied Health Research Centre (AHRC)
Li Ka Shing Knowledge Institute of St. Michael's
Assistant Professor, Dalla Lana School of Public Health
University of Toronto
email: [hidden email]  Tel: 416.864.5776  Fax: 416.864.3016

> On Feb 18, 2021, at 12:50 PM, Robert Dodier <[hidden email]> wrote:
>
> EXTERNAL EMAIL:
>
> Hi, a quick follow-up about the question about putting R-generated
> figures into MS Word.
>
> I have found by experimenting with some figures and documents that if
> I import an SVG figure generated by svglite (didn't try other output
> functions), I can view it okay in my installation of MS Word (Word for
> Mac 16.16.10), and it looks okay in MS Word for Windows (circa 2016 or
> 2018) on a laptop I have, and two other people can view it okay (one
> on Mac and one on Windows). So that seems safe enough to go ahead.
> YMMV.
>
> I am informed that MS Word is actually storing a bitmap image of the
> SVG figure, which is displayed by non-SVG-aware versions of Word. So
> that seems like a good safeguard.
>
> For the record, I converted the SVG to EPS, PNG, PDF, WMF, and EMF via
> Imagemagick. EPS and PNG were tolerable, PDF was too fuzzy, and WMF
> and EMF, at least as generated, could not be displayed (I was a little
> surprised by that). There are, no doubt, many unanswered questions
> here, which unfortunately I cannot take the time to explore right now.
>
> In summary I found that importing SVG generated by svglite into MS
> Word for Mac seems to work okay to generate a generally-readable file.
> Perhaps this experience is useful in some way to others.
>
> best,
>
> Robert Dodier
>
> ______________________________________________
> [hidden email] mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: ISO recommendations for plot output format from R to MS Word

Robert Dodier
On Thu, Feb 18, 2021 at 10:12 AM Kevin Thorpe <[hidden email]> wrote:

> I would think that it would be more seamless to use Rmarkdown.
> Simply put the plotting code into an Rmarkdown file and send it
> straight to Word. Is there a reason why this is not a viable option?

Hi Kevin, thanks for your reply. Well, I started working with Word
because at least one other person needs to edit it and they want to
use Word. More fundamentally, it's not clear to me that going through
Rmarkdown solves the problem of determining the image format -- at
some point a figure is going to get generated and then pasted into a
Word document. It's not clear that doing that automatically is going
to work better or differently than doing it by hand. Anyway I think I
have a working solution at this point so I leave it to others to
investigate further possibilities.

best,

Robert Dodier

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: ISO recommendations for plot output format from R to MS Word

Kevin Thorpe

> On Feb 18, 2021, at 2:03 PM, Robert Dodier <[hidden email]> wrote:
>
> EXTERNAL EMAIL:
>
> On Thu, Feb 18, 2021 at 10:12 AM Kevin Thorpe <[hidden email]> wrote:
>
>> I would think that it would be more seamless to use Rmarkdown.
>> Simply put the plotting code into an Rmarkdown file and send it
>> straight to Word. Is there a reason why this is not a viable option?
>
> Hi Kevin, thanks for your reply. Well, I started working with Word
> because at least one other person needs to edit it and they want to
> use Word. More fundamentally, it's not clear to me that going through
> Rmarkdown solves the problem of determining the image format -- at
> some point a figure is going to get generated and then pasted into a
> Word document. It's not clear that doing that automatically is going
> to work better or differently than doing it by hand. Anyway I think I
> have a working solution at this point so I leave it to others to
> investigate further possibilities.
>
> best,
>
> Robert Dodier

Fair enough. I mentioned it since from my limited experience sending to Word
(I hate Word) the images seem to look fine. Whatever is done seems to work.
With the Rmarkdown generated Word file, I imagine copy/paste into the “master”
Document would work just fine.

Kevin


--
Kevin E. Thorpe
Head of Biostatistics,  Applied Health Research Centre (AHRC)
Li Ka Shing Knowledge Institute of St. Michael's
Assistant Professor, Dalla Lana School of Public Health
University of Toronto
email: [hidden email]  Tel: 416.864.5776  Fax: 416.864.3016

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: ISO recommendations for plot output format from R to MS Word / tangential

J C Nash
FWIW, even in Rmarkdown images sometimes give trouble. However, there is the possibilty
of asking to keep the latex version of the document after Rmarkdown has been processed.
That is, in the yaml header there is the "output" section

output:
  pdf_document:
    keep_tex: false
    toc: true

Here I have kept_tex NOT active. Change false to true and a .tex file will be produced.
I've found this useful to adjust images and a few other things. Mostly I am happy with
Rmarkdown output, and I have to say such tweaks are quite rare, though I have once or
twice used this feature to track down some non-printing characters in code chunks when
the Rmarkdown processing was fine, but pdflatex choked.

Possibly it is easier to do Latex --> Word. Like many others in the R community, I find
Word an unfortunate annoyance, in particular because I can never be sure really what
is present in a "doc"ument.

Best, J Nash


On 2021-02-18 2:16 p.m., Kevin Thorpe wrote:

>
>> On Feb 18, 2021, at 2:03 PM, Robert Dodier <[hidden email]> wrote:
>>
>> EXTERNAL EMAIL:
>>
>> On Thu, Feb 18, 2021 at 10:12 AM Kevin Thorpe <[hidden email]> wrote:
>>
>>> I would think that it would be more seamless to use Rmarkdown.
>>> Simply put the plotting code into an Rmarkdown file and send it
>>> straight to Word. Is there a reason why this is not a viable option?
>>
>> Hi Kevin, thanks for your reply. Well, I started working with Word
>> because at least one other person needs to edit it and they want to
>> use Word. More fundamentally, it's not clear to me that going through
>> Rmarkdown solves the problem of determining the image format -- at
>> some point a figure is going to get generated and then pasted into a
>> Word document. It's not clear that doing that automatically is going
>> to work better or differently than doing it by hand. Anyway I think I
>> have a working solution at this point so I leave it to others to
>> investigate further possibilities.
>>
>> best,
>>
>> Robert Dodier
>
> Fair enough. I mentioned it since from my limited experience sending to Word
> (I hate Word) the images seem to look fine. Whatever is done seems to work.
> With the Rmarkdown generated Word file, I imagine copy/paste into the “master”
> Document would work just fine.
>
> Kevin
>
>

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: ISO recommendations for plot output format from R to MS Word

Donald Macnaughton
In reply to this post by Robert Dodier
The native graphics format in Microsoft Office (including Word) is EMF
(Enhanced MetaFile), which is an enhanced version of WMF (Windows MetaFile).
This is a VECTOR format with embedded scalable fonts, so it scales perfectly
to all sizes. R will output EMF graph files using Philip Johnson's
library(devEMF), which is on CRAN. These files can be imported into Word
using Insert > Pictures > ....

These images are "perfect" if the Word document is converted (by Word
itself) to PDF, with unbitmapped fonts and lines, so they look perfect even
if you zoom the PDF to 600%.

I haven't tried lately, but in the past the driver generated huge files from
ggplot2, but small files from the graphics and grid packages.

Don Macnaughton


-----Original Message-----
From: R-help <[hidden email]> On Behalf Of Robert Dodier
Sent: Thursday, February 18, 2021 12:50 PM
To: [hidden email]
Subject: Re: [R] ISO recommendations for plot output format from R to MS
Word

Hi, a quick follow-up about the question about putting R-generated figures
into MS Word.

I have found by experimenting with some figures and documents that if I
import an SVG figure generated by svglite (didn't try other output
functions), I can view it okay in my installation of MS Word (Word for Mac
16.16.10), and it looks okay in MS Word for Windows (circa 2016 or
2018) on a laptop I have, and two other people can view it okay (one on Mac
and one on Windows). So that seems safe enough to go ahead.
YMMV.

I am informed that MS Word is actually storing a bitmap image of the SVG
figure, which is displayed by non-SVG-aware versions of Word. So that seems
like a good safeguard.

For the record, I converted the SVG to EPS, PNG, PDF, WMF, and EMF via
Imagemagick. EPS and PNG were tolerable, PDF was too fuzzy, and WMF and EMF,
at least as generated, could not be displayed (I was a little surprised by
that). There are, no doubt, many unanswered questions here, which
unfortunately I cannot take the time to explore right now.

In summary I found that importing SVG generated by svglite into MS Word for
Mac seems to work okay to generate a generally-readable file.
Perhaps this experience is useful in some way to others.

best,

Robert Dodier

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.