0

I am using the tufte-book documentclass and template. I have been exporting ggplot2 images to PDF format, and then including them in LaTeX in figure environments.

Everything was going fine, until one day some of the dots in the graphs just... disappeared. They had been there in previous builds of the document. Specifically dot shape 16 in ggplot2 (the default shape for geom_point) no longer shows up. Other shapes show up fine. I've tried reinstalling ggplot2, tried getting rid of tufte-book (as in the reprex), no dice. I've also tried building with both xelatex and pdflatex. This is all the more confusing because it used to work just fine, and I can't think of what I might have changed. Any tips would be appreciated.

For reference, here is the actual ggplot2-generated PDF that I am including:

Actual Image

and here is how it shows up in my LaTeX doc (in the tufte-latex version, although the problem shows up in the documentclass{article} version in the reprex too):

Image in LaTeX

Here is the code. I don't think I'm doing anything unusual here:

To generate the graph:

library(tidyverse)

# Police and crime
library(wooldridge)
data(crime4)

ggplot(crime4, aes(x = polpc, y = crmrte)) + 
  geom_point() + 
  theme_minimal() + 
  scale_x_log10() + 
  scale_y_log10() + 
  labs(x = "Police per Capita (log scale)",
       y = "Crime Rate (log scale)")
ggsave('crime1.pdf', width = 6, height = 5)

And the LaTeX doc itself

\documentclass{article}

\usepackage{graphicx}

\begin{document}

\begin{figure}[h!]
    \caption{Police Presence and Crime Rate by County, North Carolina 1981-1987}
    \label{fig:causaldiagrams-crime1}
    \includegraphics{"crime1.pdf"}
\end{figure}

\end{document}
1

1 Answer 1

1

Sorry, I cannot comment, so I have to answer: Are the dots missing in the preview within your LaTex editor or also in the compiled document when you open it from another pdf viewer? I had the same problem and the points were only missing in the built-in TeXmaker pdf viewer but not in other programs... In my case, all round dots (pch in {16, 19, 20, 21}) produced in R were missing, but it seems it was only a problem of the pdf viewer (i.e. the symbols it understands). Try to open the complete document you've compiled with the same pdf viewer that displayed your plot pdf correctly. If it works it was the pdf viewer all the time.

Furthermore, note that the "same" pdf viewer might behave differently depending on your OS. I first thought it was the OS, since TeXmaker showed the dots under Linux but not under Windows. So I did "the same thing" twice with different results.

I suppose it is like Marijin noted a question of the circle symbol used by R which is not displaied correctly. You can either use the suggested cairo_pdf device instead of pdf or use another symbol instead of a cricle. You could also experiment with

geom_text(label = "\u2022", size = 10)

(might require the package Unicode(?)).Plotting text instead of points, you can try different symbols or character families.

Update: I also found that setting the opacity of the points to a value different from 1 (e.g. in ggplot simply set alpha=0.99) will prevent R from using the "problematic" ZapfDingbats character. Might be worth a try, it appears to work for me.

1
  • It was the PDF viewer - I didn't even think to check that! cairo_pdf fixes everything. Thanks!
    – NickCHK
    Mar 24, 2020 at 22:14

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .