Skip to content
Prev 165 / 7420 Next

Publication quality graphics in R

You can exert quite a lot of control over the appearance of JPG output. 
Try inserting "lowres.jpg" and "hires.jpg" (generated by the code below) 
into a Word document and comparing the results.

foo <- function(){
plot.new()
plot.window(c(0,1),c(0,1))
plot(sin(seq(0,2*pi,0.01)),type="l",col="blue",lwd=2)
title("Example")}

jpeg("lowres.jpg",width=480,height=480)
foo()
dev.off()

jpeg("hires.jpg",width=4*480,height=4*480,pointsize=48)
foo()
dev.off()

*************************************************
Glen A. Sargeant, Ph.D.
Research Wildlife Biologist/Statistician
Northern Prairie Wildlife Research Center
8711 37th Street SE
Jamestown, ND  58401

Phone: (701) 253-5528
E-mail:  glen_sargeant at usgs.gov
FAX:     (701) 253-5553
*************************************************



David Hewitt <dhewitt37 at gmail.com> 
Sent by: r-sig-ecology-bounces at r-project.org
05/30/2008 04:06 PM

To
r-sig-ecology at r-project.org
cc

Subject
Re: [R-sig-eco] Publication quality graphics in R
presentation
Powerpoint),
I'd strongly recommend making the figures by writing them to files rather
than copying and pasting from the graphics device window. So, for example,
when you want a figure as a pdf you'd use "pdf(filename, options)" to open
the device with the output settings you desire, then do all your plotting
commands, then close the device with dev.off().

type ?pdf at the prompt; other devices are described in ?png

You can run the plots in the device window and then save as..., but you'll
get subtle (and sometimes not-so-subtle) differences between the window
display and the output through a device command. Once you get what you 
like,
then fine-tune the device options to produce the final file to be imported
to your text.

The format you use will vary depending on what you're putting it into. 
I've
had the most luck with PDF images rolled into LaTeX PDFs (via LyX --
www.lyx.org), although I've heard that EPS is even better for some things.
JPGs never worked well for me in anything. I gave up on M$ Office a few
years ago. Not much looks good in there.


-----
David Hewitt
Research Fishery Biologist
USGS Klamath Falls Field Station (USA)