dagger appears in ggplot in viewer, but replaced with ... when saved to pdf

ggplot2, r

Solution

from @BenBolker:

See ?pdf, especially search for "embed fonts" and "problems with PDF output"

library("Cairo")
ggsave("myfig.pdf", device=cairo_pdf)

Problem

I am using `ggplot2` to create a dotplot. One item label has a dagger (†). The dagger appears in the plot when viewed in RStudio, but it is replaced with ... when I save the plot to pdf. Is there a way to prevent the graphics device from converting my dagger to ...? Here's a small example: ``` library(ggplot2) # data dat <- data.frame(VARIABLES=c("Item 1", "Item 2 †"), est=c(.3, .5), min=c(.2, .4), max=c(.4, .7)) # plot ggplot(dat, aes(x=reorder(as.character(VARIABLES), est), y=est)) + geom_pointrange(aes(ymin=min, ymax=max), linetype="dashed") + geom_point(size=3) + ylim(-1,1) + theme_bw() + theme(legend.position="none") + coord_flip() #--- # dagger appears in viewer ``` ``` # save plot ggsave(filename="myfig.pdf") #--- # dagger replaced with ... in pdf ```

Original source