An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20131215/1f531d3d/attachment.pl>
Exporting R graphics into Word without losing graph quality
14 messages · david hamer, Henrik Bengtsson, Duncan Murdoch +8 more
See ?png and argument 'pointsize'. You can increase that as you increase the dimensions of the output image. /Henrik
On Sun, Dec 15, 2013 at 3:00 PM, david hamer <j.david.hamer at gmail.com> wrote:
Hello,
My x-y scatterplot produces a very ragged best-fit line when imported into
Word.
* >plot (data.file$x, data.file$y, type = "p", las=1, pch=20, ylab =
expression("Cover of Species y" ~ (m^{2}~ha^{-1} )), xlab =
expression("Cover of Species x" ~ (m^{2}~ha^{-1})) ) >lines (
data.file$x, fitted ( model.x ) )*
A suggestion from the internet is to use .png at high (1200) resolution.
* >dev.print ( device = png, file = "R.graph.png", width = 1200,
height = 700)*
This gives a high?quality graph, but the titles and tick?mark labels become
very tiny when exported into Word.
I therefore increased the size of the titles and tick?mark labels with cex.
* >plot (......cex =1.8, cex.lab = 1.8, cex.axis = 1.25,....)*
But this causes the x?axis title to lie on top of the tick?mark labels.
(This problem does not occur with the y?axis, where the title lies well
away from the y?axis tick?mark labels.)
Changing margins * >par ( mai = c ( 1.3, 1.35, 1, .75 ) )* does not
seem to have any effect on this.
A suggestion from the internet is to delete the titles from plot, and use
mtext with line=4 to drop the title lower on the graph.
* >plot (....... ylab = " ", xlab = " ".....) >mtext(side = 1, "Cover
of Species x (superscripts??)", line = 4)*
This works, but with mtext I have now lost the ability to have the
superscripts in the axis title.
And I am back full circle, having to lower the resolution of the graph to
keep the x?axis title away from the axis, and thus reverting to a ragged,
segmented ?line? when exported to Word......
Final note: The R graphics window version of the graph becomes very
distorted, even though the graph may be of high quality (other than the
problem of the x-axis title overlaying the x-axis tick-mark labels) once in
Word. I guess this is because of using ?tricks? to try to get a desired
end-product in Word....
Thanks for any suggestions,
David.
[[alternative HTML version deleted]]
______________________________________________ R-help at r-project.org mailing list 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.
And possibly better, argument 'res', e.g.
png("R.graph.png", width=1200, height = 700, res=144)
plot(...)
dev.off()
Default corresponds to res=72.
/Henrik
On Sun, Dec 15, 2013 at 3:13 PM, Henrik Bengtsson <hb at biostat.ucsf.edu> wrote:
See ?png and argument 'pointsize'. You can increase that as you increase the dimensions of the output image. /Henrik On Sun, Dec 15, 2013 at 3:00 PM, david hamer <j.david.hamer at gmail.com> wrote:
Hello,
My x-y scatterplot produces a very ragged best-fit line when imported into
Word.
* >plot (data.file$x, data.file$y, type = "p", las=1, pch=20, ylab =
expression("Cover of Species y" ~ (m^{2}~ha^{-1} )), xlab =
expression("Cover of Species x" ~ (m^{2}~ha^{-1})) ) >lines (
data.file$x, fitted ( model.x ) )*
A suggestion from the internet is to use .png at high (1200) resolution.
* >dev.print ( device = png, file = "R.graph.png", width = 1200,
height = 700)*
This gives a high?quality graph, but the titles and tick?mark labels become
very tiny when exported into Word.
I therefore increased the size of the titles and tick?mark labels with cex.
* >plot (......cex =1.8, cex.lab = 1.8, cex.axis = 1.25,....)*
But this causes the x?axis title to lie on top of the tick?mark labels.
(This problem does not occur with the y?axis, where the title lies well
away from the y?axis tick?mark labels.)
Changing margins * >par ( mai = c ( 1.3, 1.35, 1, .75 ) )* does not
seem to have any effect on this.
A suggestion from the internet is to delete the titles from plot, and use
mtext with line=4 to drop the title lower on the graph.
* >plot (....... ylab = " ", xlab = " ".....) >mtext(side = 1, "Cover
of Species x (superscripts??)", line = 4)*
This works, but with mtext I have now lost the ability to have the
superscripts in the axis title.
And I am back full circle, having to lower the resolution of the graph to
keep the x?axis title away from the axis, and thus reverting to a ragged,
segmented ?line? when exported to Word......
Final note: The R graphics window version of the graph becomes very
distorted, even though the graph may be of high quality (other than the
problem of the x-axis title overlaying the x-axis tick-mark labels) once in
Word. I guess this is because of using ?tricks? to try to get a desired
end-product in Word....
Thanks for any suggestions,
David.
[[alternative HTML version deleted]]
______________________________________________ R-help at r-project.org mailing list 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.
On 13-12-15 6:00 PM, david hamer wrote:
Hello, My x-y scatterplot produces a very ragged best-fit line when imported into Word.
Don't use a bitmap format (png). Don't produce your graph in one format (screen display), then convert to another (png). Open the device in the format you want for the final file. Use a vector format for output. I don't know what kinds Word supports, but EPS or PDF would likely be best; if it can't read those, then Windows metafile (via windows() to open the device) would be best. (Don't trust the preview to tell you the quality of the graph, try printing the document. Word isn't quite as bad as it appears.) Don't use Word. Duncan Murdoch
* >plot (data.file$x, data.file$y, type = "p", las=1, pch=20, ylab =
expression("Cover of Species y" ~ (m^{2}~ha^{-1} )), xlab =
expression("Cover of Species x" ~ (m^{2}~ha^{-1})) ) >lines (
data.file$x, fitted ( model.x ) )*
A suggestion from the internet is to use .png at high (1200) resolution.
* >dev.print ( device = png, file = "R.graph.png", width = 1200,
height = 700)*
This gives a high?quality graph, but the titles and tick?mark labels become
very tiny when exported into Word.
I therefore increased the size of the titles and tick?mark labels with cex.
* >plot (......cex =1.8, cex.lab = 1.8, cex.axis = 1.25,....)*
But this causes the x?axis title to lie on top of the tick?mark labels.
(This problem does not occur with the y?axis, where the title lies well
away from the y?axis tick?mark labels.)
Changing margins * >par ( mai = c ( 1.3, 1.35, 1, .75 ) )* does not
seem to have any effect on this.
A suggestion from the internet is to delete the titles from plot, and use
mtext with line=4 to drop the title lower on the graph.
* >plot (....... ylab = " ", xlab = " ".....) >mtext(side = 1, "Cover
of Species x (superscripts??)", line = 4)*
This works, but with mtext I have now lost the ability to have the
superscripts in the axis title.
And I am back full circle, having to lower the resolution of the graph to
keep the x?axis title away from the axis, and thus reverting to a ragged,
segmented ?line? when exported to Word......
Final note: The R graphics window version of the graph becomes very
distorted, even though the graph may be of high quality (other than the
problem of the x-axis title overlaying the x-axis tick-mark labels) once in
Word. I guess this is because of using ?tricks? to try to get a desired
end-product in Word....
Thanks for any suggestions,
David.
[[alternative HTML version deleted]]
______________________________________________ R-help at r-project.org mailing list 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.
On 16/12/13 12:23, Duncan Murdoch wrote:
<SNIP>
[After a number of other "Don'ts"]
Don't trust the preview to tell you the quality of the graph, try printing the document. Word isn't quite as bad as it appears. Don't use Word.
Fortune?
cheers,
Rolf Turner
This will create a simple plot using Windows enhanced metafile format:
win.metafile("TestFigure.emf")
plot(rnorm(25), rnorm(25))
dev.off()
null device
1
Windows does not read pdf. It will offer to import an eps (encapsulated postscript) file, but it only imports the bitmap thumbnail image of the figure so it is completely useless. You can edit a metafile in Word, but different versions seem to have different issues. Earlier versions would lose clipping if you tried to edit the file, but World 2013 works reasonably well. Text labels can jump if you edit the figure in Word (especially rotated text) although it is simple to drag them back to where you want them. I haven't tried 2010 or 2007 recently. ------------------------------------- David L Carlson Department of Anthropology Texas A&M University College Station, TX 77840-4352 -----Original Message----- From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf Of Duncan Murdoch Sent: Sunday, December 15, 2013 5:24 PM To: david hamer; r-help at r-project.org Subject: Re: [R] Exporting R graphics into Word without losing graph quality
On 13-12-15 6:00 PM, david hamer wrote:
Hello, My x-y scatterplot produces a very ragged best-fit line when
imported into
Word.
Don't use a bitmap format (png). Don't produce your graph in one format (screen display), then convert to another (png). Open the device in the format you want for the final file. Use a vector format for output. I don't know what kinds Word supports, but EPS or PDF would likely be best; if it can't read those, then Windows metafile (via windows() to open the device) would be best. (Don't trust the preview to tell you the quality of the graph, try printing the document. Word isn't quite as bad as it appears.) Don't use Word. Duncan Murdoch
* >plot (data.file$x, data.file$y, type = "p", las=1, pch=20,
ylab =
expression("Cover of Species y" ~ (m^{2}~ha^{-1} )),
xlab =
expression("Cover of Species x" ~ (m^{2}~ha^{-1})) )
lines (
data.file$x, fitted ( model.x ) )*
A suggestion from the internet is to use .png at high (1200)
resolution.
* >dev.print ( device = png, file = "R.graph.png",
width = 1200,
height = 700)* This gives a high-quality graph, but the titles and tick-mark
labels become
very tiny when exported into Word. I therefore increased the size of the titles and tick-mark
labels with cex.
* >plot (......cex =1.8, cex.lab = 1.8, cex.axis =
1.25,....)*
But this causes the x-axis title to lie on top of the
tick-mark labels.
(This problem does not occur with the y-axis, where the title
lies well
away from the y-axis tick-mark labels.) Changing margins * >par ( mai = c ( 1.3, 1.35, 1, .75 ) )*
does not
seem to have any effect on this. A suggestion from the internet is to delete the titles from
plot, and use
mtext with line=4 to drop the title lower on the graph. * >plot (....... ylab = " ", xlab = " ".....) >mtext(side
= 1, "Cover
of Species x (superscripts??)", line = 4)* This works, but with mtext I have now lost the ability to have
the
superscripts in the axis title. And I am back full circle, having to lower the resolution of
the graph to
keep the x-axis title away from the axis, and thus reverting
to a ragged,
segmented "line" when exported to Word...... Final note: The R graphics window version of the graph
becomes very
distorted, even though the graph may be of high quality (other
than the
problem of the x-axis title overlaying the x-axis tick-mark
labels) once in
Word. I guess this is because of using "tricks" to try to get
a desired
end-product in Word....
Thanks for any suggestions,
David.
[[alternative HTML version deleted]]
______________________________________________ R-help at r-project.org mailing list 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.
______________________________________________ R-help at r-project.org mailing list 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.
On Dec 16, 2013, at 8:39 AM, David Carlson <dcarlson at tamu.edu> wrote:
This will create a simple plot using Windows enhanced metafile format:
win.metafile("TestFigure.emf")
plot(rnorm(25), rnorm(25))
dev.off()
null device
1
Windows does not read pdf.
This is correct for Office on Windows, not for Office on OSX. However, if you share the Office document created on OSX that has a PDF embedded with Windows Office users, they will see a bitmapped version of the graphic, rather than the PDF.
It will offer to import an eps (encapsulated postscript) file, but it only imports the bitmap thumbnail image of the figure so it is completely useless.
Regarding EPS imports, this is NOT correct. Word and the other Office apps will import the EPS file. It cannot render the postscript however, thus it will **display** a bitmapped preview image. If you print the Word document using a PS compatible printer driver, you will get the full high quality vector based graphic output. If you print to a non-PS compatible printer, the bitmapped preview is what will be printed. You may need to install EPS import filters for Office if they were not installed during the initial Office installation. That being said, while it has been years since I was on Windows, I used to use the WMF/EMF format to import or just copy/paste into Word, when I needed a document containing an R plot that could be shared with others. In most cases, the image quality was fine. Regards, Marc Schwartz
You can edit a metafile in Word, but different versions seem to have different issues. Earlier versions would lose clipping if you tried to edit the file, but World 2013 works reasonably well. Text labels can jump if you edit the figure in Word (especially rotated text) although it is simple to drag them back to where you want them. I haven't tried 2010 or 2007 recently. ------------------------------------- David L Carlson Department of Anthropology Texas A&M University College Station, TX 77840-4352 -----Original Message----- From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf Of Duncan Murdoch Sent: Sunday, December 15, 2013 5:24 PM To: david hamer; r-help at r-project.org Subject: Re: [R] Exporting R graphics into Word without losing graph quality On 13-12-15 6:00 PM, david hamer wrote:
Hello, My x-y scatterplot produces a very ragged best-fit line when
imported into
Word.
Don't use a bitmap format (png). Don't produce your graph in one format (screen display), then convert to another (png). Open the device in the format you want for the final file. Use a vector format for output. I don't know what kinds Word supports, but EPS or PDF would likely be best; if it can't read those, then Windows metafile (via windows() to open the device) would be best. (Don't trust the preview to tell you the quality of the graph, try printing the document. Word isn't quite as bad as it appears.) Don't use Word. Duncan Murdoch
* >plot (data.file$x, data.file$y, type = "p", las=1, pch=20,
ylab =
expression("Cover of Species y" ~ (m^{2}~ha^{-1} )),
xlab =
expression("Cover of Species x" ~ (m^{2}~ha^{-1})) )
lines (
data.file$x, fitted ( model.x ) )*
A suggestion from the internet is to use .png at high (1200)
resolution.
* >dev.print ( device = png, file = "R.graph.png",
width = 1200,
height = 700)* This gives a high-quality graph, but the titles and tick-mark
labels become
very tiny when exported into Word. I therefore increased the size of the titles and tick-mark
labels with cex.
* >plot (......cex =1.8, cex.lab = 1.8, cex.axis =
1.25,....)*
But this causes the x-axis title to lie on top of the
tick-mark labels.
(This problem does not occur with the y-axis, where the title
lies well
away from the y-axis tick-mark labels.) Changing margins * >par ( mai = c ( 1.3, 1.35, 1, .75 ) )*
does not
seem to have any effect on this. A suggestion from the internet is to delete the titles from
plot, and use
mtext with line=4 to drop the title lower on the graph. * >plot (....... ylab = " ", xlab = " ".....) >mtext(side
= 1, "Cover
of Species x (superscripts??)", line = 4)* This works, but with mtext I have now lost the ability to have
the
superscripts in the axis title. And I am back full circle, having to lower the resolution of
the graph to
keep the x-axis title away from the axis, and thus reverting
to a ragged,
segmented "line" when exported to Word...... Final note: The R graphics window version of the graph
becomes very
distorted, even though the graph may be of high quality (other
than the
problem of the x-axis title overlaying the x-axis tick-mark
labels) once in
Word. I guess this is because of using "tricks" to try to get
a desired
end-product in Word....
Thanks for any suggestions,
David.
Unfortunately the win.metafile() device does not support semi-transparent colours, which I like using.
In my experience, the best way to get R graphics into Word is to use compressed high-resolution tiff, like this:
word.tif = function(filename="Word_Figure_%03d.tif", zoom=4, width=17, height=10, pointsize=10, ...) {
if (!grepl("[.]ti[f]+$", filename, ignore.case=TRUE))
filename = paste0(filename,".tif")
tiff(filename=filename, compression="lzw", res=96*zoom,
width=width, height=height, units='cm', pointsize=pointsize, ...)
}
word.tif('test')
plot(rnorm(100))
dev.off()
Now drag the file test.tif into your Word document.
Sure, it's a bitmap format rather than a vector format, but the quality is excellent and the file sizes are still quite small. None of the vector formats works as well as this.
cheers,
Steve
From: Duncan Murdoch...
Don't use a bitmap format (png).
I disagree. Each vector format comes with its own problems.
Don't produce your graph in one format (screen display), then convert to another (png). Open the device in the format you want for the final file.
Agreed.
Use a vector format for output.
Why? Sure, that's good advice in the ideal (pdflatex) world, but not necessarily the best of advice for Word users.
I don't know what kinds Word supports, but EPS or PDF would likely be best; if it can't read those, then Windows metafile (via windows() to open the device) would be best.
None of these works well, if at all, in my experience with Word.
Don't use Word.
Some of us don't really have a choice.
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20131216/b1c9e6ad/attachment.pl>
1 day later
Another option to consider if your goal is to create a word file with 1 or more plots in it (possibly intermingled with text and other output) is to use the knitr or pander packages (or odfWeave or sweave or ...). This way you can create a script (or template file) that sets a couple of options up front (width, height, resolution, file type) and creates the graphs (and possibly other output to be included), run the script (and maybe the external program pandoc) and you have a word document with the plots without needing to copy/paste or import. This becomes a real time saver when the client comes back to you and says there was a typo in the data, the 13 on line 27 needs to be an 18 and can you rerun everything with that change? (if something along those lines has not happened to you yet, it will).
On Mon, Dec 16, 2013 at 9:33 PM, david hamer <j.david.hamer at gmail.com> wrote:
Thanks to everyone for the helpful suggestions. -- David. On Mon, Dec 16, 2013 at 7:23 PM, Steve Taylor <steve.taylor at aut.ac.nz>wrote:
From: Duncan Murdoch...
Don't use a bitmap format (png).
I disagree. Each vector format comes with its own problems.
Don't produce your graph in one format (screen display), then convert to another (png). Open the device in the format you want for the final
file. Agreed.
Use a vector format for output.
Why? Sure, that's good advice in the ideal (pdflatex) world, but not necessarily the best of advice for Word users.
I don't know what kinds Word supports, but EPS or PDF would likely be best; if it can't read those, then Windows
metafile
(via windows() to open the device) would be best.
None of these works well, if at all, in my experience with Word.
Don't use Word.
Some of us don't really have a choice.
[[alternative HTML version deleted]]
______________________________________________ R-help at r-project.org mailing list 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.
Gregory (Greg) L. Snow Ph.D. 538280 at gmail.com
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20131218/34e18822/attachment.pl>
2 days later
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20131221/1ce81b4b/attachment.pl>
1 day later
Waterloo Graphics is open-source and can be used from R. Graphics can be copied and pasted in vector format to Word on Windows or Mac. There is also an SVG file save option that produces output with easy-to-use object groupings for editing an Adobe Illustrator/Inkscape. (as well as HTML5/Processing support) http://waterloo.sourceforge.net