david hamer
2013-Dec-15 23:00 UTC
[R] Exporting R graphics into Word without losing graph quality
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]]
Henrik Bengtsson
2013-Dec-15 23:13 UTC
[R] Exporting R graphics into Word without losing graph quality
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. >
Duncan Murdoch
2013-Dec-15 23:23 UTC
[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. >
Shane McMahon
2013-Dec-21 19:29 UTC
[R] Exporting R graphics into Word without losing graph quality
Sorry I'm a little late to the party on this one, but I thought I'd throw in my solution. I usually produce my plots with the svg device. Ex: plot(1:100,(1:100)^2) svg(filename="example.svg",height=3.83,width=3.83,pointsize=10) plot(1:100,(1:100)^2,xlab="x",ylab=expression("x"^2)) dev.off() Word doesn't play well with .svg files but the free, open source software inkscape works well. I use inkscape to put together figures and I usually add axis labels in inkscape as well. Save your figure from inkscape as an enhanced metafile (*.emf) and import them into word. This procedure works well with word 2007, I can't speak directly about other versions. cheers, Shane On 12/15/2013 3:00 PM, david hamer 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@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.[[alternative HTML version deleted]]