# Plot symbols not showing properly using R + knitr with 'pdf' device

When I include R plots in a latex document using knitr, symbols do not show properly when knitr's graphic device is 'pdf', while everything is OK when the graphic device is 'png'. Here is a MWE:

\documentclass{article}

<<>>=
library(knitr)
library(survival)
attach(lung)
@

\begin{document}

A sample figure with default 'pdf' device.

<<>>=
plot(age, meal.cal)
@
\clearpage

Same figure, with 'png' device.

<<dev='png'>>=
plot(age, meal.cal)
detach(lung)
@
\end{document}


In the first graph the circles are not drawn, while the second graph is fine. Any suggestion?

• You could try the Cairopdf device from the R Cairo package, that sometimes works better than the default pdf device. Jun 27, 2018 at 11:04
• Tried to install the Cairo package, but the installation failed. I have libcairo2 already installed on my system (Linux Opensuse Leap 15), so I will have to resolve that issue first. Jun 27, 2018 at 11:16
• You may also need libcairo2-dev and libxt-dev. Jun 27, 2018 at 11:24
• Hum... neither package seems to be available from the OpenSuse standard repositories. I will look around for the RPM's. Jun 27, 2018 at 11:53
• Regarding the question itself: I downloaded the file from the Google drive and for me both the pdf and the png plots look exactly the same (i.e., with open circles for each data point). However, the file properties show that the ZapfDingbats font is used in the document (presumably for the circle symbol) but, importantly, that this font is not embedded. On my system I don't have this font, and my pdf viewer informs me that the font is replaced by Dingbats (which is installed, and which provides a suitable replacement symbol). But if you don't have a suitable font the symbol will not show. Jun 27, 2018 at 12:27

The default pdf device in R uses a character from the ZapfDingbats font for the circles in the graph. However, the font is not embedded in the pdf file, therefore a pdf viewer does not display the circles when the font or a suitable replacement is not found (to the defense of R: ZapfDingbats is one of the Standard 14 Fonts, i.e., several variants of Times, Helvetica, Courier, Symbol and ZapfDingbats). See the font properties of the pdf file created using the pdf device:

The cairo_pdf device can be used instead. This device does not use a circle character from a font (the circle is drawn directly). Moreover, all fonts are embedded.

Relevant code:

\begin{document}

A sample figure with default 'pdf' device.

<<dev='cairo_pdf'>>=
plot(age, meal.cal)
@
\end{document}


Example font properties:

Note that with cairo_pdf the circles are not selectable/searchable, but that is not likely to be a problem.