# Included png appears too big in PDF

I'm a beginner with LaTex and writing an article in it (letter-sized). WinEDT and MikTeX (versions seen in the log).

I have a PNG chart (obtained from R/ggplot2) which is 471 x 335 pixels and which I'm including as below.

The problem: in the PDF the image is scaled up to occupy the width of the page and thus becomes blurry. I see the warnings in the log, but am not sure what I need to do given it's a picture, not text.

\documentclass[12pt]{article}
\usepackage[letterpaper]{geometry}
\geometry{top=1.0in, bottom=1.0in, left=1.5in, right=1.0in}
\usepackage{graphicx}
\begin{figure}
\includegraphics{chart}\\                            % line 35
\caption{Adjusted Relative Risk (RR)}\label{mylabel} % line 36
\end{figure}


The output log shows:

Command Line:   texify.exe --pdf --tex-option=--synctex=-1 "C:\Documents and Settings\myself\Application Data\WinEdt Team\WinEdt 6\RW\test1.tex"
Startup Folder: C:\Documents and Settings\myself\Application Data\WinEdt Team\WinEdt 6\RW

This is pdfTeX, Version 3.1415926-1.40.10 (MiKTeX 2.8)
entering extended mode

("C:/Documents and Settings/myself/Application Data/WinEdt Team/WinEdt 6/RW/test1.tex"
LaTeX2e
Babel  and hyphenation patterns for english, dumylang, nohyphenation, ge
rman, ngerman, german-x-2009-06-19, ngerman-x-2009-06-19, french, loaded.
(C:\MiKTeX\tex\latex\base\article.cls
Document Class: article 2007/10/19 v1.4h Standard LaTeX document class
(C:\MiKTeX\tex\latex\base\size12.clo)) (C:\MiKTeX\tex\generic\babel\babel.sty
*************************************
* Local config file bblopts.cfg used
*
(C:\MiKTeX\tex\latex\00miktex\bblopts.cfg)
(C:\MiKTeX\tex\generic\babel\english.ldf (C:\MiKTeX\tex\generic\babel\babel.def
))) (C:\MiKTeX\tex\latex\graphics\graphicx.sty
(C:\MiKTeX\tex\latex\graphics\keyval.sty)
(C:\MiKTeX\tex\latex\graphics\graphics.sty
(C:\MiKTeX\tex\latex\graphics\trig.sty)
(C:\MiKTeX\tex\latex\00miktex\graphics.cfg)
(C:\MiKTeX\tex\latex\pdftex-def\pdftex.def)))
(C:\MiKTeX\tex\latex\geometry\geometry.sty
(C:\MiKTeX\tex\generic\oberdiek\ifpdf.sty)
(C:\MiKTeX\tex\generic\oberdiek\ifvtex.sty)
(C:\MiKTeX\tex\latex\geometry\geometry.cfg))
(C:\MiKTeX\tex\latex\base\flafter.sty)
(C:\MiKTeX\tex\latex\setspace\setspace.sty
Package: setspace' 6.7
)
("C:\Documents and Settings\myself\Application Data\WinEdt Team\WinEdt 6\RW\t
est1.aux") (C:\MiKTeX\tex\context\base\supp-pdf.tex
)
*geometry* driver: auto-detecting
*geometry* detected driver: pdftex
[1{C:/MiKTeX/pdftex/config/pdftex.map}] [2]

Overfull \hbox (39.14508pt too wide) in paragraph at lines 35--36
[][]

Underfull \hbox (badness 10000) in paragraph at lines 35--36

[3] [4 ] [5]
("C:\Documents and Settings\myself\Application Data\WinEdt Team\WinEdt 6\RW\t
est1.aux") )
(see the transcript file for additional information)
Output written on test1.pdf (5 pages, 100528 bytes).
SyncTeX written on test1.synctex
Transcript written on test1.log.
-

This is not exactly an answer to the question you asked, but do you know that R/ggplot2 can write out your charts as pdf files that can be \includegraphicsed? Just use pdf() instead of png() when setting up the output device, or if you're using ggsave(), give the file a .pdf extension instead of png. Then you get real text and vector graphics, which pdfTeX can scale without blurriness. Note: the width and height arguments to pdf() are in inches, not pixels. Also, you may have to delete the .png file to get pdfTeX to pick up the PDF.

-
Zack's advice is sound. Generating a pixel-based image that is intended for printing is just asking for trouble. Even if you get it looking fine on your printer, many publishers use high resolution typesetting systems, and the final result will then fail to live up to expectations. –  András Salamon Aug 5 '10 at 18:15
Thanks, I think that this should be the best practice as opposed to specifying the size. I'll update my preferred answer to be your suggestion. –  wishihadabettername Aug 6 '10 at 15:42

What Geoff said, additionally you can specify the height, or even both: \includegraphics[width=5cm,height=5cm]{chart}

That being said, if you use only one of them graphicx (the package providing the \includegraphics macro) will take care of maintaining the proper aspect ratio.

-
Thanks. I cannot yet vote this up. –  wishihadabettername Aug 5 '10 at 17:56

You could write

\pdfimageresolution=300


if the image has a resolution of 300 dpi etc. Perhaps it has a higher resolution but the standard value is 72 dpi. Or save it with setting 72 dpi.

-
To explain a bit further, it is quite common for png files to miss out vital information in the file. So TeX works with standard values, which can give these unexpected results. –  Joseph Wright Aug 5 '10 at 17:04
Indeed, the resolution was 94 in this case. The PNG was missing it because it. I added it and the size is correct now, but in the PDF it's still blurry (most obvious in the legend of the chart which, being in small font, is not anti-aliased). Is there an extra setting to add? Thanks. –  wishihadabettername Aug 5 '10 at 17:28
At a second thought, I'll ask my 2nd problem stated in the comment above in a separate question and reference this one. –  wishihadabettername Aug 5 '10 at 17:46

You can specify the printed width: \includegraphics[width=2in]{chart}`

-