[R] Basic: setting resolution and size of an R graphic

Marc Schwartz MSchwartz at mn.rr.com
Tue Oct 25 14:59:08 CEST 2005


If you specifically need the plot to have a dimension measured in
pixels, then you need to use a bitmapped format such as png and specify
the output to be the size you require:

  png("test.png", width = 300, height = 300, ...)
  DoYourPlotHere()
  dev.off()

Do this directly using the png() device, rather than trying to convert
the image format, which almost always introduces "noise".

Since you are using a bitmapped format, you will experience the tradeoff
with respect to the image quality (ie. pixelated) as compared to a
vector based format such as PDF or PS.

I would re-verify the requirements for the journal to which you are
submitting the article relative to what they need for image specs. It
seems unusual for a journal to request an image in this fashion, unless
it is a photograph where a jpg format may be preferred or perhaps for
online publication on a web page.

HTH,

Marc Schwartz

On Tue, 2005-10-25 at 08:57 +0200, Dr. med. Peter Robinson wrote:
> Thanks Marc and Jim for the tips. The PDF file that I create with R looks
> about the same as the one you created. However, I need to get the graphic
> to be a certain size (300 pixels wide). I have been using the ImageMagick
> program to do so for other graphics:
> 
> convert test.pdf -resize 300x300 out.pdf
> 
> then out.pdf looks rather poor (pixelly). The original image is too big.
> ANy ideas?
> Thanks a lot,Peter
> 
> 
> Am Mo, 24.10.2005, 22:53, schrieb Marc Schwartz (via MN):
> > On Mon, 2005-10-24 at 22:32 +0200, Dr. med. Peter Robinson wrote:
> >
> >> Dear List,
> >>
> >>
> >> I am sorry if this perhaps a too basic question, but I have not found
> >> an answer in Google or in the R help system. I am trying to use R to do
> >> a very simple analysis of some data (RT-PCR and Western analysis) with a
> >>  T-test and
> >> to plot the results as a histogram with error bars. (I have pasted an
> >> example script at the bottom of this mail). In order to use this for
> >> publication, I would like to adjust the resolution and size of the final
> >> image. However, even using file types such as postscript or pdf that are
> >> vector based, I get rather bad-looking results with
> >>> pdf(file="test.pdf") source("script at bottom of mail") dev.off()
> >>
> >> using either pdf or postscript or jpg devices.
> >>
> >>
> >> Therefore I would like to ask the list, how to best produce a graphic
> >> from the script below that would fit into one column of a published
> >> article and have a high resolution (as eps, or failing that tiff or
> >> png)? Thanks in advance for any advice,
> >>
> >>
> >> Peter
> >>
> >
> > <Snip of code>
> >
> >
> > What OS are you on?
> >
> >
> > Running your example on FC4, I get the attached output for a pdf().
> >
> >
> > I suspect that on your OS, the height and width arguments are not
> > appropriate by default.
> >
> > Thus, you may need to adjust your pdf (or postscript) function call to
> > explicitly specify larger height and width arguments.
> >
> > Also note that to generate an EPS file, pay attention to the details
> > section of ?postscript, taking note of the 'onefile', 'horizontal' and
> > 'paper' arguments and settings.
> >
> >
> > Also, check with your journal to see if they specify dimensions for such
> > graphics so that you can abide by their specs if provided. If they are
> > using LaTeX, there are means of specifying and/or adjusting the height
> > and/or width specs in the code based upon proportions of various measures
> > (ie. \includegraphics[width=0.9\textwidth]{GraphicsFile.eps} ).
> >
> >
> > HTH,
> >
> >
> > Marc Schwartz
> >
> >
> >
>




More information about the R-help mailing list